diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
index d33d1f3..a936f31 100644
|
|
class BP_Activity_Template { |
217 | 217 | $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; |
218 | 218 | |
219 | 219 | // Check if blog/forum replies are disabled |
220 | | $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false; |
| 220 | $this->disable_blogforum_replies = (bool) bp_core_get_root_option( 'bp-disabled-blogforum-comments' ); |
221 | 221 | |
222 | 222 | // Get an array of the logged in user's favorite activities |
223 | 223 | $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) ); |
diff --git src/bp-blogs/bp-blogs-filters.php src/bp-blogs/bp-blogs-filters.php
index 47ee940..53ad999 100644
|
|
function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, |
86 | 86 | * Stop infinite loops with WordPress MU Sitewide Tags. |
87 | 87 | * That plugin changed the way its settings were stored at some point. Thus the dual check. |
88 | 88 | */ |
89 | | if ( ! empty( $bp->site_options['sitewide_tags_blog'] ) ) { |
90 | | $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] ); |
| 89 | $sitewide_tags_blog_settings = bp_core_get_root_option( 'sitewide_tags_blog' ); |
| 90 | if ( ! empty( $sitewide_tags_blog_settings ) ) { |
| 91 | $st_options = maybe_unserialize( $sitewide_tags_blog_settings ); |
91 | 92 | $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0; |
92 | 93 | } else { |
93 | | $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0; |
| 94 | $tags_blog_id = bp_core_get_root_option( 'sitewide_tags_blog' ); |
| 95 | $tags_blog_id = intval( $tags_blog_id ); |
94 | 96 | } |
95 | 97 | |
96 | 98 | /** |
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php
index 838f54f..49e37a5 100644
|
|
function bp_total_blog_count_for_user( $user_id = 0 ) { |
1114 | 1114 | function bp_blog_signup_enabled() { |
1115 | 1115 | global $bp; |
1116 | 1116 | |
1117 | | $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all'; |
| 1117 | $active_signup = bp_core_get_root_option( 'registration' ); |
| 1118 | if ( ! $active_signup ) { |
| 1119 | $active_signup = 'all'; |
| 1120 | } |
1118 | 1121 | |
1119 | 1122 | /** |
1120 | 1123 | * Filters whether or not blog creation is enabled. |
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php
index b98b24b..abb0e9d 100644
|
|
function bp_core_set_avatar_constants() { |
31 | 31 | |
32 | 32 | if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) { |
33 | 33 | |
34 | | if ( !isset( $bp->site_options['fileupload_maxk'] ) ) { |
| 34 | $fileupload_maxk = bp_core_get_root_option( 'fileupload_maxk' ); |
| 35 | if ( '' === $fileupload_maxk ) { |
35 | 36 | define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb |
36 | 37 | } else { |
37 | | define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 ); |
| 38 | define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $fileupload_maxk * 1024 ); |
38 | 39 | } |
39 | 40 | } |
40 | 41 | |
diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php
index f927069..20110d1 100644
|
|
function bp_core_get_root_options() { |
432 | 432 | return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta ); |
433 | 433 | } |
434 | 434 | |
| 435 | /** |
| 436 | * Get a root option. |
| 437 | * |
| 438 | * "Root options" are those that apply across an entire installation, and are |
| 439 | * fetched only a single time during a pageload and stored in buddypress()-> |
| 440 | * site_options to prevent future lookups. See {@see bp_core_get_root_options()}. |
| 441 | * |
| 442 | * @since BuddyPress 2.2.0 |
| 443 | * |
| 444 | * @param string $option Name of the option key. |
| 445 | * @return mixed Value, if found. |
| 446 | */ |
| 447 | function bp_core_get_root_option( $option ) { |
| 448 | $bp = buddypress(); |
| 449 | |
| 450 | if ( ! isset( $bp->site_options ) ) { |
| 451 | $bp->site_options = bp_core_get_root_options(); |
| 452 | } |
| 453 | |
| 454 | $value = ''; |
| 455 | if ( isset( $bp->site_options[ $option ] ) ) { |
| 456 | $value = $bp->site_options[ $option ]; |
| 457 | } |
| 458 | |
| 459 | return $value; |
| 460 | } |
| 461 | |
435 | 462 | /** Active? *******************************************************************/ |
436 | 463 | |
437 | 464 | /** |
diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php
index 5b631d2..845f0ea 100644
|
|
function bp_blog_signup_allowed() { |
712 | 712 | return false; |
713 | 713 | } |
714 | 714 | |
715 | | $status = buddypress()->site_options['registration']; |
| 715 | $status = bp_core_get_root_option( 'registration' ); |
716 | 716 | if ( ( 'none' !== $status ) && ( 'user' !== $status ) ) { |
717 | 717 | return true; |
718 | 718 | } |
diff --git src/bp-forums/bp-forums-loader.php src/bp-forums/bp-forums-loader.php
index bbabdd4..ab737be 100644
|
|
class BP_Forums_Component extends BP_Component { |
57 | 57 | define( 'BP_FORUMS_SLUG', $this->id ); |
58 | 58 | |
59 | 59 | // The location of the bbPress stand-alone config file |
60 | | if ( isset( $bp->site_options['bb-config-location'] ) ) |
61 | | $this->bbconfig = $bp->site_options['bb-config-location']; |
| 60 | $bbconfig = bp_core_get_root_option( 'bb-config-location' ); |
| 61 | if ( '' !== $bbconfig ) |
| 62 | $this->bbconfig = $bbconfig; |
62 | 63 | |
63 | 64 | // All globals for messaging component. |
64 | 65 | // Note that global_tables is included in this array. |
diff --git src/bp-groups/bp-groups-loader.php src/bp-groups/bp-groups-loader.php
index d12712f..d3155c7 100644
|
|
class BP_Groups_Component extends BP_Component { |
270 | 270 | ) ); |
271 | 271 | |
272 | 272 | // If avatar uploads are not disabled, add avatar option |
273 | | if ( ! (int) $bp->site_options['bp-disable-avatar-uploads'] && $bp->avatar->show_avatars ) { |
| 273 | $disabled_avatar_uploads = (int) bp_core_get_root_option( 'bp-disable-avatar-uploads' ); |
| 274 | if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) { |
274 | 275 | $this->group_creation_steps['group-avatar'] = array( |
275 | 276 | 'name' => _x( 'Photo', 'Group screen nav', 'buddypress' ), |
276 | 277 | 'position' => 20 |
diff --git src/bp-members/bp-members-screens.php src/bp-members/bp-members-screens.php
index 66156f0..ea56267 100644
|
|
function bp_core_screen_signup() { |
118 | 118 | |
119 | 119 | // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled |
120 | 120 | if ( isset( $_POST['signup_with_blog'] ) ) { |
121 | | $active_signup = $bp->site_options['registration']; |
| 121 | $active_signup = bp_core_get_root_option( 'registration' ); |
122 | 122 | |
123 | 123 | if ( 'blog' == $active_signup || 'all' == $active_signup ) { |
124 | 124 | $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] ); |
… |
… |
function bp_core_screen_signup() { |
145 | 145 | $bp->signup->step = 'save-details'; |
146 | 146 | |
147 | 147 | // No errors! Let's register those deets. |
148 | | $active_signup = !empty( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : ''; |
| 148 | $active_signup = bp_core_get_root_option( 'registration' ); |
149 | 149 | |
150 | 150 | if ( 'none' != $active_signup ) { |
151 | 151 | |
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php
index b4a3fbf..6bbb137 100644
|
|
function bp_signup_allowed() { |
1809 | 1809 | $signup_allowed = false; |
1810 | 1810 | |
1811 | 1811 | if ( is_multisite() ) { |
1812 | | if ( ! isset( $bp->site_options ) ) { |
1813 | | $bp->site_options = bp_core_get_root_options(); |
1814 | | } |
| 1812 | $registration = bp_core_get_root_option( 'registration' ); |
1815 | 1813 | |
1816 | | if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) ) { |
| 1814 | if ( in_array( $registration, array( 'all', 'user' ) ) ) { |
1817 | 1815 | $signup_allowed = true; |
1818 | 1816 | } |
1819 | 1817 | |
diff --git src/bp-settings/bp-settings-loader.php src/bp-settings/bp-settings-loader.php
index aa36634..4709dca 100644
|
|
class BP_Settings_Component extends BP_Component { |
183 | 183 | } |
184 | 184 | |
185 | 185 | // Delete Account |
186 | | if ( !bp_current_user_can( 'bp_moderate' ) && empty( $bp->site_options['bp-disable-account-deletion'] ) ) { |
| 186 | if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { |
187 | 187 | $wp_admin_nav[] = array( |
188 | 188 | 'parent' => 'my-account-' . $this->id, |
189 | 189 | 'id' => 'my-account-' . $this->id . '-delete-account', |
diff --git src/bp-xprofile/bp-xprofile-loader.php src/bp-xprofile/bp-xprofile-loader.php
index 9d49fab..b4f4e2e 100644
|
|
class BP_XProfile_Component extends BP_Component { |
91 | 91 | // to use in SQL statements. |
92 | 92 | // Defined conditionally to accommodate unit tests |
93 | 93 | if ( ! defined( 'BP_XPROFILE_BASE_GROUP_NAME' ) ) { |
94 | | define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( $bp->site_options['bp-xprofile-base-group-name'] ) ); |
| 94 | define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( bp_core_get_root_option( 'avatar_default' ) ) ); |
95 | 95 | } |
96 | 96 | |
97 | 97 | if ( ! defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) ) { |
98 | | define( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ) ); |
| 98 | define( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( bp_core_get_root_option( 'bp-xprofile-fullname-field-name' ) ) ); |
99 | 99 | } |
100 | 100 | |
101 | 101 | // Set the support field type ids |
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php
index a749eb3..78ba6bb 100644
|
|
class BP_Tests_Core_Functions extends BP_UnitTestCase { |
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
| 566 | * @group bp_core_get_root_option |
| 567 | */ |
| 568 | public function test_bp_core_get_root_option_with_unpopulated_cache() { |
| 569 | // Back up and unset global cache. |
| 570 | $old_options = buddypress()->site_options; |
| 571 | unset( buddypress()->site_options ); |
| 572 | |
| 573 | $this->assertSame( $old_options['avatar_default'], bp_core_get_root_option( 'avatar_default' ) ); |
| 574 | |
| 575 | // Clean up. |
| 576 | buddypress()->site_options = $old_options; |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * @group bp_core_get_root_option |
| 581 | */ |
| 582 | public function test_bp_core_get_root_option_with_populated_cache() { |
| 583 | // Back up and unset global cache. |
| 584 | $old_options = buddypress()->site_options; |
| 585 | buddypress()->site_options = bp_core_get_root_options(); |
| 586 | $expected = buddypress()->site_options['avatar_default']; |
| 587 | |
| 588 | $this->assertSame( $expected, bp_core_get_root_option( 'avatar_default' ) ); |
| 589 | } |
| 590 | |
| 591 | /** |
566 | 592 | * @group bp_core_add_root_component |
567 | 593 | */ |
568 | 594 | public function test_add_root_component_not_in_bp_pages() { |