Making WordPress.org

Changeset 10901


Ignore:
Timestamp:
04/14/2021 04:49:37 AM (4 years ago)
Author:
dd32
Message:

Login: Store Akismet result for each signup, and expose it within the Admin UI.

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

Legend:

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

    r10010 r10901  
    1111            'user_ip'         => 'IP',
    1212            'scores'          => 'reCaptcha',
     13            'akismet'         => 'Akismet',
    1314            'user_registered' => 'Registered Date',
    1415            'created_date'    => 'Created Date',
     
    2324            'user_email'      => array( 'user_email', true ),
    2425            'scores'          => array( 'scores', true ),
     26            'akismet'         => array( 'akismet', true ),
    2527            'user_registered' => array( 'user_registered', true ),
    2628            'created_date'    => array( 'created_date', true ),
     
    168170    }
    169171
     172    function column_akismet( $item ) {
     173        $meta = json_decode( $item->meta, true );
     174
     175        echo $meta['akismet_result'] ?? '';
     176    }
     177
    170178}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-registration.php

    r10900 r10901  
    6363    $akismet = Akismet::rest_auto_check_comment( $payload );
    6464    if ( is_wp_error( $akismet ) ) {
    65         return 'OK'; // Assume it's okay in the event of failure / unknown.
    66         // return $akismet->get_error_code();
    67     }
    68 
    69     if ( ! empty( $akismet['akismet_pro_tip'] ) ) {
    70         return $akismet['akismet_pro_tip'];
     65        return $akismet->get_error_code();
     66    }
     67
     68    if ( ! empty( $akismet['akismet_pro_tip'] ) && 'discard' === $akismet['akismet_pro_tip'] ) {
     69        return 'spam';
    7170    } elseif ( 'true' === $akismet['akismet_result'] ) {
    7271        return 'spam';
     
    7473        return 'OK';
    7574    } else {
    76         return 'OK'; // Assume it's okay in the event of failure / unknown.
     75        return 'unknown';
    7776    }
    7877}
     
    8180 * Handles creating a "Pending" registration that will later be converted to an actual user  account.
    8281 */
    83 function wporg_login_create_pending_user( $user_login, $user_email, $user_mailinglist = false, $tos_revision = 0 ) {
     82function wporg_login_create_pending_user( $user_login, $user_email, $meta = array() ) {
    8483    global $wpdb, $wp_hasher;
    8584
     
    9897    $profile_key        = wp_generate_password( 24, false, false );
    9998    $hashed_profile_key = time() . ':' . wp_hash_password( $profile_key );
    100 
    101     $tos_meta_key = WPOrg_SSO::TOS_USER_META_KEY;
    10299
    103100    $pending_user = array(
     
    107104        'user_activation_key' => '',
    108105        'user_profile_key' => $hashed_profile_key,
    109         'meta' => array(
    110             'user_mailinglist' => $user_mailinglist,
     106        'meta' => $meta + array(
    111107            'registration_ip'  => $_SERVER['REMOTE_ADDR'], // Spam & fraud control. Will be discarded after the account is created.
    112             $tos_meta_key      => $tos_revision,
    113108        ),
    114109        'scores' => array()
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/pending-create.php

    r10900 r10901  
    8383    );
    8484
    85     if ( 'OK' !== $akismet ) {
     85    // Store for reference.
     86    $pending_user['meta']['akismet_result'] = $akismet;
     87    wporg_update_pending_user( $pending_user );
     88
     89    if ( 'spam' == $akismet ) {
    8690        // No no. "Please try again."
    8791        $error_akismet = true;
    8892        unset( $_POST['user_pass'] );
    89 
    90         // Store for reference.
    91         $pending_user['meta']['akismet_result'] = $akismet;
    92         wporg_update_pending_user( $pending_user );
    9393    }
    9494
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/register.php

    r10900 r10901  
    3636        if ( ! wporg_login_check_recapcha_status( 'register' ) ) {
    3737            $error_recapcha_status = true;
    38         } elseif ( 'OK' !== wporg_login_check_akismet( $user_login, $user_email ) ) {
    39             $error_akismet = true;
    4038        } else {
    41             wporg_login_create_pending_user( $user_login, $user_email, $user_mailinglist, $terms_of_service );
    42             die();
     39            $akismet = wporg_login_check_akismet( $user_login, $user_email );
     40
     41            $tos_meta_key = WPOrg_SSO::TOS_USER_META_KEY;
     42            $meta = [
     43                'user_mailinglist' => $user_mailinglist,
     44                'akismet_result'   => $akismet,
     45                $tos_meta_key      => $terms_of_service,
     46            ];
     47
     48            if ( 'spam' === $akismet ) {
     49                $error_akismet = true;
     50            } else {
     51                wporg_login_create_pending_user( $user_login, $user_email, $meta );
     52                die();
     53            }
    4354        }
    4455    }
Note: See TracChangeset for help on using the changeset viewer.