Skip to:
Content

BuddyPress.org

Changeset 4559


Ignore:
Timestamp:
06/24/2011 06:57:51 PM (10 years ago)
Author:
boonebgorges
Message:

Introduces bp_x_option() wrapper functions, along with bp_get_option_blog_id() to allow for fully filterable option storage. Refactors internal option storage to use new API functions. Fixes bp-pages for BP_ENABLE_MULTIBLOG. Fixes #3261

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-template.php

    r4466 r4559  
    363363    global $bp;
    364364
    365     $active_signup = $bp->site_options['registration'];
    366 
    367     if ( !$active_signup )
    368         $active_signup = 'all';
     365    $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
    369366
    370367    $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
  • trunk/bp-core/admin/bp-core-admin.php

    r4482 r4559  
    5959        // Settings form submitted, now save the settings.
    6060        foreach ( (array)$_POST['bp-admin'] as $key => $value )
    61             update_site_option( $key, $value );
     61            bp_update_option( $key, $value );
    6262
    6363    } ?>
     
    8787                            <th scope="row"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</th>
    8888                            <td>
    89                                 <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    90                                 <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     89                                <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)bp_get_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     90                                <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)bp_get_option( 'bp-disable-profile-sync' ) || '' == bp_get_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    9191                            </td>
    9292                        </tr>
     
    9797                        <th scope="row"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</th>
    9898                        <td>
    99                             <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    100                             <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     99                            <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     100                            <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)bp_get_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    101101                        </td>
    102102                    </tr>
     
    105105                        <th scope="row"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</th>
    106106                        <td>
    107                             <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    108                             <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     107                            <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     108                            <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    109109                        </td>
    110110                    </tr>
     
    113113                        <th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
    114114                        <td>
    115                             <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    116                             <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     115                            <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)bp_get_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     116                            <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)bp_get_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    117117                        </td>
    118118                    </tr>
     
    123123                            <th scope="row"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</th>
    124124                            <td>
    125                                 <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    126                                 <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     125                                <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)bp_get_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     126                                <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)bp_get_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    127127                            </td>
    128128                        </tr>
     
    135135                            <th scope="row"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</th>
    136136                            <td>
    137                                 <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    138                                 <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     137                                <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)bp_get_option( 'bp-disable-blogforum-comments' ) || false === bp_get_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     138                                <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)bp_get_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    139139                            </td>
    140140                        </tr>
     
    147147                            <th scope="row"><?php _e( 'Restrict group creation to Site Admins?', 'buddypress' ) ?>:</th>
    148148                            <td>
    149                                 <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '1', get_site_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    150                                 <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '0', get_site_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     149                                <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '1', bp_get_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     150                                <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '0', bp_get_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    151151                            </td>
    152152                        </tr>
     
    184184        if ( isset( $_POST['bp_components'] ) ) {
    185185            $bp->active_components = stripslashes_deep( $_POST['bp_components'] );
    186             update_site_option( 'bp-active-components', $bp->active_components );
     186            bp_update_option( 'bp-active-components', $bp->active_components );
    187187        }
    188188
     
    263263function bp_core_admin_component_options() {
    264264    global $bp_wizard;
    265 
    266     $active_components = apply_filters( 'bp_active_components', get_site_option( 'bp-active-components' ) );
     265           
     266    require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
     267
     268    $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
    267269   
    268270    // An array of strings looped over to create component setup markup
  • trunk/bp-core/admin/bp-core-schema.php

    r4391 r4559  
    205205    $bp_prefix = bp_core_get_table_prefix();
    206206
    207     update_site_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
    208     update_site_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
     207    bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
     208    bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
    209209
    210210    $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
     
    263263
    264264    if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) )
    265         $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( get_site_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
     265        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
    266266
    267267    if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) )
    268         $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( get_site_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
     268        $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
    269269
    270270    dbDelta( $insert_sql );
  • trunk/bp-core/admin/bp-core-update.php

    r4556 r4559  
    1818
    1919        // Ensure that we have access to some utility functions
    20         include( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
     20        require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
    2121
    2222        // Get current DB version
     
    260260    }
    261261
    262     function step_ms_update() {
     262    function step_ms_update() {     
    263263        if ( !current_user_can( 'activate_plugins' ) )
    264264            return false;
    265265
    266         $active_components = get_site_option( 'bp-active-components' );
     266        $active_components = bp_get_option( 'bp-active-components' );
    267267
    268268        if ( defined( 'BP_BLOGS_SLUG' ) )
     
    272272
    273273        // Call up old bp-pages to see if a page has been previously linked to Blogs
    274         $page_blog_id        = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    275         $existing_pages_data = get_blog_option( $page_blog_id, 'bp-pages' );
    276         $existing_pages      = $existing_pages_data[$page_blog_id];
     274        $existing_pages = bp_get_option( 'bp-pages' );
    277275
    278276        if ( !empty( $existing_pages['blogs'] ) )
     
    370368
    371369        $existing_pages = bp_core_update_get_page_meta();
     370       
     371        // Provide empty indexes to avoid PHP errors with wp_dropdown_pages()
     372        $indexes = array( 'members', 'activity', 'groups', 'forums', 'blogs', 'register', 'activate' );
     373        foreach ( $indexes as $index ) {
     374            if ( !isset( $existing_pages[$index] ) )
     375                $existing_pages[$index] = '';
     376        }
     377       
     378        if ( !empty( $existing_pages['blogs'] ) )
     379            $existing_blog_page = '&selected=' . $existing_pages['blogs'];
     380        else
     381            $existing_blog_page = '';
    372382
    373383        // Get active components
    374         $active_components = apply_filters( 'bp_active_components', get_site_option( 'bp-active-components' ) );
     384        $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
    375385
    376386        // Check for defined slugs
     
    739749            // Update the active components option early if we're updating
    740750            if ( 'update' == $this->setup_type )
    741                 update_site_option( 'bp-active-components', $bp->active_components );
     751                bp_update_option( 'bp-active-components', $bp->active_components );
    742752
    743753            return true;
     
    772782
    773783                // Move bp-pages data from the blog options table to site options
    774                 $page_blog_id        = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    775                 $existing_pages_data = get_blog_option( $page_blog_id, 'bp-pages' );
    776                 $existing_pages      = $existing_pages_data[$page_blog_id];
    777 
    778                 $bp_pages            = $this->setup_pages( (array)$_POST['bp_pages'] );
    779                 $bp_pages            = array_merge( (array)$existing_pages, (array)$bp_pages );
    780 
    781                 $existing_pages_data[$page_blog_id] = $bp_pages;
    782 
    783                 update_site_option( 'bp-pages', $existing_pages_data );
     784                $existing_pages = bp_get_option( 'bp-pages' );
     785
     786                $bp_pages       = $this->setup_pages( (array)$_POST['bp_pages'] );
     787                $bp_pages       = array_merge( (array)$existing_pages, (array)$bp_pages );
     788
     789                bp_update_option( 'bp-pages', $existing_pages );
    784790
    785791                if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
     
    789795            }
    790796
    791             update_site_option( 'bp-active-components', $active_components );
     797            bp_update_option( 'bp-active-components', $active_components );
    792798
    793799            return true;
     
    808814                $active_components[$key] = 1;
    809815
    810             update_site_option( 'bp-active-components', $active_components );
     816            bp_update_option( 'bp-active-components', $active_components );
    811817
    812818            wp_cache_flush();
     
    836842
    837843            $blog_pages   = $this->setup_pages( (array)$_POST['bp_pages'] );
    838             $page_blog_id = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    839             $bp_pages     = array( $page_blog_id => $blog_pages );
    840 
    841             update_site_option( 'bp-pages', $bp_pages );
     844            bp_update_option( 'bp-pages', $blog_pages );
    842845
    843846            if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != BP_ROOT_BLOG ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
     
    10081011
    10091012            // Update the DB version in the database
     1013            // Stored in sitemeta. Do not use bp_update_option()
    10101014            update_site_option( 'bp-db-version', $this->new_version );
    10111015            delete_site_option( 'bp-core-db-version' );
     
    10761080
    10771081    if ( empty( $active_components ) )
    1078         $active_components = apply_filters( 'bp_active_components', get_site_option( 'bp-active-components' ) );
     1082        $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
    10791083
    10801084    require_once( dirname( __FILE__ ) . '/bp-core-schema.php' );
     
    11321136    if ( !(int)$bp->site_options['bp-blogs-first-install'] && is_multisite() ) {
    11331137        bp_blogs_record_existing_blogs();
    1134         add_site_option( 'bp-blogs-first-install', 1 );
     1138        bp_update_option( 'bp-blogs-first-install', 1 );
    11351139    }
    11361140
     
    12491253
    12501254/**
    1251  * Fetches BP pages from the meta table, depending on setup
     1255 * Fetches BP pages from the meta table
    12521256 *
    12531257 * @package BuddyPress Core
     
    12561260 * @return array $page_ids
    12571261 */
    1258 function bp_core_update_get_page_meta() {
    1259     $page_ids = get_site_option( 'bp-pages' );
    1260 
    1261     $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
    1262 
    1263     $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
    1264 
    1265     $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
    1266 
    1267     return apply_filters( 'bp_core_update_get_page_meta', $blog_page_ids );
     1262function bp_core_update_get_page_meta() {           
     1263    require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
     1264   
     1265    if ( !$page_ids = bp_get_option( 'bp-pages' ) )
     1266        $page_ids = array();
     1267
     1268    return apply_filters( 'bp_core_update_get_page_meta', $page_ids );
    12681269}
    12691270
  • trunk/bp-core/bp-core-buddybar.php

    r4466 r4559  
    322322        return false;
    323323
    324     if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
     324    if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
    325325        return false;
    326326
     
    487487        show_admin_bar( false );
    488488
    489         if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
     489        if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
    490490            return;
    491491
  • trunk/bp-core/bp-core-functions.php

    r4558 r4559  
    11<?php
     2
     3/**
     4 * Retrieve an option
     5 *
     6 * This is a wrapper for get_blog_option(), which in turn stores settings data (such as bp-pages)
     7 * on the appropriate blog, given your current setup.
     8 *
     9 * The 'bp_get_option' filter is primarily for backward-compatibility.
     10 *
     11 * @package BuddyPress
     12 * @since 1.3
     13 *
     14 * @uses bp_get_option_blog_id()
     15 * @param str $option_name The option to be retrieved
     16 * @param str $default Optional. Default value to be returned if the option isn't set
     17 * @return mixed The value for the option
     18 */
     19function bp_get_option( $option_name, $default = false ) {
     20    $value = get_blog_option( bp_get_option_blog_id( $option_name ), $option_name, $default );
     21   
     22    return apply_filters( 'bp_get_option', $value );
     23}
     24
     25/**
     26 * Save an option
     27 *
     28 * This is a wrapper for update_blog_option(), which in turn stores settings data (such as bp-pages)
     29 * on the appropriate blog, given your current setup.
     30 *
     31 * @package BuddyPress
     32 * @since 1.3
     33 *
     34 * @uses bp_get_option_blog_id()
     35 * @param str $option_name The option key to be set
     36 * @param str $value The value to be set
     37 */
     38function bp_update_option( $option_name, $value ) {
     39    // update_blog_option() does not return anything on success/failure, so neither can we
     40    update_blog_option( bp_get_option_blog_id( $option_name ), $option_name, $value );
     41}
     42
     43/**
     44 * Delete an option
     45 *
     46 * This is a wrapper for delete_blog_option(), which in turn deletes settings data (such as
     47 * bp-pages) on the appropriate blog, given your current setup.
     48 *
     49 * @package BuddyPress
     50 * @since 1.3
     51 *
     52 * @uses bp_get_option_blog_id()
     53 * @param str $option_name The option key to be set
     54 */
     55function bp_delete_option( $option_name ) {
     56    // update_blog_option() does not return anything on success/failure, so neither can we
     57    delete_blog_option( bp_get_option_blog_id( $option_name ), $option_name );
     58}
     59
     60/**
     61 * Retrieve the filterable blog_id of the blog where the option is question is saved
     62 *
     63 * Since BP 1.3, BuddyPress has stored all of its settings in blog options tables, as opposed to
     64 * sitemeta. This makes it easier for non-standard setups (like BP_ENABLE_MULTIBLOG and
     65 * multinetwork BP) to save and access options in a consistent and logical way.
     66 *
     67 * By default, nearly all settings are stored in the options table of BP_ROOT_BLOG. The one
     68 * exception is when BP_ENABLE_MULTIBLOG is enabled. In this case, bp-pages - the list of pages that
     69 * are associated with BP top-level components - must be specific to each blog in the network. If
     70 * you are building a plugin that requires an option (either a BP-native option, or your own custom
     71 * option) to be specific to each blog in a network, filter 'bp_blog_specific_options' and add your
     72 * option's name. This will allow you to use bp_get_option() and bp_update_option() seamlessly.
     73 *
     74 * @package BuddyPress
     75 * @since 1.3
     76 *
     77 * @see bp_get_option()
     78 * @see bp_update_option()
     79 * @uses apply_filters() Filter bp_get_option_blog_id to change this setting
     80 * @return int $blog_id
     81 */
     82function bp_get_option_blog_id( $option_name ) {
     83    $blog_specific_options = apply_filters( 'bp_blog_specific_options', array(
     84        'bp-pages'
     85    ) );
     86   
     87    if ( in_array( $option_name, $blog_specific_options ) ) {
     88        if ( defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ) {
     89            $blog_id = get_current_blog_id();
     90        } else {
     91            $blog_id = BP_ROOT_BLOG;
     92        }
     93    } else {
     94        $blog_id = BP_ROOT_BLOG;
     95    }
     96
     97    return apply_filters( 'bp_get_option_blog_id', $blog_id );
     98}
    299
    3100/**
     
    23120 */
    24121function bp_core_get_page_meta() {
    25     $page_ids = get_site_option( 'bp-pages' );
    26 
    27     $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
    28 
    29     $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
    30 
    31     // Upgrading from an earlier version of BP pre-1.3
    32     if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {
    33         if ( empty( $page_ids ) ) {
    34             // We're probably coming from an old multisite install
    35             $old_page_ids = get_blog_option( $page_blog_id, 'bp-pages' );
    36         } else {
    37             // We're probably coming from an old single-WP install
    38             $old_page_ids = $page_ids;
    39         }
    40 
    41         /**
    42          * If $page_ids is found in a blog_option, and it's formatted in the new way (keyed
    43          * by blog_id), it means that this is an MS upgrade. Return false and let the
    44          * upgrade wizard handle the migration.
    45          */
    46         if ( !isset( $old_page_ids['members'] ) )
    47             return false;
    48 
    49         // Finally, move the page ids over to site options
    50         $new_page_ids = array(
    51             $page_blog_id => $old_page_ids
    52         );
    53 
    54         update_site_option( 'bp-pages', $new_page_ids );
    55     }
    56 
    57     $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
    58 
    59     return apply_filters( 'bp_core_get_page_meta', $blog_page_ids );
     122    $page_ids = bp_get_option( 'bp-pages' );
     123 
     124    // Upgrading from an earlier version of BP pre-1.3
     125    if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) {
     126        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
     127 
     128        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
     129
     130        if ( isset( $ms_page_ids[$page_blog_id] ) ) {
     131            $page_ids = $ms_page_ids[$page_blog_id];
     132
     133            bp_update_option( 'bp-pages', $page_ids );
     134        }
     135    }
     136   
     137    return apply_filters( 'bp_core_get_page_meta', $page_ids );
    60138}
    61139
     
    72150 */
    73151function bp_core_update_page_meta( $blog_page_ids ) {
    74     if ( !$page_ids = get_site_option( 'bp-pages' ) )
    75         $page_ids = array();
    76 
    77     // Generally, we key by the BP_ROOT_BLOG. Exception: when BP_ENABLE_MULTIBLOG is turned on
    78     $key = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    79 
    80     $page_ids[$key] = $blog_page_ids;
    81 
    82     update_site_option( 'bp-pages', $page_ids );
     152    bp_update_option( 'bp-pages', $blog_page_ids );
    83153}
    84154
     
    875945 *
    876946 * @package BuddyPress Core
     947 * @todo Does this need to be here anymore after the introduction of bp_get_option etc?
    877948 */
    878949function bp_core_activate_site_options( $keys = array() ) {
     
    884955        foreach ( $keys as $key => $default ) {
    885956            if ( empty( $bp->site_options[ $key ] ) ) {
    886                 $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
    887 
    888                 if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
     957                $bp->site_options[ $key ] = bp_get_option( $key, $default );
     958
     959                if ( !bp_update_option( $key, $bp->site_options[ $key ] ) )
    889960                    $errors = true;
    890961            }
     
    908979    global $bp, $wpdb;
    909980
    910     // These options come from the options table in WP single, and sitemeta in MS
     981    // These options come from the options table
    911982    $site_options = apply_filters( 'bp_core_site_options', array(
    912983        'bp-deactivated-components',
     
    9361007    $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
    9371008
    938     if ( is_multisite() )
    939         $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}" );
    940     else
    941         $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
     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    }
    9421044
    9431045    $root_blog_meta_keys  = "'" . implode( "','", (array)$root_blog_options ) ."'";
     
    9491051        if ( !empty( $meta ) ) {
    9501052            foreach( (array)$meta as $meta_item ) {
    951                 $site_options[$meta_item->name] = $meta_item->value;
     1053                if ( isset( $meta_item->name ) )
     1054                    $site_options[$meta_item->name] = $meta_item->value;
    9521055            }
    9531056        }
  • trunk/bp-core/bp-core-loader.php

    r4556 r4559  
    2222    require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php'  );
    2323
     24// Move active components from sitemeta, if necessary
     25// Provides backpat with earlier versions of BP
     26if ( is_multisite() && $active_components = get_site_option( 'bp-active-components' ) )
     27    bp_update_option( 'bp-active-components', $active_components );
     28
    2429/** "And now for something completely different" ******************************/
    2530
     
    6772
    6873        // Get a list of activated components
    69         if ( $active_components = get_site_option( 'bp-active-components' ) ) {
     74        if ( $active_components = bp_get_option( 'bp-active-components' ) ) {
    7075            $bp->active_components      = apply_filters( 'bp_active_components', $active_components );
    7176            $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) );
    7277
    7378        // Pre 1.3 Backwards compatibility
    74         } elseif ( $deactivated_components = get_site_option( 'bp-deactivated-components' ) ) {
     79        } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
    7580            // Trim off namespace and filename
    7681            foreach ( (array) $deactivated_components as $component => $value )
  • trunk/bp-core/bp-core-template.php

    r4554 r4559  
    442442}
    443443
    444 function bp_get_option( $option_name ) {
    445     global $bp;
    446 
    447     if ( !empty( $bp->site_options[$option_name] ) )
    448         $retval = $bp->site_options[$option_name];
    449     else
    450         $retval = false;
    451 
    452     return apply_filters( 'bp_get_option', $retval );
    453 }
    454 
    455444/**
    456445 * Allow templates to pass parameters directly into the template loops via AJAX
  • trunk/bp-core/bp-core-wpabstraction.php

    r4456 r4559  
    1717
    1818    $wpdb->base_prefix = $wpdb->prefix;
    19     $wpdb->blogid      = 1;
     19    $wpdb->blogid      = BP_ROOT_BLOG;
    2020
    2121    if ( !function_exists( 'get_blog_option' ) ) {
    2222        function get_blog_option( $blog_id, $option_name, $default = false ) {
    2323            return get_option( $option_name, $default );
     24        }
     25    }
     26   
     27    if ( !function_exists( 'update_blog_option' ) ) {
     28        function update_blog_option( $blog_id, $option_name, $value ) {
     29            return update_option( $option_name, $value );
    2430        }
    2531    }
  • trunk/bp-forums/bp-forums-admin.php

    r4482 r4559  
    144144    }
    145145
    146     update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
     146    bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
    147147
    148148    if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
     
    215215    }
    216216
    217     update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
     217    bp_update_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
    218218    return $initial_write;
    219219}
  • trunk/bp-groups/bp-groups-template.php

    r4524 r4559  
    19291929 *
    19301930 * @uses apply_filters() To call 'bp_user_can_create_groups'.
    1931  * @uses get_site_option() To retrieve value of 'bp_restrict_group_creation'. Defaults to 0.
     1931 * @uses bp_get_option() To retrieve value of 'bp_restrict_group_creation'. Defaults to 0.
    19321932 * @uses is_super_admin() To determine if current user if super admin.
    19331933 *
     
    19401940
    19411941    // Get group creation option, default to 0 (allowed)
    1942     $restricted = (int) get_site_option( 'bp_restrict_group_creation', 0 );
     1942    $restricted = (int) bp_get_option( 'bp_restrict_group_creation', 0 );
    19431943
    19441944    // Allow by default
  • trunk/bp-members/bp-members-functions.php

    r4558 r4559  
    528528 * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
    529529 * @uses wp_delete_user() Deletes a user from the system on singlesite installs.
    530  * @uses get_site_option Checks if account deletion is allowed
    531530 */
    532531function bp_core_delete_account( $user_id = 0 ) {
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r4364 r4559  
    5050
    5151        <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress'); ?></p>
    52         <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( get_site_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p>
     52        <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p>
    5353
    5454        <form action="" id="profile-field-form" method="post">
Note: See TracChangeset for help on using the changeset viewer.