Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/02/2021 04:26:52 PM (3 years ago)
Author:
imath
Message:

Improve the Group Extension API extensibility

  • Use a new global to store the registered Group extensions of the Groups component.
  • Edit the behavior of the bp_register_group_extension() function so that it only registers custom group extensions into the new global.
  • Introduce a new function bp_init_group_extensions() to init the registered Group extensions.

These improvements will make it possible for the BP Rewrites feature as a plugin to allow slug customization of the registered Group extensions.

Props boonebgorges

Fixes #8558

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r13085 r13101  
    35323532    }
    35333533}
     3534
     3535/**
     3536 * Register a new Group Extension.
     3537 *
     3538 * @since 1.1.0
     3539 * @since 10.0.0 The function was moved from the `/bp-groups/classes/class-bp-group-extension.php` file.
     3540 *               It only registers Group Extensions if their corresponding class name has not been already
     3541 *               registered.
     3542 *
     3543 * @param string $group_extension_class Name of the Extension class.
     3544 * @return bool                         Returns true on success, otherwise false.
     3545 */
     3546function bp_register_group_extension( $group_extension_class = '' ) {
     3547    if ( ! class_exists( $group_extension_class ) ) {
     3548        return false;
     3549    }
     3550
     3551    $bp = buddypress();
     3552
     3553    if ( isset( $bp->groups->group_extensions[ $group_extension_class ] ) ) {
     3554        return false;
     3555    }
     3556
     3557    // Add the new Group extension to the registered ones.
     3558    $bp->groups->group_extensions[ $group_extension_class ] = true;
     3559
     3560    return true;
     3561}
     3562
     3563/**
     3564 * Init Registered Group Extensions.
     3565 *
     3566 * @since 10.0.0
     3567 */
     3568function bp_init_group_extensions() {
     3569    $registered_group_extensions = buddypress()->groups->group_extensions;
     3570
     3571    if ( ! $registered_group_extensions ) {
     3572        return;
     3573    }
     3574
     3575    foreach ( array_keys( $registered_group_extensions ) as $group_extension_class ) {
     3576        $extension = new $group_extension_class;
     3577
     3578        add_action( 'bp_actions', array( &$extension, '_register' ), 8 );
     3579        add_action( 'admin_init', array( &$extension, '_register' ) );
     3580    }
     3581}
     3582add_action( 'bp_init', 'bp_init_group_extensions', 11 );
Note: See TracChangeset for help on using the changeset viewer.