Skip to:
Content

BuddyPress.org

Changeset 13524


Ignore:
Timestamp:
07/24/2023 10:27:28 AM (3 years ago)
Author:
imath
Message:

Improve the BP Rewrites API support of the Group Extension

The BP_Group_Extension::init() $args parameter (array) now accepts a new argument: $show_tab_callback. You can use this argument to inform about the callback function to use to check whether the Extension group's tab should be displayed or not. This callback function is called inside the BP_Group_Extension::setup_access_settings() to make sure to set the $show_tab argument once the current group has been defined by BuddyPress.

Third party plugin authors are strongly encouraged to use this new argument if they used to define the $show_tab argument according to the result of a function. Doing so in BuddyPress 12.0.0 won't make your extension behave as expected.

Fixes #8943
Closes https://github.com/buddypress/buddypress/pull/136

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-group-extension.php

    r13452 r13524  
    197197
    198198        /**
    199          * List of Group access levels.
    200          *
    201          * @since 12.0.0
    202          * @var string[]
    203          */
    204         public $access_levels = array( 'noone', 'admin', 'mod', 'member', 'loggedin', 'anyone' );
    205 
    206         /**
    207199         * Whether the current user can visit the tab.
    208200         *
     
    514506         *                                           `array( 'mod', 'admin' )`. Defaults to 'anyone' for public groups
    515507         *                                           and 'member' for private groups.
     508         *    @type string|array  $show_tab_callback The function to execute to set the $show_tab argument.
    516509         * }
    517510         */
     
    545538                                'access'            => null,
    546539                                'show_tab'          => null,
     540                                'show_tab_callback' => '',
    547541                        )
    548542                );
    549543
    550                 $show_tab = $this->params['show_tab'];
    551                 if ( $show_tab && ! in_array( $show_tab, $this->access_levels, true ) && is_callable( $show_tab ) ) {
    552                         $this->show_tab_callback = $show_tab;
    553 
    554                         // Group Admin can always see.
    555                         $this->params['show_tab'] = 'admin';
     544                if ( $this->params['show_tab_callback'] && is_callable( $this->params['show_tab_callback'] ) ) {
     545                        $this->show_tab_callback = $this->params['show_tab_callback'];
    556546                }
    557547
     
    867857                $this->user_can_see_nav_item = false;
    868858
     859                // Use the provided callback to show or hide the Group extension tab.
     860                if ( $this->show_tab_callback ) {
     861                        $this->params['show_tab'] = call_user_func_array( $this->show_tab_callback, array( $this->group_id ) );
     862                }
     863
    869864                /*
    870865                 * Backward compatibility for components that do not provide
    871                  * explicit 'show_tab' parameter.
     866                 * explicit 'show_tab_callback' or 'show_tab' parameters.
    872867                 */
    873868                if ( empty( $this->params['show_tab'] ) ) {
     
    11101105                if ( ( 'noone' !== $this->params['show_tab'] ) && bp_current_user_can( 'bp_moderate' ) ) {
    11111106                        return true;
    1112                 }
    1113 
    1114                 if ( $this->show_tab_callback ) {
    1115                         return call_user_func( $this->show_tab_callback );
    11161107                }
    11171108
Note: See TracChangeset for help on using the changeset viewer.