Skip to:
Content

BuddyPress.org

Changeset 11094


Ignore:
Timestamp:
09/13/2016 05:20:29 PM (8 years ago)
Author:
djpaul
Message:

Core: stop bp_get_default_options() adding missing options to the database.

bp_get_default_options() is used to get default option names and values throughout BuddyPress. If an option is not set in the database when the function is ran, it will add it.
The function is called in lots of places, and it even gets called before the version update handler routine does, from bp_core_set_avatar_constants().
This is not obvious, and causes unpredictable behaviour about when a new option should exist (or not).

This change removes the missing option insertion from bp_get_default_options().
New installs will have all options added by bp_activation(). Version updates will take responsibility to add new options within the existing upgrade routines.

See #7254 and #7227

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-options.php

    r11093 r11094  
    415415        }
    416416
    417         // Missing some options, so do some one-time fixing.
    418         if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
    419 
    420             // Get a list of the keys that are already populated.
    421             $existing_options = array();
    422             foreach( $root_blog_options_meta as $already_option ) {
    423                 $existing_options[$already_option->name] = $already_option->value;
    424             }
    425 
    426             // Unset the query - We'll be resetting it soon.
    427             unset( $root_blog_options_meta );
    428 
    429             // Loop through options.
    430             foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
    431 
    432                 if ( isset( $existing_options[$old_meta_key] ) ) {
    433                     continue;
    434                 }
    435 
    436                 // Get old site option.
    437                 if ( is_multisite() ) {
    438                     $old_meta_value = get_site_option( $old_meta_key );
    439                 }
    440 
    441                 // No site option so look in root blog.
    442                 if ( empty( $old_meta_value ) ) {
    443                     $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
    444                 }
    445 
    446                 // Update the root blog option.
    447                 bp_update_option( $old_meta_key, $old_meta_value );
    448 
    449                 // Update the global array.
    450                 $root_blog_options_meta[$old_meta_key] = $old_meta_value;
    451 
    452                 // Clear out the value for the next time around.
    453                 unset( $old_meta_value );
    454             }
    455 
    456             $root_blog_options_meta = array_merge( $root_blog_options_meta, $existing_options );
    457             unset( $existing_options );
    458 
    459         // We're all matched up.
    460         } else {
    461             // Loop through our results and make them usable.
    462             foreach ( $root_blog_options_meta as $root_blog_option ) {
    463                 $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
    464             }
    465 
    466             // Copy the options no the return val.
    467             $root_blog_options_meta = $root_blog_options;
    468 
    469             // Clean up our temporary copy.
    470             unset( $root_blog_options );
     417        // Loop through our results and make them usable.
     418        foreach ( $root_blog_options_meta as $root_blog_option ) {
     419            $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
    471420        }
     421
     422        // Copy the options no the return val.
     423        $root_blog_options_meta = $root_blog_options;
     424
     425        // Clean up our temporary copy.
     426        unset( $root_blog_options );
    472427
    473428        wp_cache_set( 'root_blog_options', $root_blog_options_meta, 'bp' );
Note: See TracChangeset for help on using the changeset viewer.