Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/12/2011 02:33:04 PM (12 years ago)
Author:
johnjamesjacoby
Message:

First pass at using settings API:

  • Split bp-core-admin.php up into smaller parts
  • Use settings API for Settings screen
  • Backport bbPress 2.x admin class
  • Move admin functions out of core functions and cssjs files
  • Update bp-core-options.php and include
  • Rename menu pages to be more accurate
  • Rename 'Pages' tab to 'Permalinks' for future slugifying
  • See #3835
File:
1 edited

Legend:

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

    r5508 r5524  
    2525        /** DB Version ********************************************************/
    2626
    27         '_bp_db_version'                => '155',
     27        '_bp_db_version'                  => '155',
     28
     29        /** Components ********************************************************/
     30
     31        'bp-deactivated-components'       => serialize( array() ),
     32
     33        /** bbPress ***********************************************************/
     34
     35        // Legacy bbPress config location
     36        'bb-config-location'              => ABSPATH . 'bb-config.php',
     37
     38        /** XProfile **********************************************************/
     39
     40        // Base profile groups name
     41        'bp-xprofile-base-group-name'     => 'Base',
     42
     43        // Base fullname field name
     44        'bp-xprofile-fullname-field-name' => 'Name',
     45
     46        /** Blogs *************************************************************/
     47
     48        // Used to decide if blogs need indexing
     49        'bp-blogs-first-install'          => false,
    2850
    2951        /** Settings **********************************************************/
    3052
    3153        // Disable the WP to BP profile sync
    32         'bp-disable-profile-sync'       => false,
     54        'bp-disable-profile-sync'         => false,
    3355
    3456        // Hide the admin bar for logged out users
    35         'hide-loggedout-adminbar'       => false,
     57        'hide-loggedout-adminbar'         => false,
    3658
    3759        // Avatar uploads
    38         'bp-disable-avatar-uploads'     => false,
     60        'bp-disable-avatar-uploads'       => false,
    3961
    4062        // Allow users to delete their own accounts
    41         'bp-disable-account-deletion'   => true,
     63        'bp-disable-account-deletion'     => true,
    4264
    4365        // Allow anonymous posting
    44         'bp-disable-blogforum-comments' => true,
     66        'bp-disable-blogforum-comments'   => true,
    4567
    4668        // Use the WordPress editor when possible
    47         '_bp_use_wp_editor'             => false,
     69        '_bp_use_wp_editor'               => false,
    4870
    4971        /** Groups ************************************************************/
     
    5274
    5375        // Restrict group creation to super admins
    54         'bp_restrict_group_creation'    => false,
     76        'bp_restrict_group_creation'      => false,
    5577
    5678        // Root forum ID for groups
    57         '_bbp_group_forums_root_id'     => 0,
     79        '_bbp_group_forums_root_id'       => 0,
    5880
    5981        /** Akismet ***********************************************************/
    6082
    6183        // Users from all sites can post
    62         '_bp_enable_akismet'        => true,
     84        '_bp_enable_akismet'              => true,
    6385    );
    6486
     
    164186    // Always return a value, even if false
    165187    return $value;
     188}
     189
     190/**
     191 * When switching from single to multisite we need to copy blog options to
     192 * site options.
     193 *
     194 * @package BuddyPress Core
     195 * @todo Does this need to be here anymore after the introduction of bp_get_option etc?
     196 */
     197function bp_core_activate_site_options( $keys = array() ) {
     198    global $bp;
     199
     200    if ( !empty( $keys ) && is_array( $keys ) ) {
     201        $errors = false;
     202
     203        foreach ( $keys as $key => $default ) {
     204            if ( empty( $bp->site_options[ $key ] ) ) {
     205                $bp->site_options[ $key ] = bp_get_option( $key, $default );
     206
     207                if ( !bp_update_option( $key, $bp->site_options[ $key ] ) )
     208                    $errors = true;
     209            }
     210        }
     211
     212        if ( empty( $errors ) )
     213            return true;
     214    }
     215
     216    return false;
     217}
     218
     219/**
     220 * BuddyPress uses common options to store configuration settings. Many of these
     221 * settings are needed at run time. Instead of fetching them all and adding many
     222 * initial queries to each page load, let's fetch them all in one go.
     223 *
     224 * @package BuddyPress Core
     225 * @todo Use settings API and audit these methods
     226 */
     227function bp_core_get_root_options() {
     228    global $wpdb;
     229
     230    // Get all the BuddyPress settings, and a few useful WP ones too
     231    $root_blog_options                   = bp_get_default_options();
     232    $root_blog_options['registration']   = '0';
     233    $root_blog_options['avatar_default'] = 'mysteryman';
     234    $root_blog_option_keys               = array_keys( $root_blog_options );
     235
     236    // Do some magic to get all the root blog options in 1 swoop
     237    $blog_options_keys      = "'" . join( "', '", (array) $root_blog_option_keys ) . "'";
     238    $blog_options_table     = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'options';
     239    $blog_options_query     = $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )" );
     240    $root_blog_options_meta = $wpdb->get_results( $blog_options_query );
     241
     242    // On Multisite installations, some options must always be fetched from sitemeta
     243    if ( is_multisite() ) {
     244        $network_options = apply_filters( 'bp_core_network_options', array(
     245            'tags_blog_id'       => '0',
     246            'sitewide_tags_blog' => '',
     247            'registration'       => '0',
     248            'fileupload_maxk'    => '1500'
     249        ) );
     250
     251        $current_site           = get_current_site();
     252        $network_option_keys    = array_keys( $network_options );
     253        $sitemeta_options_keys  = "'" . join( "', '", (array) $network_option_keys ) . "'";
     254        $sitemeta_options_query = $wpdb->prepare( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id );
     255        $network_options_meta   = $wpdb->get_results( $sitemeta_options_query );
     256
     257        // Sitemeta comes second in the merge, so that network 'registration' value wins
     258        $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta );
     259    }
     260
     261    // Missing some options, so do some one-time fixing
     262    if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
     263
     264        // Unset the query - We'll be resetting it soon
     265        unset( $root_blog_options_meta );
     266
     267        // Loop through options
     268        foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
     269            // Clear out the value from the last time around
     270            unset( $old_meta_value );
     271
     272            // Get old site option
     273            if ( is_multisite() )
     274                $old_meta_value = get_site_option( $old_meta_key );
     275
     276            // No site option so look in root blog
     277            if ( empty( $old_meta_value ) )
     278                $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
     279
     280            // Update the root blog option
     281            bp_update_option( $old_meta_key, $old_meta_value );
     282
     283            // Update the global array
     284            $root_blog_options_meta[$old_meta_key] = $old_meta_value;
     285        }
     286
     287    // We're all matched up
     288    } else {
     289        // Loop through our results and make them usable
     290        foreach ( $root_blog_options_meta as $root_blog_option )
     291            $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
     292
     293        // Copy the options no the return val
     294        $root_blog_options_meta = $root_blog_options;
     295
     296        // Clean up our temporary copy
     297        unset( $root_blog_options );
     298    }
     299
     300    return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
    166301}
    167302
Note: See TracChangeset for help on using the changeset viewer.