Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/06/2015 11:01:27 PM (10 years ago)
Author:
r-a-y
Message:

Core: Introduce ability for components to register new features.

This commit allows plugin developers to register a feature in the
'BP_Component' class. To BuddyPress, a feature is merely an internal
marker. It is up to the developer to implement the feature.

Developers can check if a feature is registered with this snippet:

bp_is_active( $component, $feature_name )

See #6331 where this idea came about.

Props boonebgorges, imath, r-a-y.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/functions.php

    r9831 r9844  
    621621        $this->assertSame( $expected_upload_dir, $tested_upload_dir );
    622622    }
     623
     624    /**
     625     * @group bp_is_active
     626     */
     627    public function test_bp_is_active_component() {
     628        $bp = buddypress();
     629        $reset_active_components = $bp->active_components;
     630
     631        $this->assertTrue( bp_is_active( 'members' ) );
     632
     633        $this->assertFalse( bp_is_active( 'foo' ) );
     634
     635        // Create and activate the foo component
     636        $bp->foo = new BP_Component;
     637        $bp->foo->id   = 'foo';
     638        $bp->foo->slug = 'foo';
     639        $bp->foo->name = 'Foo';
     640        $bp->active_components[ $bp->foo->id ] = 1;
     641
     642        $this->assertTrue( bp_is_active( 'foo' ) );
     643
     644        add_filter( 'bp_is_active', '__return_false' );
     645
     646        $this->assertFalse( bp_is_active( 'foo' ) );
     647
     648        remove_filter( 'bp_is_active', '__return_false' );
     649
     650        // Reset buddypress() vars
     651        $bp->active_components = $reset_active_components;
     652    }
     653
     654    /**
     655     * @group bp_is_active
     656     */
     657    public function test_bp_is_active_feature() {
     658        $bp = buddypress();
     659        $reset_active_components = $bp->active_components;
     660
     661        // Create and activate the foo component
     662        $bp->foo = new BP_Component;
     663        $bp->foo->id   = 'foo';
     664        $bp->foo->slug = 'foo';
     665        $bp->foo->name = 'Foo';
     666        $bp->active_components[ $bp->foo->id ] = 1;
     667
     668        // foo did not register 'bar' as a feature
     669        $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
     670
     671        // fake registering the 'bar' feature
     672        $bp->foo->features = array( 'bar' );
     673        $this->assertTrue( bp_is_active( 'foo', 'bar' ) );
     674
     675        // test the feature filter
     676        add_filter( 'bp_is_foo_bar_active', '__return_false' );
     677        $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
     678        remove_filter( 'bp_is_foo_bar_active', '__return_false' );
     679
     680        // test the main component filter
     681        add_filter( 'bp_is_active', '__return_false' );
     682        $this->assertFalse( bp_is_active( 'foo', 'bar' ) );
     683        remove_filter( 'bp_is_active', '__return_false' );
     684
     685        // Reset buddypress() vars
     686        $bp->active_components = $reset_active_components;
     687    }
    623688}
Note: See TracChangeset for help on using the changeset viewer.