Skip to:
Content

BuddyPress.org

Ticket #3307: 3307.patch

File 3307.patch, 7.3 KB (added by johnjamesjacoby, 14 years ago)
  • bp-core-functions.php

     
    1616 * @param str $default Optional. Default value to be returned if the option isn't set
    1717 * @return mixed The value for the option
    1818 */
    19 function bp_get_option( $option_name, $default = false ) {
     19function bp_get_option( $option_name, $default = '' ) {
    2020        $value = get_blog_option( bp_get_option_blog_id( $option_name ), $option_name, $default );
    2121       
    2222        return apply_filters( 'bp_get_option', $value );
     
    969969}
    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.
     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.
    975975 *
    976976 * @package BuddyPress Core
     977 * @todo Use settings API and audit these methods
    977978 */
    978 function bp_core_get_site_options() {
    979         global $bp, $wpdb;
     979function bp_core_get_root_options() {
     980        global $wpdb;
    980981
    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',
     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',
    995998
    996                 // Useful WordPress settings used often
    997                 'tags_blog_id',
    998                 'registration',
    999                 'fileupload_maxk'
     999                // Useful WordPress settings
     1000                'tags_blog_id'                    => '0',
     1001                'registration'                    => '0',
     1002                'fileupload_maxk'                 => '1500',
     1003                'avatar_default'                  => 'mysteryman'
    10001004        ) );
     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 );
    10011009
    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         ) );
     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 ) ) ) {
    10061012
    1007         $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
     1013                // Unset the query - We'll be resetting it soon
     1014                unset( $root_blog_options_meta );
    10081015
    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})" );
     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;
    10171035                }
    10181036               
    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         }
     1037        // We're all matched up
     1038        } else {
    10441039
    1045         $root_blog_meta_keys  = "'" . implode( "','", (array)$root_blog_options ) ."'";
    1046         $root_blog_meta_table = $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'options';
    1047         $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})" ) );
    1048         $site_options         = array();
     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;
    10491043
    1050         foreach( array( $site_meta, $root_blog_meta ) as $meta ) {
    1051                 if ( !empty( $meta ) ) {
    1052                         foreach( (array)$meta as $meta_item ) {
    1053                                 if ( isset( $meta_item->name ) )
    1054                                         $site_options[$meta_item->name] = $meta_item->value;
    1055                         }
    1056                 }
     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 );
    10571049        }
    1058         return apply_filters( 'bp_core_get_site_options', $site_options );
     1050
     1051        return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
    10591052}
    10601053
    10611054/**
  • bp-core-loader.php

     
    137137
    138138                // Fetches all of the core BuddyPress settings in one fell swoop
    139139                if ( empty( $bp->site_options ) )
    140                         $bp->site_options = bp_core_get_site_options();
     140                        $bp->site_options = bp_core_get_root_options();
    141141
    142142                // The names of the core WordPress pages used to display BuddyPress content
    143143                if ( empty( $bp->pages ) )