Skip to:
Content

bbPress.org

Changeset 6052


Ignore:
Timestamp:
06/02/2016 07:38:35 AM (3 years ago)
Author:
netweb
Message:

Administration: Only display bbPress users role in bbPress' "Forum Role" list

Since WordPress 4.4 users with multiple roles are displayed in WordPress' "Site Role" list, this changeset ensures bbPress' roles are only displayed under the "Forum Role" list and not duplicated in the "Site Role" list of the users list table.

Props johnbillion, tharsheblows for initial patches
Fixes #2874

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/users.php

    r5951 r6052  
    5757        add_filter( 'manage_users_custom_column', array( $this, 'user_role_row'           ), 10, 3 );
    5858
     59        // Only list bbPress roles under Forum Role, remove from WordPress' > 4.4 Site Role list.
     60        if ( bbp_get_major_wp_version() >= 4.4 ) {
     61            add_filter( 'get_role_list',          array( $this, 'user_role_list_filter'   ), 10, 2 );
     62        }
     63
    5964        // Process bulk role change
    6065        add_action( 'load-users.php',             array( $this, 'user_role_bulk_change'   )        );
     
    129134    public static function user_role_bulk_dropdown() {
    130135
    131         // Bail if current user cannot promote users 
     136        // Bail if current user cannot promote users
    132137        if ( ! current_user_can( 'promote_users' ) ) {
    133138            return;
     
    184189        check_admin_referer( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
    185190
    186         // Bail if current user cannot promote users 
     191        // Bail if current user cannot promote users
    187192        if ( ! current_user_can( 'promote_users' ) ) {
    188193            return;
     
    202207
    203208            // Set up user and role data
    204             $user_role = bbp_get_user_role( $user_id );         
     209            $user_role = bbp_get_user_role( $user_id );
    205210            $new_role  = sanitize_text_field( $_REQUEST['bbp-new-role'] );
    206211
     
    263268        return $retval;
    264269    }
     270
     271    /**
     272     * Filter the list of roles included in the WordPress site role list
     273     *
     274     * This ensures bbPress' roles are only displayed under the Forum Role list
     275     * in the WordPRess USers list table
     276     *
     277     * @since 2.6.0 bbPress (r6051)
     278     *
     279     * @return array $roles
     280     */
     281    public static function user_role_list_filter( $roles, $user ) {
     282
     283        // Get the users role
     284        $user_role = bbp_get_user_role( $user->ID );
     285
     286        if ( ! empty( $user_role ) ) {
     287            unset( $roles[ $user_role ] );
     288        }
     289        return $roles;
     290    }
    265291}
    266292new BBP_Users_Admin();
Note: See TracChangeset for help on using the changeset viewer.