Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/04/2011 04:59:01 PM (13 years ago)
Author:
johnjamesjacoby
Message:
  • Swap BP_ROOT_BLOG const usage for new bp_get_root_blog_id() function
  • Use bp_get_root_blog_id() place of bp_get_option_blog_id()
  • Check for BP_ENABLE_MULTIBLOG when assigning root blog ID

See #3313, #3314.

File:
1 edited

Legend:

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

    r4596 r4602  
    1212 * @since 1.3
    1313 *
    14  * @uses bp_get_option_blog_id()
     14 * @uses bp_get_root_blog_id()
    1515 * @param str $option_name The option to be retrieved
    1616 * @param str $default Optional. Default value to be returned if the option isn't set
     
    1818 */
    1919function bp_get_option( $option_name, $default = '' ) {
    20     $value = get_blog_option( bp_get_option_blog_id( $option_name ), $option_name, $default );
     20    $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
    2121   
    2222    return apply_filters( 'bp_get_option', $value );
     
    3232 * @since 1.3
    3333 *
    34  * @uses bp_get_option_blog_id()
     34 * @uses bp_get_root_blog_id()
    3535 * @param str $option_name The option key to be set
    3636 * @param str $value The value to be set
    3737 */
    3838function 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 );
     39    update_blog_option( bp_get_root_blog_id(), $option_name, $value );
    4140}
    4241
     
    5049 * @since 1.3
    5150 *
    52  * @uses bp_get_option_blog_id()
     51 * @uses bp_get_root_blog_id()
    5352 * @param str $option_name The option key to be set
    5453 */
    5554function 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  */
    82 function 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 );
     55    delete_blog_option( bp_get_root_blog_id(), $option_name );
    9856}
    9957
     
    12684        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
    12785 
    128         $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
     86        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : bp_get_root_blog_id();
    12987
    13088        if ( isset( $ms_page_ids[$page_blog_id] ) ) {
     
    142100 *
    143101 * bp-pages data is stored in site_options (falls back to options on non-MS), in an array keyed by
    144  * blog_id. This allows you to change your BP_ROOT_BLOG and go through the setup process again.
     102 * blog_id. This allows you to change your bp_get_root_blog_id() and go through the setup process again.
    145103 *
    146104 * @package BuddyPress Core
     
    170128    if ( $page_ids = bp_core_get_page_meta() ) {
    171129
    172         $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
     130        $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts' : $wpdb->posts;
    173131        $page_ids_sql     = implode( ',', (array)$page_ids );
    174132        $page_names       = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
     
    513471    global $wpdb;
    514472
    515     if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
    516         $domain = get_home_url( $wpdb->blogid );
    517     else
    518         $domain = get_home_url( BP_ROOT_BLOG );
     473    $domain = get_home_url( bp_get_root_blog_id() );
    519474
    520475    return apply_filters( 'bp_core_get_root_domain', $domain );
     
    10971052
    10981053/**
    1099  * Is this BP_ROOT_BLOG?
     1054 * Is this the root blog ID?
    11001055 *
    11011056 * @package BuddyPress
     
    11031058 *
    11041059 * @param int $blog_id Optional. Defaults to the current blog id.
    1105  * @return bool $is_root_blog Returns true if this is BP_ROOT_BLOG.
    1106  */
    1107 function bp_is_root_blog( $blog_id = false ) {
    1108     $is_root_blog = true;
    1109 
    1110     if ( !$blog_id )
     1060 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
     1061 */
     1062function bp_is_root_blog( $blog_id = 0 ) {
     1063   
     1064    // Assume false
     1065    $is_root_blog = false;
     1066
     1067    // Use current blog if no ID is passed
     1068    if ( empty( $blog_id ) )
    11111069        $blog_id = get_current_blog_id();
    11121070
    1113     if ( $blog_id != BP_ROOT_BLOG )
    1114         $is_root_blog = false;
    1115 
    1116     return apply_filters( 'bp_is_root_blog', $is_root_blog );
     1071    // Compare to root blog ID
     1072    if ( $blog_id == bp_get_root_blog_id() )
     1073        $is_root_blog = true;
     1074
     1075    return apply_filters( 'bp_is_root_blog', (bool) $is_root_blog );
     1076}
     1077
     1078/**
     1079 * Is this bp_get_root_blog_id()?
     1080 *
     1081 * @package BuddyPress
     1082 * @since 1.3
     1083 *
     1084 * @param int $blog_id Optional. Defaults to the current blog id.
     1085 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
     1086 */
     1087function bp_get_root_blog_id( $blog_id = false ) {
     1088
     1089    // Define on which blog ID BuddyPress should run
     1090    if ( !defined( 'BP_ROOT_BLOG' ) ) {
     1091
     1092        // Root blog is the main site on this network
     1093        if ( is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
     1094            $current_site = get_current_site();
     1095            $root_blog_id = $current_site->blog_id;
     1096
     1097        // Root blog is every site on this network
     1098        } elseif ( is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) ) {
     1099            $root_blog_id = get_current_blog_id();
     1100
     1101        // Root blog is the only blog on this network
     1102        } elseif( !is_multisite() ) {
     1103            $root_blog_id = 1;
     1104        }
     1105
     1106        define( 'BP_ROOT_BLOG', $root_blog_id );
     1107       
     1108    // Root blog is defined
     1109    } else {
     1110        $root_blog_id = BP_ROOT_BLOG;
     1111    }
     1112
     1113    return apply_filters( 'bp_get_root_blog_id', (int) $root_blog_id );
    11171114}
    11181115
Note: See TracChangeset for help on using the changeset viewer.