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/src/bp-core/bp-core-component.php

    r9819 r9844  
    132132     *
    133133     * @since BuddyPress (1.5.0)
    134      *
    135      * @uses BP_Component::setup_actions() Set up the hooks and actions.
    136      *
    137      * @param string $id Unique ID (for internal identification). Letters,
    138      *        numbers, and underscores only.
    139      * @param string $name Unique name. This should be a translatable name,
    140      *        eg __( 'Groups', 'buddypress' ).
    141      * @param string $path The file path for the component's files. Used by
    142      *        {@link BP_Component::includes()}.
    143      * @param array $params Additional parameters used by the component.
    144      *        The config array supports the following values:
    145      *        - 'adminbar_myaccount_order' Sets the position for our
    146      *          component menu under the WP Toolbar's "My Account" menu.
     134     * @since BuddyPress (1.9.0) Added $params as a parameter.
     135     * @since BuddyPress (2.3.0) Added $params['features'] as a configurable value.
     136     *
     137     * @param string $id   Unique ID. Letters, numbers, and underscores only.
     138     * @param string $name Unique name. This should be a translatable name, eg.
     139     *                     __( 'Groups', 'buddypress' ).
     140     * @param string $path The file path for the component's files. Used by {@link BP_Component::includes()}.
     141     * @param array  $params {
     142     *     Additional parameters used by the component.
     143     *     @type int   $adminbar_myaccount_order Set the position for our menu under the WP Toolbar's "My Account menu"
     144     *     @type array $features                 An array of feature names. This is used to load additional files from your
     145     *                                           component directory and for feature active checks. eg. array( 'awesome' )
     146     *                                           would look for a file called "bp-{$this->id}-awesome.php" and you could use
     147     *                                           bp_is_active( $this->id, 'awesome' ) to determine if the feature is active.
     148     * }
    147149     */
    148150    public function start( $id = '', $name = '', $path = '', $params = array() ) {
     
    162164            if ( ! empty( $params['adminbar_myaccount_order'] ) ) {
    163165                $this->adminbar_myaccount_order = (int) $params['adminbar_myaccount_order'];
     166            }
     167
     168            // Register features
     169            if ( ! empty( $params['features'] ) ) {
     170                $this->features = array_map( 'sanitize_title', (array) $params['features'] );
    164171            }
    165172
Note: See TracChangeset for help on using the changeset viewer.