Making WordPress.org


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].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.