Making WordPress.org


Ignore:
Timestamp:
03/02/2022 06:07:14 AM (4 years ago)
Author:
dd32
Message:

Login: Add an admin UI to manage blocked words/phrases/email domains for registration spam.

This also allows whitelisting/blocking individual IP addresses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-registration.php

    r11505 r11620  
    4646
    4747/**
    48  * Handles creating a "Pending" registration that will later be converted to an actual user  account.
     48 * Handles creating a "Pending" registration that will later be converted to an actual user account.
    4949 */
    5050function wporg_login_create_pending_user( $user_login, $user_email, $meta = array() ) {
     
    9696    }
    9797
     98    $passes_block_words = wporg_login_check_against_block_words( $pending_user );
     99
    98100    $pending_user['cleared'] = (
    99101        'allow' === $pending_user['meta']['heuristics'] &&
    100         (float)$pending_user['scores']['pending'] >= (float) get_option( 'recaptcha_v3_threshold', 0.2 )
     102        (float)$pending_user['scores']['pending'] >= (float) get_option( 'recaptcha_v3_threshold', 0.2 ) &&
     103        $passes_block_words
    101104    );
    102105
     
    398401    }
    399402
     403    // If not manually approved, check against block_words.
     404    if ( $pending_user['cleared'] < 2 ) {
     405        $passes_block_words = wporg_login_check_against_block_words( $pending_user );
     406        if ( ! $passes_block_words ) {
     407            $pending_user['cleared'] = 0;
     408        }
     409    }
     410
    400411    if ( $pending_user ) {
    401412        wporg_update_pending_user( $pending_user );
     
    407418    return true;
    408419}
     420
     421/**
     422 * Check a pending user object against the 'block words' setting.
     423 *
     424 * @return bool
     425 */
     426function wporg_login_check_against_block_words( $user ) {
     427    $block_words = get_option( 'registration_block_words', [] );
     428
     429    foreach ( $block_words as $word ) {
     430        if (
     431            false !== stripos( $user['user_login'], $word ) ||
     432            false !== stripos( $user['user_email'], $word ) ||
     433            false !== stripos( $user['meta']['url'], $word ) ||
     434            false !== stripos( $user['meta']['from'], $word ) ||
     435            false !== stripos( $user['meta']['occ'], $word ) ||
     436            false !== stripos( $user['meta']['interests'], $word )
     437        ) {
     438            return false;
     439        }
     440    }
     441
     442    return true;
     443}
Note: See TracChangeset for help on using the changeset viewer.