Skip to:
Content

BuddyPress.org

Changeset 4587


Ignore:
Timestamp:
07/04/2011 05:56:31 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Rename bp_core_get_site_options() to bp_core_get_root_options() and fix issue where moved site settings would not completely migrate, causing migration to run on each page load. Fixes #3307. See #3313 and r4585.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-functions.php

    r4586 r4587  
    970970
    971971/**
    972  * BuddyPress uses site options to store configuration settings. Many of these settings are needed
    973  * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
    974  * them all in one go.
    975  *
    976  * @package BuddyPress Core
    977  */
    978 function bp_core_get_site_options() {
    979     global $bp, $wpdb;
    980 
    981     // These options come from the options table
    982     $site_options = apply_filters( 'bp_core_site_options', array(
    983         'bp-deactivated-components',
    984         'bp-blogs-first-install',
    985         'bp-disable-blog-forum-comments',
    986         'bp-xprofile-base-group-name',
    987         'bp-xprofile-fullname-field-name',
    988         'bp-disable-profile-sync',
    989         'bp-disable-avatar-uploads',
    990         'bp-disable-account-deletion',
    991         'bp-disable-forum-directory',
    992         'bp-disable-blogforum-comments',
    993         'bb-config-location',
    994         'hide-loggedout-adminbar',
    995 
    996         // Useful WordPress settings used often
    997         'tags_blog_id',
    998         'registration',
    999         'fileupload_maxk'
    1000     ) );
    1001 
    1002     // These options always come from the options table of BP_ROOT_BLOG
    1003     $root_blog_options = apply_filters( 'bp_core_root_blog_options', array(
    1004         'avatar_default'
    1005     ) );
    1006 
    1007     $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
    1008 
    1009     $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
    1010    
    1011     // Backward compatibility - moves sitemeta to the blog
    1012     if ( empty( $site_meta ) || ( count( $site_meta ) < count( $site_options ) ) ) {
    1013         if ( is_multisite() ) {
    1014             $ms_site_meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );
    1015         } else {
    1016             $ms_site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
    1017         }
    1018        
    1019         $settings_to_move = array(
    1020             'bp-deactivated-components',
    1021             'bp-blogs-first-install',
    1022             'bp-disable-blog-forum-comments',
    1023             'bp-xprofile-base-group-name',
    1024             'bp-xprofile-fullname-field-name',
    1025             'bp-disable-profile-sync',
    1026             'bp-disable-avatar-uploads',
    1027             'bp-disable-account-deletion',
    1028             'bp-disable-forum-directory',
    1029             'bp-disable-blogforum-comments',
    1030             'bb-config-location',
    1031             'hide-loggedout-adminbar',
    1032         );
    1033        
    1034         foreach( (array)$ms_site_meta as $meta ) { 
    1035             if ( isset( $meta->name ) && in_array( $meta->name, $settings_to_move ) ) {
    1036                 bp_update_option( $meta->name, $meta->value );
    1037                        
    1038                 if ( empty( $site_meta[$meta->name] ) ) {
    1039                     $site_meta[$meta->name] = $meta->value;
    1040                 }
    1041             }
    1042         }
    1043     }
    1044    
    1045     // Some WP settings are always in sitemeta
    1046     if ( is_multisite() ) {
    1047         $sitewide_option_keys = apply_filters( 'bp_core_sitewide_site_options', array(
    1048             'tags_blog_id',
    1049             'registration',
    1050             'fileupload_maxk'
    1051         ) );
    1052        
    1053         $sitewide_options_keys_cs = "'" . implode( "','", (array)$sitewide_option_keys ) ."'";
    1054        
    1055         $network_meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$sitewide_options_keys_cs}) AND site_id = {$wpdb->siteid}" );
    1056     }
    1057 
    1058     $root_blog_meta_keys  = "'" . implode( "','", (array)$root_blog_options ) ."'";
    1059     $root_blog_meta_table = $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'options';
    1060     $root_blog_meta       = $wpdb->get_results( $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$root_blog_meta_table} WHERE option_name IN ({$root_blog_meta_keys})" ) );
    1061     $site_options         = array();
    1062 
    1063     foreach( array( $site_meta, $root_blog_meta, $network_meta ) as $meta ) {
    1064         if ( !empty( $meta ) ) {
    1065             foreach( (array)$meta as $meta_item ) {
    1066                 if ( isset( $meta_item->name ) )
    1067                     $site_options[$meta_item->name] = $meta_item->value;
    1068             }
    1069         }
    1070     }
    1071     return apply_filters( 'bp_core_get_site_options', $site_options );
     972 * BuddyPress uses common options to store configuration settings. Many of these
     973 * settings are needed at run time. Instead of fetching them all and adding many
     974 * initial queries to each page load, let's fetch them all in one go.
     975 *
     976 * @package BuddyPress Core
     977 * @todo Use settings API and audit these methods
     978 */
     979function bp_core_get_root_options() {
     980    global $wpdb;
     981
     982    // These options come from the root blog options table
     983    $root_blog_options = apply_filters( 'bp_core_site_options', array(
     984
     985        // BuddyPress core settings
     986        'bp-deactivated-components'       => serialize( array( ) ),
     987        'bp-blogs-first-install'          => '0',
     988        'bp-disable-blog-forum-comments'  => '0',
     989        'bp-xprofile-base-group-name'     => 'Base',
     990        'bp-xprofile-fullname-field-name' => 'Name',
     991        'bp-disable-profile-sync'         => '0',
     992        'bp-disable-avatar-uploads'       => '0',
     993        'bp-disable-account-deletion'     => '0',
     994        'bp-disable-forum-directory'      => '0',
     995        'bp-disable-blogforum-comments'   => '0',
     996        'bb-config-location'              => ABSPATH,
     997        'hide-loggedout-adminbar'         => '0',
     998
     999        // Useful WordPress settings
     1000        'tags_blog_id'                    => '0',
     1001        'registration'                    => '0',
     1002        'fileupload_maxk'                 => '1500',
     1003        'avatar_default'                  => 'mysteryman'
     1004    ) );
     1005    $root_blog_option_keys  = array_keys( $root_blog_options );
     1006    $blog_options_keys      = implode( "', '", (array) $root_blog_option_keys );
     1007    $blog_options_query     = sprintf( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ('%s')", $blog_options_keys );
     1008    $root_blog_options_meta = $wpdb->get_results( $blog_options_query );
     1009
     1010    // Missing some options, so do some one-time fixing
     1011    if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
     1012
     1013        // Unset the query - We'll be resetting it soon
     1014        unset( $root_blog_options_meta );
     1015
     1016        // Loop through options
     1017        foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
     1018
     1019            // Clear out the value from the last time around
     1020            unset( $old_meta_value );
     1021
     1022            // Get old site option
     1023            if ( is_multisite() )
     1024                $old_meta_value = get_site_option( $old_meta_key );
     1025
     1026            // No site option so look in root blog
     1027            if ( empty( $old_meta_value ) )
     1028                $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
     1029
     1030            // Update the root blog option
     1031            bp_update_option( $old_meta_key, $old_meta_value );
     1032
     1033            // Update the global array
     1034            $root_blog_options_meta[$old_meta_key] = $old_meta_value;
     1035        }
     1036
     1037    // We're all matched up
     1038    } else {
     1039
     1040        // Loop through our results and make them usable
     1041        foreach ( $root_blog_options_meta as $root_blog_option )
     1042            $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
     1043
     1044        // Copy the options no the return val
     1045        $root_blog_options_meta = $root_blog_options;
     1046
     1047        // Clean up our temporary copy
     1048        unset( $root_blog_options );
     1049    }
     1050
     1051    return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
    10721052}
    10731053
Note: See TracChangeset for help on using the changeset viewer.