[wp-trac] [WordPress Trac] #56028: Pass the user object instead of recall get user function

WordPress Trac noreply at wordpress.org
Wed Jun 22 17:33:51 UTC 2022


#56028: Pass the user object instead of recall get user function
--------------------------------------+------------------------------
 Reporter:  pbearne                   |       Owner:  pbearne
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Users                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------
Description changed by pbearne:

Old description:

> IN wp_ajax_send_password_reset we have
>
> {{{#!php
> <?php
>         $user    = get_userdata( $user_id );
>         $results = retrieve_password( $user->user_email );
> }}}
>
> then in retrieve_password we have
>
> {{{#!php
> <?php
>         if ( empty( $user_login ) ) {
>                 $errors->add( 'empty_username', __(
> '<strong>Error:</strong> Please enter a username or email address.' ) );
>         } elseif ( strpos( $user_login, '@' ) ) {
>                 $user_data = get_user_by( 'email', trim( wp_unslash(
> $user_login ) ) );
>                 if ( empty( $user_data ) ) {
>                         $errors->add( 'invalid_email', __(
> '<strong>Error:</strong> There is no account with that username or email
> address.' ) );
>                 }
>         } else {
>                 $user_data = get_user_by( 'login', trim( wp_unslash(
> $user_login ) ) );
>         }
> }}}
>

> This patch allows us to pass a user object and bypass the sound call to
> find user

New description:

 IN wp_ajax_send_password_reset we have

 {{{#!php
 <?php
         $user    = get_userdata( $user_id );
         $results = retrieve_password( $user->user_email );
 }}}

 then in retrieve_password we have

 {{{#!php
 <?php
         if ( empty( $user_login ) ) {
                 $errors->add( 'empty_username', __(
 '<strong>Error:</strong> Please enter a username or email address.' ) );
         } elseif ( strpos( $user_login, '@' ) ) {
                 $user_data = get_user_by( 'email', trim( wp_unslash(
 $user_login ) ) );
                 if ( empty( $user_data ) ) {
                         $errors->add( 'invalid_email', __(
 '<strong>Error:</strong> There is no account with that username or email
 address.' ) );
                 }
         } else {
                 $user_data = get_user_by( 'login', trim( wp_unslash(
 $user_login ) ) );
         }
 }}}


 This patch allows us to pass a user object and bypass the second call to
 find the user

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56028#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list