Changeset 4602 for trunk/bp-core/bp-core-functions.php
- Timestamp:
- 07/04/2011 04:59:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-functions.php
r4596 r4602 12 12 * @since 1.3 13 13 * 14 * @uses bp_get_ option_blog_id()14 * @uses bp_get_root_blog_id() 15 15 * @param str $option_name The option to be retrieved 16 16 * @param str $default Optional. Default value to be returned if the option isn't set … … 18 18 */ 19 19 function 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 ); 21 21 22 22 return apply_filters( 'bp_get_option', $value ); … … 32 32 * @since 1.3 33 33 * 34 * @uses bp_get_ option_blog_id()34 * @uses bp_get_root_blog_id() 35 35 * @param str $option_name The option key to be set 36 36 * @param str $value The value to be set 37 37 */ 38 38 function 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 ); 41 40 } 42 41 … … 50 49 * @since 1.3 51 50 * 52 * @uses bp_get_ option_blog_id()51 * @uses bp_get_root_blog_id() 53 52 * @param str $option_name The option key to be set 54 53 */ 55 54 function 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 ); 98 56 } 99 57 … … 126 84 $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false; 127 85 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(); 129 87 130 88 if ( isset( $ms_page_ids[$page_blog_id] ) ) { … … 142 100 * 143 101 * 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_BLOGand 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. 145 103 * 146 104 * @package BuddyPress Core … … 170 128 if ( $page_ids = bp_core_get_page_meta() ) { 171 129 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; 173 131 $page_ids_sql = implode( ',', (array)$page_ids ); 174 132 $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' " ) ); … … 513 471 global $wpdb; 514 472 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() ); 519 474 520 475 return apply_filters( 'bp_core_get_root_domain', $domain ); … … 1097 1052 1098 1053 /** 1099 * Is this BP_ROOT_BLOG?1054 * Is this the root blog ID? 1100 1055 * 1101 1056 * @package BuddyPress … … 1103 1058 * 1104 1059 * @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 */ 1062 function 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 ) ) 1111 1069 $blog_id = get_current_blog_id(); 1112 1070 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 */ 1087 function 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 ); 1117 1114 } 1118 1115
Note: See TracChangeset
for help on using the changeset viewer.