Skip to:
Content

bbPress.org

Changeset 6061


Ignore:
Timestamp:
06/10/2016 04:09:10 AM (8 years ago)
Author:
netweb
Message:

General - Administration: Update "change forum role" dropdown

This changeset resolves an issue introduced in WordPress 4.4 ( changeset:34636 / #WP27743 ) which caused bbPress "change forum role" dropdown to only work using the "bottom" user list table dropdown, for WordPress versions < 4.6 the "change forum role" dropdown is now only shown at the "top" of the user list table.

This changeset also adds a new parameter $which to user_role_bulk_dropdown() which was added in WordPress 4.6 ( changeset:37422 / #WP35307 ) to pass the location of the extra table nav markup for the "top" or "bottom" "change role" dropdown, and in turn fixes bbPress' "change forum role" dropdown to once again work at the "top" and "bottom" of the user list table.

Props ocean90.
Fixes #2906.

File:
1 edited

Legend:

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

    r6057 r6061  
    5353
    5454        // WordPress user screen
    55         add_action( 'restrict_manage_users',      array( $this, 'user_role_bulk_dropdown' )        );
     55        // Remvove the bottom list table "change forum role" dropdown from WordPress < 4.6.
     56        // See https://bbpress.trac.wordpress.org/ticket/2906.
     57        if ( bbp_get_major_wp_version() < 4.6 ) {
     58            add_action( 'restrict_manage_users',  array( __CLASS__, 'user_role_bulk_dropdown' )    );
     59        } else {
     60            add_action( 'restrict_manage_users',  array( $this, 'user_role_bulk_dropdown' )        );
     61        }
    5662        add_filter( 'manage_users_columns',       array( $this, 'user_role_column'        )        );
    5763        add_filter( 'manage_users_custom_column', array( $this, 'user_role_row'           ), 10, 3 );
     
    131137     *
    132138     * @since 2.2.0 bbPress (r4360)
    133      */
    134     public static function user_role_bulk_dropdown() {
     139     * @since 2.6.0 bbPress (r6055) Introduced the `$which` parameter.
     140     *
     141     * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
     142     */
     143    public static function user_role_bulk_dropdown( $which ) {
     144
     145        // Remove the bottom list table "change forum role" dropdown from WordPress < 4.6.
     146        // See https://bbpress.trac.wordpress.org/ticket/2906.
     147        if ( bbp_get_major_wp_version() < 4.6 ) {
     148            remove_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
     149        }
    135150
    136151        // Bail if current user cannot promote users
     
    145160        if ( ! bbp_is_user_keymaster() ) {
    146161            unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
    147         } ?>
    148 
    149         <label class="screen-reader-text" for="bbp-new-role"><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></label>
    150         <select name="bbp-new-role" id="bbp-new-role" style="display:inline-block; float:none;">
     162        }
     163
     164        $select_id = 'bottom' === $which ? 'bbp-new-role2' : 'bbp-new-role';
     165        $button_id = 'bottom' === $which ? 'bbp-change-role2' : 'bbp-change-role';
     166        ?>
     167
     168        <label class="screen-reader-text" for="<?php echo $select_id; ?>"><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></label>
     169        <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>" style="display:inline-block; float:none;">
    151170            <option value=''><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></option>
    152171            <?php foreach ( $dynamic_roles as $role => $details ) : ?>
    153172                <option value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
    154173            <?php endforeach; ?>
    155         </select><?php submit_button( __( 'Change', 'bbpress' ), 'secondary', 'bbp-change-role', false );
     174        </select><?php submit_button( __( 'Change', 'bbpress' ), 'secondary', $button_id, false );
    156175
    157176        wp_nonce_field( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
     
    161180     * Process bulk dropdown form submission from the WordPress Users
    162181     * Table
     182     *
     183     * @since 2.2.0 bbPress (r4365)
    163184     *
    164185     * @uses current_user_can() to check for 'promote users' capability
     
    176197
    177198        // Bail if this isn't a bbPress action
    178         if ( empty( $_REQUEST['bbp-new-role'] ) || empty( $_REQUEST['bbp-change-role'] ) ) {
    179             return;
     199        if ( ( empty( $_REQUEST['bbp-new-role'] ) && empty( $_REQUEST['bbp-new-role2'] ) ) || ( empty( $_REQUEST['bbp-change-role'] ) && empty( $_REQUEST['bbp-change-role2'] ) ) ) {
     200            return;
     201        }
     202
     203        $new_role = false;
     204        if ( ! empty( $_REQUEST['bbp-change-role2'] ) && ! empty( $_REQUEST['bbp-new-role2'] ) ) {
     205            $new_role = $_REQUEST['bbp-new-role2'];
     206        } elseif ( ! empty( $_REQUEST['bbp-change-role'] ) && ! empty( $_REQUEST['bbp-new-role'] ) ) {
     207            $new_role = $_REQUEST['bbp-new-role'];
    180208        }
    181209
    182210        // Check that the new role exists
    183211        $dynamic_roles = bbp_get_dynamic_roles();
    184         if ( empty( $dynamic_roles[ $_REQUEST['bbp-new-role'] ] ) ) {
     212        if ( ! $new_role || empty( $dynamic_roles[ $new_role ] ) ) {
    185213            return;
    186214        }
     
    208236            // Set up user and role data
    209237            $user_role = bbp_get_user_role( $user_id );
    210             $new_role  = sanitize_text_field( $_REQUEST['bbp-new-role'] );
     238            $new_role  = sanitize_text_field( $new_role );
    211239
    212240            // Only keymasters can set other keymasters
Note: See TracChangeset for help on using the changeset viewer.