Skip to:
Content

BuddyPress.org

Ticket #6045: 6045.patch

File 6045.patch, 10.7 KB (added by boonebgorges, 10 years ago)
  • src/bp-activity/bp-activity-template.php

    diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
    index d33d1f3..a936f31 100644
    class BP_Activity_Template { 
    217217                $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    218218
    219219                // 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' );
    221221
    222222                // Get an array of the logged in user's favorite activities
    223223                $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );
  • src/bp-blogs/bp-blogs-filters.php

    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, 
    8686         * Stop infinite loops with WordPress MU Sitewide Tags.
    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
    9698        /**
  • src/bp-blogs/bp-blogs-template.php

    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 ) { 
    11141114function bp_blog_signup_enabled() {
    11151115        global $bp;
    11161116
    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        }
    11181121
    11191122        /**
    11201123         * Filters whether or not blog creation is enabled.
  • src/bp-core/bp-core-avatars.php

    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() { 
    3131
    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        }
    4041
  • src/bp-core/bp-core-options.php

    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() { 
    432432        return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
    433433}
    434434
     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 */
     447function 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
    435462/** Active? *******************************************************************/
    436463
    437464/**
  • src/bp-core/bp-core-template.php

    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() { 
    712712                        return false;
    713713                }
    714714
    715                 $status = buddypress()->site_options['registration'];
     715                $status = bp_core_get_root_option( 'registration' );
    716716                if ( ( 'none' !== $status ) && ( 'user' !== $status ) ) {
    717717                        return true;
    718718                }
  • src/bp-forums/bp-forums-loader.php

    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 { 
    5757                        define( 'BP_FORUMS_SLUG', $this->id );
    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.
    6465                // Note that global_tables is included in this array.
  • src/bp-groups/bp-groups-loader.php

    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 { 
    270270                ) );
    271271
    272272                // 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 ) {
    274275                        $this->group_creation_steps['group-avatar'] = array(
    275276                                'name'     => _x( 'Photo', 'Group screen nav', 'buddypress' ),
    276277                                'position' => 20
  • src/bp-members/bp-members-screens.php

    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() { 
    118118
    119119                // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled
    120120                if ( isset( $_POST['signup_with_blog'] ) ) {
    121                         $active_signup = $bp->site_options['registration'];
     121                        $active_signup = bp_core_get_root_option( 'registration' );
    122122
    123123                        if ( 'blog' == $active_signup || 'all' == $active_signup ) {
    124124                                $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
    function bp_core_screen_signup() { 
    145145                        $bp->signup->step = 'save-details';
    146146
    147147                        // 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' );
    149149
    150150                        if ( 'none' != $active_signup ) {
    151151
  • src/bp-members/bp-members-template.php

    diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php
    index b4a3fbf..6bbb137 100644
    function bp_signup_allowed() { 
    18091809                $signup_allowed = false;
    18101810
    18111811                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' );
    18151813
    1816                         if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) ) {
     1814                        if ( in_array( $registration, array( 'all', 'user' ) ) ) {
    18171815                                $signup_allowed = true;
    18181816                        }
    18191817
  • src/bp-settings/bp-settings-loader.php

    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 { 
    183183                        }
    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,
    189189                                        'id'     => 'my-account-' . $this->id . '-delete-account',
  • src/bp-xprofile/bp-xprofile-loader.php

    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 { 
    9191                // to use in SQL statements.
    9292                // Defined conditionally to accommodate unit tests
    9393                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' ) ) );
    9595                }
    9696
    9797                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' ) ) );
    9999                }
    100100
    101101                // Set the support field type ids
  • tests/phpunit/testcases/core/functions.php

    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 { 
    563563        }
    564564
    565565        /**
     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        /**
    566592         * @group bp_core_add_root_component
    567593         */
    568594        public function test_add_root_component_not_in_bp_pages() {