WordPress.org

Make WordPress Core

Ticket #4170: 4170.2.diff

File 4170.2.diff, 3.4 KB (added by Denis-de-Bernardy, 5 years ago)
  • Users/denis/Sites/sem-pro/wp-includes/user.php

     
    597597        wp_cache_add($user->ID, $user, 'users'); 
    598598        wp_cache_add($user->user_login, $user->ID, 'userlogins'); 
    599599        wp_cache_add($user->user_email, $user->ID, 'useremail'); 
     600        wp_cache_add($user->user_nicename, $user->ID, 'usernicename'); 
    600601} 
    601602 
    602603?> 
  • Users/denis/Sites/sem-pro/wp-includes/query.php

     
    20022002                                } 
    20032003                        } 
    20042004                        $q['author_name'] = sanitize_title($q['author_name']); 
    2005                         $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); 
     2005                        $q['author'] = get_user_by_nicename($q['author_name']); 
     2006                        $q['author'] = $q['author']->ID; 
    20062007                        $whichauthor .= " AND ($wpdb->posts.post_author = ".absint($q['author']).')'; 
    20072008                } 
    20082009 
  • Users/denis/Sites/sem-pro/wp-includes/general-template.php

     
    422422                $title = $title->display_name; 
    423423        } 
    424424        if ( !empty($author_name) ) { 
    425                 // We do a direct query here because we don't cache by nicename. 
    426                 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name)); 
     425                $title = get_user_by_nicename($author_name); 
     426                $title = $title->display_name; 
    427427        } 
    428428 
    429429        // If there's a month 
  • Users/denis/Sites/sem-pro/wp-includes/pluggable.php

     
    203203} 
    204204endif; 
    205205 
     206if ( !function_exists('get_user_by_nicename') ) : 
     207/** 
     208 * Retrieve user info by user nicename. 
     209 * 
     210 * @since 2.8 
     211 * 
     212 * @param string $nicename User's nice nicename 
     213 * @return bool|object False on failure, User DB row object 
     214 */ 
     215function get_user_by_nicename($nicename) { 
     216        global $wpdb; 
     217 
     218        $user_id = wp_cache_get($nicename, 'usernicename'); 
     219 
     220        $user = false; 
     221        if ( false !== $user_id ) 
     222                $user = wp_cache_get($user_id, 'users'); 
     223 
     224        if ( false !== $user ) 
     225                return $user; 
     226 
     227        if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_nicename = %s", $nicename)) ) 
     228                return false; 
     229 
     230        _fill_user($user); 
     231 
     232        return $user; 
     233} 
     234endif; 
     235 
    206236if ( !function_exists( 'wp_mail' ) ) : 
    207237/** 
    208238 * Send mail, similar to PHP's mail 
  • Users/denis/Sites/sem-pro/wp-admin/includes/user.php

     
    441441        wp_cache_delete($id, 'users'); 
    442442        wp_cache_delete($user->user_login, 'userlogins'); 
    443443        wp_cache_delete($user->user_email, 'useremail'); 
     444        wp_cache_delete($user->user_nicename, 'usernicename'); 
    444445         
    445446        // allow for commit transaction 
    446447        do_action('deleted_user', $id);