Making WordPress.org

Changeset 11623


Ignore:
Timestamp:
03/02/2022 07:51:58 AM (3 years ago)
Author:
dd32
Message:

Support: User Blocking: When blocking a user, add where they've been blocked from, and context if possible.

Fixes #5764.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r11350 r11623  
    13361336        $user_has_blocked_role = ! empty( $user->roles ) && in_array( $blocked_role, $user->roles, true );
    13371337
     1338        // Define what has blocked the user.
     1339        if ( ! ms_is_switched() ) {
     1340            $where_from = preg_replace( '!^https?://!i', '', home_url( is_admin() ? '/wp-admin' : '' ) );
     1341        } else {
     1342            // When we're switched, we can't determine the source of the switch, so we use a bit of URL parsing magic.
     1343            $where_from = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     1344            if ( str_contains( $where_from, '?' ) ) {
     1345                list( $where_from, ) = explode( '?', $where_from );
     1346            }
     1347            // Trim actual filename off, just the major path component.
     1348            $where_from = preg_replace( '!/[^/?]+\.[a-z]{3}$!i', '', $where_from  );
     1349        }
     1350
    13381351        if (
    13391352            ( $blocked_role === $new_role || $user_has_blocked_role ) &&
     
    13601373            // Add a user note about this action.
    13611374            $note_text = sprintf(
    1362                 'Forum role changed to %s.',
    1363                 get_role( $new_role )->name
     1375                $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.',
     1376                get_role( $new_role )->name,
     1377                $where_from
    13641378            );
     1379
     1380            // Used in wporg-login to add context.
     1381            $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user );
    13651382        } else if (
    13661383            $password_broken &&
     
    13831400            // Add a user note about this action.
    13841401            $note_text = sprintf(
    1385                 'Forum role changed to %s.',
    1386                 get_role( $new_role )->name
     1402                $where_from ? 'Forum role changed to %s via %s.' : 'Forum role changed to %s.',
     1403                get_role( $new_role )->name,
     1404                $where_from
    13871405            );
     1406
     1407            // Unused, here for consistency with above.
     1408            $note_text = apply_filters( 'wporg_bbp_forum_role_changed_note_text', $note_text, $user );
    13881409        }
    13891410
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php

    r11622 r11623  
    312312        } else {
    313313            $url = add_query_arg(
    314                 'user_id',
    315                 urlencode( $item->user->ID ),
     314                'user',
     315                urlencode( $item->user->user_login ),
    316316                admin_url( 'admin-post.php?action=login_block_account' )
    317317            );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/ui.php

    r11622 r11623  
    140140        if ( $block_words ) {
    141141            $block_words = explode( "\n", $block_words );
    142             $block_words = array_values( array_unique( array_filter( array_map( 'trim', $block_words ) ) ) );
     142            $block_words = array_values( array_unique( array_filter( $block_words ) ) );
    143143
    144144            // Sanity; Don't let it change more than 20%.
     
    190190        '<tr>
    191191            <th>reCaptcha v3 low-score threshold for Registration</th>
    192             <td><input name="recaptcha_v3_threshold" type="number" min="0.0" max="1.0" step="0.1" name="" value="%s"></td>
     192            <td>
     193                <input name="recaptcha_v3_threshold" type="number" min="0.0" max="1.0" step="0.1" name="" value="%s">
     194                <p><em>Any reCaptcha v3 score lower than this threshold is considered to have failed the reCaptcha and will be put into manual review.</em></p>
     195            </td>
    193196        </tr>',
    194197        esc_attr( get_option( 'recaptcha_v3_threshold', 0.2 ) )
     
    200203            <td>
    201204                <textarea name="registration_block_words" rows="10" cols="80">%s</textarea>
    202                 <p><em>Any registrations with any of these phrases within their username, email address, or profile fields will be put into manual review. One phrase per line.</em></p>
     205                <p>
     206                    <em>Any registrations with any of these phrases within their username, email address, or profile fields will be put into manual review.</em><br>
     207                    <em>Multiple words allowed to form a phrase. Leading/trailing whitespace is not removed. One phrase per line.</em>
     208                </p>
    203209            </td>
    204210        </tr>',
     
    356362    }
    357363
    358     if ( empty( $_REQUEST['user_id'] ) ) {
     364    if ( empty( $_REQUEST['user'] ) ) {
    359365        die();
    360366    }
    361367
    362     $user_id = (int) $_REQUEST['user_id'];
    363 
    364     check_admin_referer( 'block_account_' . $user_id );
    365 
    366     if ( $user_id && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     368    $pending_user = wporg_get_pending_user( $_REQUEST['user'] );
     369    if ( ! $pending_user || ! $pending_user['created'] ) {
     370        die();
     371    }
     372
     373    $user = get_user_by( 'slug', $pending_user['user_login'] );
     374    if ( ! $user ) {
     375        die();
     376    }
     377
     378    $table = new User_Registrations_List_Table();
     379
     380    ob_start();
     381    $pending_as_object       = (object) $pending_user;
     382    $pending_as_object->meta = (object) $pending_as_object->meta;
     383    $pending_as_object->user = $user;
     384
     385    unset( $pending_as_object->meta->registration_ip, $pending_as_object->meta->confirmed_ip );
     386
     387    $table->column_meta( $pending_as_object );
     388    $meta_column = ob_get_clean();
     389    $meta_column = wp_strip_all_tags( str_replace( '<br>', "\n", $meta_column ), false );
     390
     391    check_admin_referer( 'block_account_' . $user->ID );
     392
     393    if ( $user && defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
    367394
    368395        // Switch first so that bbPress loads with the correct context.
     
    379406        switch_to_blog( WPORG_SUPPORT_FORUMS_BLOGID );
    380407
     408        add_filter( 'wporg_bbp_forum_role_changed_note_text', function( $text ) use ( $meta_column ) {
     409            return trim( "{$meta_column}\n\n{$text}" );
     410        } );
     411
    381412        // Set the user to blocked. Support forum hooks will take care of the rest.
    382         bbp_set_user_role( $user_id, bbp_get_blocked_role() );
     413        bbp_set_user_role( $user->ID, bbp_get_blocked_role() );
    383414
    384415        restore_current_blog();
Note: See TracChangeset for help on using the changeset viewer.