Skip to:
Content

BuddyPress.org

Changeset 8323


Ignore:
Timestamp:
04/26/2014 05:13:30 PM (10 years ago)
Author:
boonebgorges
Message:

Don't attempt to overload add_root property in bp_core_add_root_component()

The add_root array is defined only for backward compatibility purposes in the
BuddyPress global object, and thus is overloaded rather than defined in the
constructor. This means that adding items directly to the array is forbidden
on recent versions of PHP. As a workaround, we add the item as a separate array
and then swap the array, which is allowed and will not result in notices.

Fixes #5588

Location:
trunk
Files:
2 edited

Legend:

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

    r8185 r8323  
    562562    // If there was no match, add a page for this root component
    563563    if ( empty( $match ) ) {
    564         $bp->add_root[] = $slug;
     564        $add_root_items   = $bp->add_root();
     565        $add_root_items[] = $slug;
     566        $bp->add_root     = $add_root_items;
    565567    }
    566568
  • trunk/tests/testcases/core/functions.php

    r7819 r8323  
    331331        }
    332332    }
     333
     334    /**
     335     * @group bp_core_add_root_component
     336     */
     337    public function test_add_root_component_not_in_bp_pages() {
     338        buddypress()->foo = new stdClass;
     339        buddypress()->foo->id = 'foo';
     340        buddypress()->foo->slug = 'foo';
     341
     342        bp_core_add_root_component( 'foo' );
     343
     344        $this->assertTrue( in_array( 'foo', buddypress()->add_root ) );
     345        $this->assertTrue( buddypress()->foo->has_directory );
     346        $this->assertNotEmpty( buddypress()->loaded_components['foo'] );
     347    }
    333348}
Note: See TracChangeset for help on using the changeset viewer.