Make WordPress Core

Ticket #50767: 50767-remove-assumption-in-code.patch

File 50767-remove-assumption-in-code.patch, 1.6 KB (added by jrf, 4 years ago)

QA: remove assumption in code Use a more stable condition. If $wpdb->get_row() is successful and the $output parameter has not been set, the output will be an instance of stdClass, so test to confirm that instead of testing against "not null".

  • src/wp-includes/ms-functions.php

    From 2adb62314f4f5d72ba210201538e08d51bcff991 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sun, 18 Oct 2020 08:18:56 +0200
    Subject: [PATCH] QA: remove assumption in code
    
    Use a more stable condition.
    If `$wpdb->get_row()` is successful and the `$output` parameter has not been set, the output will be an instance of `stdClass`, so test to confirm that instead of testing against "not null".
    ---
     src/wp-includes/ms-functions.php | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php
    index 65ee3d253d..0ad1f219a8 100644
    a b function wpmu_validate_user_signup( $user_name, $user_email ) { 
    543543
    544544        // Has someone already signed up for this username?
    545545        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) );
    546         if ( null != $signup ) {
     546        if ( $signup instanceof stdClass ) {
    547547                $registered_at = mysql2date( 'U', $signup->registered );
    548548                $now           = time();
    549549                $diff          = $now - $registered_at;
    function wpmu_validate_user_signup( $user_name, $user_email ) { 
    556556        }
    557557
    558558        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) );
    559         if ( null != $signup ) {
     559        if ( $signup instanceof stdClass ) {
    560560                $diff = time() - mysql2date( 'U', $signup->registered );
    561561                // If registered more than two days ago, cancel registration and let this signup go through.
    562562                if ( $diff > 2 * DAY_IN_SECONDS ) {