Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/06/2015 11:01:27 PM (5 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-template.php

    r9819 r9844  
    18461846
    18471847/**
    1848  * Check whether a given component has been activated by the admin.
     1848 * Check whether a given component (or feature of a component) is active.
     1849 *
     1850 * @since BuddyPress (1.2.0) See r2539.
     1851 * @since BuddyPress (2.3.0) Added $feature as a parameter.
    18491852 *
    18501853 * @param string $component The component name.
    1851  * @return bool True if the component is active, otherwise false.
    1852  */
    1853 function bp_is_active( $component = '' ) {
     1854 * @param string $feature   The feature name.
     1855 * @return bool
     1856 */
     1857function bp_is_active( $component = '', $feature = '' ) {
    18541858    $retval = false;
    18551859
     
    18621866    if ( isset( buddypress()->active_components[ $component ] ) || isset( buddypress()->required_components[ $component ] ) ) {
    18631867        $retval = true;
     1868
     1869        // Is feature active?
     1870        if ( ! empty( $feature ) ) {
     1871            if ( empty( buddypress()->$component->features ) || false === in_array( $feature, buddypress()->$component->features, true ) ) {
     1872                $retval = false;
     1873            }
     1874
     1875            /**
     1876             * Filters whether or not a given feature for a component is active.
     1877             *
     1878             * @since BuddyPress (2.3.0)
     1879             *
     1880             * @param bool $retval
     1881             */
     1882            $retval = apply_filters( "bp_is_{$component}_{$feature}_active", $retval );
     1883        }
    18641884    }
    18651885
Note: See TracChangeset for help on using the changeset viewer.