WordPress.org

Make WordPress Core

Changes between Version 3 and Version 4 of Ticket #40042, comment 1


Ignore:
Timestamp:
03/07/2017 07:49:22 AM (5 years ago)
Author:
BackuPs
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #40042, comment 1

    v3 v4  
    2222
    2323
    24 Now i know i can code around this issue. But that is very cumbersome as i  have to get the users records and compare the author_name (which) is the login name to the user login name;
    25 
    26 The question is why in the first time the action is called the $query does not have the user id set?
     24Now i know i can code around this issue. But the question is why in the first time the action is called the $query does not have the user id set?
    2725
    2826
     
    3331                $author_id = get_query_var('author');
    3432                if (empty($author_id)) $author_id=get_query_var('author_name');
    35                 if (!is_numeric($author_id)) {
     33                if (!is_numeric($author_id) && !empty($author_id)) {
    3634                        $authorname=$author_id;
    3735                        $author_id='';
    38                         $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) );
    39                         foreach($users as $user){
    40                                 if ($authorname==$user->user_login) {
    41                                         $author_id=$user->ID;
    42                                         break;
    43                                 }
    44                         }
     36                        $user = get_user_by( 'login', $authorname);
     37                        if (isset($user->ID)) $author_id=$user->ID;
    4538                }
    4639                if (!empty($author_id)) {