Skip to:
Content

BuddyPress.org

Changeset 9698


Ignore:
Timestamp:
04/05/2015 06:18:13 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce bp_core_get_root_option() and use throughout BP.

Previously, we referenced the $bp->site_options array directly. This causes
problems in cases where these options may be referenced before the array is
initially populated. bp_core_get_root_option() will fetch the requested
value from the array if it's been populated, and will populate it if it has not.

Fixes #6045.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-template.php

    r9665 r9698  
    296296
    297297                // Check if blog/forum replies are disabled
    298                 $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false;
     298                $this->disable_blogforum_replies = (bool) bp_core_get_root_option( 'bp-disabled-blogforum-comments' );
    299299
    300300                // Get an array of the logged in user's favorite activities
  • trunk/src/bp-blogs/bp-blogs-filters.php

    r9472 r9698  
    8787         * That plugin changed the way its settings were stored at some point. Thus the dual check.
    8888         */
    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 );
    9192                $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
    9293        } 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 );
    9496        }
    9597
  • trunk/src/bp-core/bp-core-avatars.php

    r9624 r9698  
    3232        if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
    3333
    34                 if ( !isset( $bp->site_options['fileupload_maxk'] ) ) {
     34                $fileupload_maxk = bp_core_get_root_option( 'fileupload_maxk' );
     35                if ( '' === $fileupload_maxk ) {
    3536                        define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
    3637                } else {
    37                         define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
     38                        define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $fileupload_maxk * 1024 );
    3839                }
    3940        }
  • trunk/src/bp-core/bp-core-options.php

    r9598 r9698  
    482482}
    483483
     484/**
     485 * Get a root option.
     486 *
     487 * "Root options" are those that apply across an entire installation, and are fetched only a single
     488 * time during a pageload and stored in `buddypress()->site_options` to prevent future lookups.
     489 * See {@see bp_core_get_root_options()}.
     490 *
     491 * @since BuddyPress (2.3.0)
     492 *
     493 * @param  string $option Name of the option key.
     494 * @return mixed Value, if found.
     495 */
     496function bp_core_get_root_option( $option ) {
     497        $bp = buddypress();
     498
     499        if ( ! isset( $bp->site_options ) ) {
     500                $bp->site_options = bp_core_get_root_options();
     501        }
     502
     503        $value = '';
     504        if ( isset( $bp->site_options[ $option ] ) ) {
     505                $value = $bp->site_options[ $option ];
     506        }
     507
     508        return $value;
     509}
     510
    484511/** Active? *******************************************************************/
    485512
  • trunk/src/bp-core/bp-core-template.php

    r9618 r9698  
    820820                }
    821821
    822                 $status = buddypress()->site_options['registration'];
     822                $status = bp_core_get_root_option( 'registration' );
    823823                if ( ( 'none' !== $status ) && ( 'user' !== $status ) ) {
    824824                        return true;
  • trunk/src/bp-forums/bp-forums-loader.php

    r9351 r9698  
    5858
    5959                // 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;
    6263
    6364                // All globals for messaging component.
  • trunk/src/bp-groups/bp-groups-loader.php

    r9454 r9698  
    299299
    300300                // If avatar uploads are not disabled, add avatar option
    301                 if ( ! (int) $bp->site_options['bp-disable-avatar-uploads'] && $bp->avatar->show_avatars ) {
     301                $disabled_avatar_uploads = (int) bp_core_get_root_option( 'bp-disable-avatar-uploads' );
     302                if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) {
    302303                        $this->group_creation_steps['group-avatar'] = array(
    303304                                'name'     => _x( 'Photo', 'Group screen nav', 'buddypress' ),
  • trunk/src/bp-members/bp-members-screens.php

    r9471 r9698  
    157157                // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled
    158158                if ( isset( $_POST['signup_with_blog'] ) ) {
    159                         $active_signup = $bp->site_options['registration'];
     159                        $active_signup = bp_core_get_root_option( 'registration' );
    160160
    161161                        if ( 'blog' == $active_signup || 'all' == $active_signup ) {
     
    197197
    198198                        // No errors! Let's register those deets.
    199                         $active_signup = !empty( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : '';
     199                        $active_signup = bp_core_get_root_option( 'registration' );
    200200
    201201                        if ( 'none' != $active_signup ) {
  • trunk/src/bp-members/bp-members-template.php

    r9665 r9698  
    22452245
    22462246                if ( is_multisite() ) {
    2247                         if ( ! isset( $bp->site_options ) ) {
    2248                                 $bp->site_options = bp_core_get_root_options();
    2249                         }
    2250 
    2251                         if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) ) {
     2247                        $registration = bp_core_get_root_option( 'registration' );
     2248
     2249                        if ( in_array( $registration, array( 'all', 'user' ) ) ) {
    22522250                                $signup_allowed = true;
    22532251                        }
  • trunk/src/bp-settings/bp-settings-loader.php

    r9351 r9698  
    184184
    185185                        // 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' ) ) {
    187187                                $wp_admin_nav[] = array(
    188188                                        'parent' => 'my-account-' . $this->id,
  • trunk/src/bp-xprofile/bp-xprofile-loader.php

    r9676 r9698  
    9696                // Defined conditionally to accommodate unit tests
    9797                if ( ! defined( 'BP_XPROFILE_BASE_GROUP_NAME' ) ) {
    98                         define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( $bp->site_options['bp-xprofile-base-group-name'] ) );
     98                        define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( bp_core_get_root_option( 'avatar_default' ) ) );
    9999                }
    100100
    101101                if ( ! defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) ) {
    102                         define( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ) );
     102                        define( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( bp_core_get_root_option( 'bp-xprofile-fullname-field-name' ) ) );
    103103                }
    104104
  • trunk/tests/phpunit/testcases/core/functions.php

    r9616 r9698  
    522522
    523523        /**
     524         * @group bp_core_get_root_option
     525         */
     526        public function test_bp_core_get_root_option_with_unpopulated_cache() {
     527                // Back up and unset global cache.
     528                $old_options = buddypress()->site_options;
     529                unset( buddypress()->site_options );
     530
     531                $this->assertSame( $old_options['avatar_default'], bp_core_get_root_option( 'avatar_default' ) );
     532
     533                // Clean up.
     534                buddypress()->site_options = $old_options;
     535        }
     536
     537        /**
     538         * @group bp_core_get_root_option
     539         */
     540        public function test_bp_core_get_root_option_with_populated_cache() {
     541                // Back up and unset global cache.
     542                $old_options = buddypress()->site_options;
     543                buddypress()->site_options = bp_core_get_root_options();
     544                $expected = buddypress()->site_options['avatar_default'];
     545
     546                $this->assertSame( $expected, bp_core_get_root_option( 'avatar_default' ) );
     547        }
     548
     549        /**
    524550         * @group bp_core_add_root_component
    525551         */
Note: See TracChangeset for help on using the changeset viewer.