Making WordPress.org

Changeset 10940


Ignore:
Timestamp:
04/30/2021 08:11:45 AM (5 years ago)
Author:
dd32
Message:

Login: When blocking users from the Admin UI, reference them by ID rather than by email to simplify some logic.

This also allows switching prior to including bbPress, avoiding issues related to code that sets all users as bbp_participant & [10939].

Follow up to [10928].

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php

    r10928 r10940  
    244244
    245245        } else {
    246             $url = add_query_arg(
    247                 'email',
    248                 urlencode( $item->user_email ),
     246            // Account created, find the user.
     247            $user = get_user_by( 'login', $item->user_login );
     248
     249            $url = add_query_arg(
     250                'user_id',
     251                urlencode( $user->ID ),
    249252                admin_url( 'admin-post.php?action=login_block_account' )
    250253            );
    251             $url = wp_nonce_url( $url, 'block_account_' . $item->user_email );
    252 
    253             if (
    254                 ! ( $user = get_user_by( 'login', $item->user_login ) ) ||
    255                 'BLOCKED' !== substr( $user->user_pass, 0, 7 )
    256             ) {
     254            $url = wp_nonce_url( $url, 'block_account_' . $user->ID );
     255
     256            if ( $user && 'BLOCKED' !== substr( $user->user_pass, 0, 7 ) ) {
    257257                $row_actions['block-account'] = '<a href="' . esc_url( $url ) . '">Block Account</a>';
    258258            }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/ui.php

    r10933 r10940  
    204204    }
    205205
    206     $email = $_REQUEST['email'] ?? '';
    207 
    208     check_admin_referer( 'block_account_' . $email );
    209 
    210     $user = get_user_by( 'email', $email );
    211     if ( $user && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     206    if ( empty( $_REQUEST['user_id'] ) ) {
     207        die();
     208    }
     209
     210    $user_id = (int) $_REQUEST['user_id'];
     211
     212    check_admin_referer( 'block_account_' . $user_id );
     213
     214    if ( $user_id && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     215
     216        // Switch first so that bbPress loads with the correct context.
     217        // This also ensures that the bbp_participant code doesn't kick in.
     218        switch_to_blog( WPORG_SUPPORT_FORUMS_BLOGID );
     219
    212220        // Load the support forums..
    213221        include_once WP_PLUGIN_DIR . '/bbpress/bbpress.php';
    214222        include_once WP_PLUGIN_DIR . '/support-forums/support-forums.php';
    215223
    216         // Then switch to it (Must be done after bbPress is loaded to get roles)
    217         switch_to_blog( WPORG_SUPPORT_FORUMS_BLOGID );
    218 
    219224        // Set the user to blocked. Support forum hooks will take care of the rest.
    220         bbp_set_user_role( $user->ID, bbp_get_blocked_role() );
     225        bbp_set_user_role( $user_id, bbp_get_blocked_role() );
    221226
    222227        restore_current_blog();
Note: See TracChangeset for help on using the changeset viewer.