Skip to:
Content

BuddyPress.org

Changeset 7192


Ignore:
Timestamp:
06/09/2013 01:39:07 PM (11 years ago)
Author:
boonebgorges
Message:

Refines the way that BP_ROOT_BLOG is calculated on multisite installations

BP was originally a 'network: true' plugin, making it possible to assume blog 1
as the default value of BP_ROOT_BLOG on a multisite installation, unless
otherwise declared. When the network-only restriction was lifted, it became
possible to activate BP only on a secondary site in a network, in which case
the default value 1 of BP_ROOT_BLOG no longer applies.

This changeset reworks the logic used to calculate BP_ROOT_BLOG, starting with
the assumption that it is the current blog, and only changing it to the
current site's blog_id (blog 1, in non-multi-network setups) when the plugin
is indeed network-activated.

This fixes a number of problems, notably one where it was impossible to set up
the bp-pages associations, because the Pages dropdowns were populated from blog
1 when BP was active only on a secondary blog of a network.

Fixes #4917

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-loader.php

    r7167 r7192  
    224224            require( WP_PLUGIN_DIR . '/bp-custom.php' );
    225225
    226         // Define on which blog ID BuddyPress should run
    227         if ( !defined( 'BP_ROOT_BLOG' ) ) {
    228 
    229             // Default to 1
    230             $root_blog_id = 1;
    231 
    232             // Root blog is the main site on this network
    233             if ( is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    234                 $current_site = get_current_site();
    235                 $root_blog_id = $current_site->blog_id;
    236 
    237             // Root blog is every site on this network
    238             } elseif ( is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    239                 $root_blog_id = get_current_blog_id();
    240             }
    241 
    242             define( 'BP_ROOT_BLOG', $root_blog_id );
     226        // Path and URL
     227        if ( ! defined( 'BP_PLUGIN_DIR' ) ) {
     228            define( 'BP_PLUGIN_DIR', trailingslashit( WP_PLUGIN_DIR . '/buddypress' ) );
    243229        }
    244230
    245         // Path and URL
    246         if ( !defined( 'BP_PLUGIN_DIR' ) )
    247             define( 'BP_PLUGIN_DIR', trailingslashit( WP_PLUGIN_DIR . '/buddypress' ) );
    248 
    249         if ( !defined( 'BP_PLUGIN_URL' ) ) {
     231        if ( ! defined( 'BP_PLUGIN_URL' ) ) {
    250232            $plugin_url = plugin_dir_url( __FILE__ );
    251233
     
    255237
    256238            define( 'BP_PLUGIN_URL', $plugin_url );
     239        }
     240
     241        // Define on which blog ID BuddyPress should run
     242        if ( ! defined( 'BP_ROOT_BLOG' ) ) {
     243
     244            // Default to use current blog ID
     245            // Fulfills non-network installs and BP_ENABLE_MULTIBLOG installs
     246            $root_blog_id = get_current_blog_id();
     247
     248            // Multisite check
     249            if ( is_multisite() ) {
     250
     251                // Multiblog isn't enabled
     252                if ( ! defined( 'BP_ENABLE_MULTIBLOG' ) || ( defined( 'BP_ENABLE_MULTIBLOG' ) && (int) constant( 'BP_ENABLE_MULTIBLOG' ) === 0 ) ) {
     253                    // Check to see if BP is network-activated
     254                    // We're not using is_plugin_active_for_network() b/c you need to include the
     255                    // /wp-admin/includes/plugin.php file in order to use that function.
     256
     257                    // get network-activated plugins
     258                    $plugins = get_site_option( 'active_sitewide_plugins');
     259                   
     260                    // basename
     261                    $basename = plugin_basename( constant( 'BP_PLUGIN_DIR' ) . 'bp-loader.php' );
     262
     263                    // plugin is network-activated; use main site ID instead
     264                    if ( isset( $plugins[ $basename ] ) ) {
     265                        $current_site = get_current_site();
     266                        $root_blog_id = $current_site->blog_id;
     267                    }
     268                }
     269
     270            }
     271
     272            define( 'BP_ROOT_BLOG', $root_blog_id );
    257273        }
    258274
Note: See TracChangeset for help on using the changeset viewer.