Ticket #21120: 21120.4.diff

File 21120.4.diff, 38.4 KB (added by nacin, 10 months ago)

Always returns a WP_User object.

Line 
1Index: wp-includes/pluggable-deprecated.php
2===================================================================
3--- wp-includes/pluggable-deprecated.php        (revision 21256)
4+++ wp-includes/pluggable-deprecated.php        (working copy)
5@@ -168,3 +168,23 @@
6 else :
7        _deprecated_function( 'wp_login', '2.5', 'wp_signon()' );
8 endif;
9+
10+if ( !function_exists('get_userdata') ) :
11+/**
12+ * Retrieve user info by user ID.
13+ *
14+ * @since 0.71
15+ *
16+ * @param int $user_id User ID.
17+ * @return bool|object False on failure, WP_User object on success
18+ */
19+function get_userdata( $user_id ) {
20+       $user = wp_get_user( $user_id );
21+       if ( $user->exists() )
22+               return $user;
23+
24+       return false;
25+}
26+else:
27+       _deprecated_function( 'get_userdata', '3.5', 'wp_get_user()' );
28+endif;
29\ No newline at end of file
30Index: wp-includes/comment.php
31===================================================================
32--- wp-includes/comment.php     (revision 21256)
33+++ wp-includes/comment.php     (working copy)
34@@ -406,10 +406,11 @@
35  */
36 function get_lastcommentmodified($timezone = 'server') {
37        global $wpdb;
38-       static $cache_lastcommentmodified = array();
39+       static $cache = array();
40+       $blog_id = get_current_blog_id();
41 
42-       if ( isset($cache_lastcommentmodified[$timezone]) )
43-               return $cache_lastcommentmodified[$timezone];
44+       if ( isset( $cache[ $blog_id ][ $timezone ] ) )
45+               return $cache[ $blog_id ][ $timezone ];
46 
47        $add_seconds_server = date('Z');
48 
49@@ -425,7 +426,7 @@
50                        break;
51        }
52 
53-       $cache_lastcommentmodified[$timezone] = $lastcommentmodified;
54+       $cache[ $blog_id ][ $timezone ] = $lastcommentmodified;
55 
56        return $lastcommentmodified;
57 }
58@@ -650,13 +651,12 @@
59 
60        do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
61 
62-       if ( isset($user_id) && $user_id) {
63-               $userdata = get_userdata($user_id);
64-               $user = new WP_User($user_id);
65+       if ( ! empty( $user_id ) ) {
66+               $user = wp_get_user($user_id);
67                $post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));
68        }
69 
70-       if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
71+       if ( isset( $user ) && $user->exists() && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
72                // The author and the admins get respect.
73                $approved = 1;
74         } else {
75Index: wp-includes/comment-template.php
76===================================================================
77--- wp-includes/comment-template.php    (revision 21256)
78+++ wp-includes/comment-template.php    (working copy)
79@@ -22,10 +22,10 @@
80  */
81 function get_comment_author( $comment_ID = 0 ) {
82        $comment = get_comment( $comment_ID );
83-       if ( empty($comment->comment_author) ) {
84-               if (!empty($comment->user_id)){
85-                       $user=get_userdata($comment->user_id);
86-                       $author=$user->user_login;
87+       if ( empty( $comment->comment_author ) ) {
88+               if ( ! empty( $comment->user_id ) ) {
89+                       $user = wp_get_user( $comment->user_id );
90+                       $author = $user->user_login;
91                } else {
92                        $author = __('Anonymous');
93                }
94@@ -307,7 +307,7 @@
95        $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
96 
97        // If the comment author has an id (registered), then print the log in name
98-       if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
99+       if ( $comment->user_id && ( $user = wp_get_user( $comment->user_id ) ) && $user->exists() ) {
100                // For all registered users, 'byuser'
101                $classes[] = 'byuser';
102                $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
103Index: wp-includes/user.php
104===================================================================
105--- wp-includes/user.php        (revision 21256)
106+++ wp-includes/user.php        (working copy)
107@@ -110,8 +110,7 @@
108                return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ),
109                $username, wp_lostpassword_url() ) );
110 
111-       $user =  new WP_User($userdata->ID);
112-       return $user;
113+       return $userdata;
114 }
115 
116 /**
117@@ -123,7 +122,7 @@
118        if ( empty($username) && empty($password) ) {
119                $user_id = wp_validate_auth_cookie();
120                if ( $user_id )
121-                       return new WP_User($user_id);
122+                       return wp_get_user( $user_id );
123 
124                global $auth_secure_cookie;
125 
126@@ -254,10 +253,7 @@
127        if ( !empty( $deprecated ) )
128                _deprecated_argument( __FUNCTION__, '3.0' );
129 
130-       if ( empty( $user ) )
131-               $user = wp_get_current_user();
132-       else
133-               $user = new WP_User( $user );
134+       $user = wp_get_user( $user );
135 
136        if ( ! $user->exists() )
137                return false;
138@@ -922,15 +918,13 @@
139  * @global string $user_url The url in the user's profile
140  * @global string $user_identity The display name of the user
141  *
142- * @param int $for_user_id Optional. User ID to set up global data.
143+ * @param mixed $user Optional. WP_User object or user ID to set up global data.
144  */
145-function setup_userdata($for_user_id = '') {
146+function setup_userdata( $user = '' ) {
147        global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity;
148 
149-       if ( '' == $for_user_id )
150-               $user = wp_get_current_user();
151-       else
152-               $user = new WP_User($for_user_id);
153+       if ( ! is_a( $user, 'WP_User' ) )
154+               $user = wp_get_user( $user );
155 
156        $userdata   = null;
157        $user_ID    = (int) $user->ID;
158@@ -1031,7 +1025,7 @@
159                }
160 
161                if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) {
162-                       $user = get_userdata( $selected );
163+                       $user = wp_get_user( $selected );
164                        $_selected = selected( $user->ID, $selected, false );
165                        $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')';
166                        $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
167@@ -1142,7 +1136,7 @@
168  */
169 function clean_user_cache( $user ) {
170        if ( is_numeric( $user ) )
171-               $user = new WP_User( $user );
172+               $user = wp_get_user( $user );
173 
174        if ( ! $user->exists() )
175                return;
176@@ -1351,7 +1345,7 @@
177                $user_id = (int) $wpdb->insert_id;
178        }
179 
180-       $user = new WP_User( $user_id );
181+       $user = wp_get_user( $user_id );
182 
183        foreach ( _get_additional_user_keys( $user ) as $key ) {
184                if ( isset( $$key ) )
185@@ -1397,7 +1391,7 @@
186        $ID = (int) $userdata['ID'];
187 
188        // First, get all of the original fields
189-       $user_obj = get_userdata( $ID );
190+       $user_obj = wp_get_user( $ID );
191 
192        $user = get_object_vars( $user_obj->data );
193 
194Index: wp-includes/class-wp-xmlrpc-server.php
195===================================================================
196--- wp-includes/class-wp-xmlrpc-server.php      (revision 21256)
197+++ wp-includes/class-wp-xmlrpc-server.php      (working copy)
198@@ -785,7 +785,7 @@
199                }
200 
201                // Get the author info.
202-               $author = get_userdata( $page->post_author );
203+               $author = wp_get_user( $page->post_author );
204 
205                $page_template = get_page_template_slug( $page->ID );
206                if ( empty( $page_template ) )
207@@ -985,9 +985,9 @@
208                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
209                                return new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) );
210 
211-                       $author = get_userdata( $post_data['post_author'] );
212+                       $author = wp_get_user( $post_data['post_author'] );
213 
214-                       if ( ! $author )
215+                       if ( ! $author->exists() )
216                                return new IXR_Error( 404, __( 'Invalid author ID.' ) );
217                } else {
218                        $post_data['post_author'] = $user->ID;
219@@ -3737,8 +3737,8 @@
220                                        return(new IXR_Error(401, __('Invalid post type')));
221                                        break;
222                        }
223-                       $author = get_userdata( $content_struct['wp_author_id'] );
224-                       if ( ! $author )
225+                       $author = wp_get_user( $content_struct['wp_author_id'] );
226+                       if ( ! $author->exists() )
227                                return new IXR_Error( 404, __( 'Invalid author ID.' ) );
228                        $post_author = $content_struct['wp_author_id'];
229                }
230@@ -4272,7 +4272,7 @@
231                        $link = post_permalink($postdata['ID']);
232 
233                        // Get the author info.
234-                       $author = get_userdata($postdata['post_author']);
235+                       $author = wp_get_user($postdata['post_author']);
236 
237                        $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
238                        $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
239@@ -4403,7 +4403,7 @@
240                        $link = post_permalink($entry['ID']);
241 
242                        // Get the post author info.
243-                       $author = get_userdata($entry['post_author']);
244+                       $author = wp_get_user($entry['post_author']);
245 
246                        $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
247                        $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
248Index: wp-includes/query.php
249===================================================================
250--- wp-includes/query.php       (revision 21256)
251+++ wp-includes/query.php       (working copy)
252@@ -2990,7 +2990,7 @@
253                        $this->queried_object_id = (int) $this->post->ID;
254                } elseif ( $this->is_author ) {
255                        $this->queried_object_id = (int) $this->get('author');
256-                       $this->queried_object = get_userdata( $this->queried_object_id );
257+                       $this->queried_object = wp_get_user( $this->queried_object_id );
258                }
259 
260                return $this->queried_object;
261@@ -3593,7 +3593,7 @@
262 
263        $id = (int) $post->ID;
264 
265-       $authordata = get_userdata($post->post_author);
266+       $authordata = wp_get_user($post->post_author);
267 
268        $currentday = mysql2date('d.m.y', $post->post_date, false);
269        $currentmonth = mysql2date('m', $post->post_date, false);
270Index: wp-includes/link-template.php
271===================================================================
272--- wp-includes/link-template.php       (revision 21256)
273+++ wp-includes/link-template.php       (working copy)
274@@ -138,7 +138,7 @@
275 
276                $author = '';
277                if ( strpos($permalink, '%author%') !== false ) {
278-                       $authordata = get_userdata($post->post_author);
279+                       $authordata = wp_get_user($post->post_author);
280                        $author = $authordata->user_nicename;
281                }
282 
283Index: wp-includes/author-template.php
284===================================================================
285--- wp-includes/author-template.php     (revision 21256)
286+++ wp-includes/author-template.php     (working copy)
287@@ -64,14 +64,14 @@
288  * @since 2.8
289  * @uses $post The current post's DB object.
290  * @uses get_post_meta() Retrieves the ID of the author who last edited the current post.
291- * @uses get_userdata() Retrieves the author's DB object.
292+ * @uses wp_get_user() Retrieves the author's DB object.
293  * @uses apply_filters() Calls 'the_modified_author' hook on the author display name.
294  * @return string The author's display name.
295  */
296 function get_the_modified_author() {
297        global $post;
298        if ( $last_id = get_post_meta($post->ID, '_edit_last', true) ) {
299-               $last_user = get_userdata($last_id);
300+               $last_user = wp_get_user($last_id);
301                return apply_filters('the_modified_author', $last_user->display_name);
302        }
303 }
304@@ -101,7 +101,7 @@
305                global $authordata;
306                $user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
307        } else {
308-               $authordata = get_userdata( $user_id );
309+               $authordata = wp_get_user( $user_id );
310        }
311 
312        if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) )
313@@ -226,7 +226,7 @@
314                $link = $file . '?author=' . $auth_ID;
315        } else {
316                if ( '' == $author_nicename ) {
317-                       $user = get_userdata($author_id);
318+                       $user = wp_get_user($author_id);
319                        if ( !empty($user->user_nicename) )
320                                $author_nicename = $user->user_nicename;
321                }
322@@ -290,7 +290,7 @@
323                $author_count[$row->post_author] = $row->count;
324 
325        foreach ( $authors as $author_id ) {
326-               $author = get_userdata( $author_id );
327+               $author = wp_get_user( $author_id );
328 
329                if ( $exclude_admin && 'admin' == $author->display_name )
330                        continue;
331Index: wp-includes/canonical.php
332===================================================================
333--- wp-includes/canonical.php   (revision 21256)
334+++ wp-includes/canonical.php   (working copy)
335@@ -152,8 +152,8 @@
336                        if ( $redirect_url = get_year_link(get_query_var('year')) )
337                                $redirect['query'] = remove_query_arg('year', $redirect['query']);
338                } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
339-                       $author = get_userdata(get_query_var('author'));
340-                       if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) {
341+                       $author = wp_get_user(get_query_var('author'));
342+                       if ( $author->exists() && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) {
343                                if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
344                                        $redirect['query'] = remove_query_arg('author', $redirect['query']);
345                        }
346Index: wp-includes/capabilities.php
347===================================================================
348--- wp-includes/capabilities.php        (revision 21256)
349+++ wp-includes/capabilities.php        (working copy)
350@@ -922,6 +922,27 @@
351 }
352 
353 /**
354+ * Returns a WP_User object of the requested user ID.
355+ *
356+ * @since 3.5.0
357+ *
358+ * @param int $user_id Optional. Defaults to the current user ID.
359+ * @return WP_User
360+ */
361+function wp_get_user( $user_id = null ) {
362+       if ( is_a( $user_id, 'WP_User' ) )
363+               return $user_id;
364+
365+       if ( ! $user_id )
366+               $user_id = get_current_user_id();
367+
368+       if ( $user = get_user_by( 'id', $user_id ) )
369+               return $user;
370+
371+       return new WP_User;
372+}
373+
374+/**
375  * Map meta capabilities to primitive capabilities.
376  *
377  * This does not actually compare whether the user ID has the actual capability,
378@@ -960,7 +981,6 @@
379                break;
380        case 'delete_post':
381        case 'delete_page':
382-               $author_data = get_userdata( $user_id );
383                $post = get_post( $args[0] );
384 
385                if ( 'revision' == $post->post_type ) {
386@@ -978,14 +998,14 @@
387                }
388 
389                if ( '' != $post->post_author ) {
390-                       $post_author_data = get_userdata( $post->post_author );
391+                       $post_author_data = wp_get_user( $post->post_author );
392                } else {
393                        // No author set yet, so default to current user for cap checks.
394-                       $post_author_data = $author_data;
395+                       $post_author_data = wp_get_user( $user_id );
396                }
397 
398                // If the user is the author...
399-               if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
400+               if ( $post_author_data->exists() && $user_id == $post_author_data->ID ) {
401                        // If the post is published...
402                        if ( 'publish' == $post->post_status ) {
403                                $caps[] = $post_type->cap->delete_published_posts;
404@@ -1010,7 +1030,6 @@
405                // edit_others_posts
406        case 'edit_post':
407        case 'edit_page':
408-               $author_data = get_userdata( $user_id );
409                $post = get_post( $args[0] );
410 
411                if ( 'revision' == $post->post_type ) {
412@@ -1028,15 +1047,15 @@
413                }
414 
415                if ( '' != $post->post_author ) {
416-                       $post_author_data = get_userdata( $post->post_author );
417+                       $post_author_data = wp_get_user( $post->post_author );
418                } else {
419                        // No author set yet, so default to current user for cap checks.
420-                       $post_author_data = $author_data;
421+                       $post_author_data = wp_get_user( $user_id );
422                }
423 
424                //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
425                // If the user is the author...
426-               if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID ) {
427+               if ( $post_author_data->exists() && $user_id == $post_author_data->ID ) {
428                        // If the post is published...
429                        if ( 'publish' == $post->post_status ) {
430                                $caps[] = $post_type->cap->edit_published_posts;
431@@ -1059,7 +1078,6 @@
432                break;
433        case 'read_post':
434        case 'read_page':
435-               $author_data = get_userdata( $user_id );
436                $post = get_post( $args[0] );
437 
438                if ( 'revision' == $post->post_type ) {
439@@ -1083,13 +1101,13 @@
440                }
441 
442                if ( '' != $post->post_author ) {
443-                       $post_author_data = get_userdata( $post->post_author );
444+                       $post_author_data = wp_get_user( $post->post_author );
445                } else {
446                        // No author set yet, so default to current user for cap checks.
447-                       $post_author_data = $author_data;
448+                       $post_author_data = wp_get_user( $user_id );
449                }
450 
451-               if ( is_object( $post_author_data ) && $user_id == $post_author_data->ID )
452+               if ( $post_author_data->exists() && $user_id == $post_author_data->ID )
453                        $caps[] = $post_type->cap->read;
454                elseif ( $status_obj->private )
455                        $caps[] = $post_type->cap->read_private_posts;
456@@ -1240,7 +1258,7 @@
457                return false;
458 
459        // Create new object to avoid stomping the global current_user.
460-       $user = new WP_User( $current_user->ID) ;
461+       $user = new WP_User( $current_user->ID );
462 
463        // Set the blog id. @todo add blog id arg to WP_User constructor?
464        $user->for_blog( $blog_id );
465@@ -1264,9 +1282,9 @@
466        if ( !$post = get_post($post) )
467                return false;
468 
469-       $author = new WP_User( $post->post_author );
470+       $author = wp_get_user( $post->post_author );
471 
472-       if ( empty( $author->ID ) )
473+       if ( ! $author->exists() )
474                return false;
475 
476        $args = array_slice( func_get_args(), 2 );
477@@ -1286,9 +1304,9 @@
478  */
479 function user_can( $user, $capability ) {
480        if ( ! is_object( $user ) )
481-               $user = new WP_User( $user );
482+               $user = wp_get_user( $user );
483 
484-       if ( ! $user || ! $user->exists() )
485+       if ( ! $user->exists() )
486                return false;
487 
488        $args = array_slice( func_get_args(), 2 );
489@@ -1380,10 +1398,7 @@
490  * @return bool True if the user is a site admin.
491  */
492 function is_super_admin( $user_id = false ) {
493-       if ( $user_id )
494-               $user = new WP_User( $user_id );
495-       else
496-               $user = wp_get_current_user();
497+       $user = wp_get_user( $user_id );
498 
499        if ( ! $user->exists() )
500                return false;
501Index: wp-includes/deprecated.php
502===================================================================
503--- wp-includes/deprecated.php  (revision 21256)
504+++ wp-includes/deprecated.php  (working copy)
505@@ -207,7 +207,7 @@
506 function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') {
507        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
508 
509-       $author_data = get_userdata($user_id);
510+       $author_data = wp_get_user($user_id);
511        return ($author_data->user_level > 1);
512 }
513 
514@@ -227,7 +227,7 @@
515 function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') {
516        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
517 
518-       $author_data = get_userdata($user_id);
519+       $author_data = wp_get_user($user_id);
520        return ($author_data->user_level >= 1);
521 }
522 
523@@ -247,9 +247,9 @@
524 function user_can_edit_post($user_id, $post_id, $blog_id = 1) {
525        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
526 
527-       $author_data = get_userdata($user_id);
528+       $author_data = wp_get_user($user_id);
529        $post = get_post($post_id);
530-       $post_author_data = get_userdata($post->post_author);
531+       $post_author_data = wp_get_user($post->post_author);
532 
533        if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2))
534                         || ($author_data->user_level > $post_author_data->user_level)
535@@ -296,7 +296,7 @@
536 function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') {
537        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
538 
539-       $author_data = get_userdata($user_id);
540+       $author_data = wp_get_user($user_id);
541        return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id));
542 }
543 
544@@ -316,7 +316,7 @@
545 function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) {
546        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
547 
548-       $author_data = get_userdata($user_id);
549+       $author_data = wp_get_user($user_id);
550        return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id));
551 }
552 
553@@ -375,8 +375,8 @@
554 function user_can_edit_user($user_id, $other_user) {
555        _deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );
556 
557-       $user  = get_userdata($user_id);
558-       $other = get_userdata($other_user);
559+       $user  = wp_get_user($user_id);
560+       $other = wp_get_user($other_user);
561        if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID )
562                return true;
563        else
564Index: wp-includes/pluggable.php
565===================================================================
566--- wp-includes/pluggable.php   (revision 21256)
567+++ wp-includes/pluggable.php   (working copy)
568@@ -32,7 +32,7 @@
569 
570        $current_user = new WP_User( $id, $name );
571 
572-       setup_userdata( $current_user->ID );
573+       setup_userdata( $current_user );
574 
575        do_action('set_current_user');
576 
577@@ -108,20 +108,6 @@
578 }
579 endif;
580 
581-if ( !function_exists('get_userdata') ) :
582-/**
583- * Retrieve user info by user ID.
584- *
585- * @since 0.71
586- *
587- * @param int $user_id User ID
588- * @return bool|object False on failure, WP_User object on success
589- */
590-function get_userdata( $user_id ) {
591-       return get_user_by( 'id', $user_id );
592-}
593-endif;
594-
595 if ( !function_exists('get_user_by') ) :
596 /**
597  * Retrieve user info by a given field
598@@ -133,6 +119,9 @@
599  * @return bool|object False on failure, WP_User object on success
600  */
601 function get_user_by( $field, $value ) {
602+       if ( 'id' === $field && $value && get_current_user_id() === intval( $value ) )
603+               return wp_get_current_user();
604+
605        $userdata = WP_User::get_data_by( $field, $value );
606 
607        if ( !$userdata )
608@@ -147,7 +136,7 @@
609 
610 if ( !function_exists('cache_users') ) :
611 /**
612- * Retrieve info for user lists to prevent multiple queries by get_userdata()
613+ * Retrieve info for user lists to prevent multiple queries by wp_get_user()
614  *
615  * @since 3.0.0
616  *
617@@ -576,7 +565,7 @@
618  * @return string Authentication cookie contents
619  */
620 function wp_generate_auth_cookie($user_id, $expiration, $scheme = 'auth') {
621-       $user = get_userdata($user_id);
622+       $user = wp_get_user($user_id);
623 
624        $pass_frag = substr($user->user_pass, 8, 4);
625 
626@@ -993,7 +982,6 @@
627 function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
628        $comment = get_comment( $comment_id );
629        $post    = get_post( $comment->comment_post_ID );
630-       $author  = get_userdata( $post->post_author );
631 
632        // The comment was left by the author
633        if ( $comment->user_id == $post->post_author )
634@@ -1003,6 +991,8 @@
635        if ( $post->post_author == get_current_user_id() )
636                return false;
637 
638+       $author = wp_get_user( $post->post_author );
639+
640        // If there's no email to send the comment to
641        if ( '' == $author->user_email )
642                return false;
643@@ -1099,7 +1089,7 @@
644 
645        $comment = get_comment($comment_id);
646        $post = get_post($comment->comment_post_ID);
647-       $user = get_userdata( $post->post_author );
648+       $user = wp_get_user( $post->post_author );
649        // Send to the administration and to the post author if the author can modify the comment.
650        $email_to = array( get_option('admin_email') );
651        if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
652@@ -1195,7 +1185,7 @@
653  * @param string $plaintext_pass Optional. The user's plaintext password
654  */
655 function wp_new_user_notification($user_id, $plaintext_pass = '') {
656-       $user = new WP_User($user_id);
657+       $user = wp_get_user($user_id);
658 
659        $user_login = stripslashes($user->user_login);
660        $user_email = stripslashes($user->user_email);
661@@ -1595,8 +1585,8 @@
662        $email = '';
663        if ( is_numeric($id_or_email) ) {
664                $id = (int) $id_or_email;
665-               $user = get_userdata($id);
666-               if ( $user )
667+               $user = wp_get_user($id);
668+               if ( $user->exists() )
669                        $email = $user->user_email;
670        } elseif ( is_object($id_or_email) ) {
671                // No avatar for pingbacks or trackbacks
672@@ -1606,8 +1596,8 @@
673 
674                if ( !empty($id_or_email->user_id) ) {
675                        $id = (int) $id_or_email->user_id;
676-                       $user = get_userdata($id);
677-                       if ( $user)
678+                       $user = wp_get_user($id);
679+                       if ( $user->exists() )
680                                $email = $user->user_email;
681                } elseif ( !empty($id_or_email->comment_author_email) ) {
682                        $email = $id_or_email->comment_author_email;
683Index: wp-includes/ms-functions.php
684===================================================================
685--- wp-includes/ms-functions.php        (revision 21256)
686+++ wp-includes/ms-functions.php        (working copy)
687@@ -183,7 +183,7 @@
688 function add_user_to_blog( $blog_id, $user_id, $role ) {
689        switch_to_blog($blog_id);
690 
691-       $user = new WP_User($user_id);
692+       $user = wp_get_user($user_id);
693 
694        if ( ! $user->exists() ) {
695                restore_current_blog();
696@@ -246,7 +246,7 @@
697        }
698 
699        // wp_revoke_user($user_id);
700-       $user = new WP_User($user_id);
701+       $user = wp_get_user($user_id);
702        if ( ! $user->exists() ) {
703                restore_current_blog();
704                return new WP_Error('user_does_not_exist', __('That user does not exist.'));
705@@ -1056,7 +1056,7 @@
706        if ( is_email($email) == false )
707                return false;
708 
709-       $user = new WP_User($user_id);
710+       $user = wp_get_user($user_id);
711 
712        $options_site_url = esc_url(network_admin_url('settings.php'));
713        $msg = sprintf(__('New User: %1s
714@@ -1233,7 +1233,7 @@
715 --The Team @ SITE_NAME' ) );
716 
717        $url = get_blogaddress_by_id($blog_id);
718-       $user = new WP_User($user_id);
719+       $user = wp_get_user($user_id);
720 
721        $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
722        $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
723@@ -1282,7 +1282,7 @@
724 
725        $welcome_email = get_site_option( 'welcome_user_email' );
726 
727-       $user = new WP_User($user_id);
728+       $user = wp_get_user($user_id);
729 
730        $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);
731        $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
732@@ -1536,7 +1536,7 @@
733  */
734 function wpmu_log_new_registrations( $blog_id, $user_id ) {
735        global $wpdb;
736-       $user = new WP_User( (int) $user_id );
737+       $user = wp_get_user( (int) $user_id );
738        $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
739 }
740 
741@@ -1802,7 +1802,7 @@
742        } else {
743                $user_id = get_user_id_from_string( $username );
744        }
745-       $u = new WP_User( $user_id );
746+       $u = wp_get_user( $user_id );
747 
748        return ( isset( $u->spam ) && $u->spam == 1 );
749 }
750Index: wp-mail.php
751===================================================================
752--- wp-mail.php (revision 21256)
753+++ wp-mail.php (working copy)
754@@ -154,7 +154,7 @@
755 
756        // Set $post_status based on $author_found and on author's publish_posts capability
757        if ( $author_found ) {
758-               $user = new WP_User($post_author);
759+               $user = wp_get_user($post_author);
760                $post_status = ( $user->has_cap('publish_posts') ) ? 'publish' : 'pending';
761        } else {
762                // Author not found in DB, set status to pending. Author already set to admin.
763Index: wp-activate.php
764===================================================================
765--- wp-activate.php     (revision 21256)
766+++ wp-activate.php     (working copy)
767@@ -77,7 +77,7 @@
768                } else {
769                        extract($result);
770                        $url = get_blogaddress_by_id( (int) $blog_id);
771-                       $user = new WP_User( (int) $user_id);
772+                       $user = wp_get_user( (int) $user_id );
773                        ?>
774                        <h2><?php _e('Your account is now active!'); ?></h2>
775 
776Index: wp-admin/users.php
777===================================================================
778--- wp-admin/users.php  (revision 21256)
779+++ wp-admin/users.php  (working copy)
780@@ -111,7 +111,7 @@
781                if ( is_multisite() && !is_user_member_of_blog( $id ) )
782                        wp_die(__('Cheatin&#8217; uh?'));
783 
784-               $user = new WP_User($id);
785+               $user = wp_get_user($id);
786                $user->set_role($_REQUEST['new_role']);
787        }
788 
789@@ -201,7 +201,7 @@
790        $go_delete = 0;
791        foreach ( $userids as $id ) {
792                $id = (int) $id;
793-               $user = new WP_User($id);
794+               $user = wp_get_user($id);
795                if ( $id == $current_user->ID ) {
796                        echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
797                } else {
798@@ -302,7 +302,7 @@
799        $go_remove = false;
800        foreach ( $userids as $id ) {
801                $id = (int) $id;
802-               $user = new WP_User($id);
803+               $user = wp_get_user($id);
804                if ( $id == $current_user->ID && !is_super_admin() ) {
805                        echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
806                } elseif ( !current_user_can('remove_user', $id) ) {
807Index: wp-admin/includes/ajax-actions.php
808===================================================================
809--- wp-admin/includes/ajax-actions.php  (revision 21256)
810+++ wp-admin/includes/ajax-actions.php  (working copy)
811@@ -1018,7 +1018,7 @@
812                ) );
813                $x->send();
814        }
815-       $user_object = new WP_User( $user_id );
816+       $user_object = wp_get_user( $user_id );
817 
818        $wp_list_table = _get_list_table('WP_Users_List_Table');
819 
820@@ -1069,8 +1069,8 @@
821        if ( $last = wp_check_post_lock( $post->ID ) ) {
822                $do_autosave = $do_lock = false;
823 
824-               $last_user = get_userdata( $last );
825-               $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
826+               $last_user = wp_get_user( $last );
827+               $last_user_name = $last_user->exists() ? $last_user->display_name : __( 'Someone' );
828                $data = __( 'Autosave disabled.' );
829 
830                $supplemental['disable_autosave'] = 'disable';
831@@ -1331,8 +1331,8 @@
832        set_current_screen( $_POST['screen'] );
833 
834        if ( $last = wp_check_post_lock( $post_ID ) ) {
835-               $last_user = get_userdata( $last );
836-               $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
837+               $last_user = wp_get_user( $last );
838+               $last_user_name = $last_user->exists() ? $last_user->display_name : __( 'Someone' );
839                printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ),        esc_html( $last_user_name ) );
840                wp_die();
841        }
842@@ -1752,7 +1752,7 @@
843        }
844 
845        if ( $last_id = get_post_meta($post_id, '_edit_last', true) ) {
846-               $last_user = get_userdata($last_id);
847+               $last_user = wp_get_user($last_id);
848                $last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time );
849        } else {
850                $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time );
851Index: wp-admin/includes/post.php
852===================================================================
853--- wp-admin/includes/post.php  (revision 21256)
854+++ wp-admin/includes/post.php  (working copy)
855@@ -1228,8 +1228,8 @@
856 
857        $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) );
858        $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
859-       $last_user = get_userdata( $user );
860-       $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
861+       $last_user = wp_get_user( $user );
862+       $last_user_name = $last_user->exists() ? $last_user->display_name : __('Somebody');
863 
864        switch ($post->post_type) {
865                case 'post':
866Index: wp-admin/includes/class-wp-users-list-table.php
867===================================================================
868--- wp-admin/includes/class-wp-users-list-table.php     (revision 21256)
869+++ wp-admin/includes/class-wp-users-list-table.php     (working copy)
870@@ -218,7 +218,7 @@
871                global $wp_roles;
872 
873                if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
874-                       $user_object = new WP_User( (int) $user_object );
875+                       $user_object = wp_get_user( (int) $user_object );
876                $user_object->filter = 'display';
877                $email = $user_object->user_email;
878 
879Index: wp-admin/includes/upgrade.php
880===================================================================
881--- wp-admin/includes/upgrade.php       (revision 21256)
882+++ wp-admin/includes/upgrade.php       (working copy)
883@@ -75,7 +75,7 @@
884                $message = __('User already exists. Password inherited.');
885        }
886 
887-       $user = new WP_User($user_id);
888+       $user = wp_get_user($user_id);
889        $user->set_role('administrator');
890 
891        wp_install_defaults($user_id);
892@@ -292,7 +292,7 @@
893                $wp_rewrite->init();
894                $wp_rewrite->flush_rules();
895 
896-               $user = new WP_User($user_id);
897+               $user = wp_get_user($user_id);
898                $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
899 
900                // Remove all perms except for the login user.
901@@ -320,7 +320,7 @@
902  * @param string $password User's Password.
903  */
904 function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
905-       $user = new WP_User($user_id);
906+       $user = wp_get_user($user_id);
907        $email = $user->user_email;
908        $name = $user->user_login;
909        $message = sprintf(__("Your new WordPress site has been successfully set up at:
910Index: wp-admin/includes/deprecated.php
911===================================================================
912--- wp-admin/includes/deprecated.php    (revision 21256)
913+++ wp-admin/includes/deprecated.php    (working copy)
914@@ -249,7 +249,7 @@
915 
916        global $wpdb;
917 
918-       $user = new WP_User( $user_id );
919+       $user = wp_get_user( $user_id );
920        $post_type_obj = get_post_type_object($post_type);
921 
922        if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
923Index: wp-admin/includes/user.php
924===================================================================
925--- wp-admin/includes/user.php  (revision 21256)
926+++ wp-admin/includes/user.php  (working copy)
927@@ -33,7 +33,7 @@
928        if ( $user_id ) {
929                $update = true;
930                $user->ID = (int) $user_id;
931-               $userdata = get_userdata( $user_id );
932+               $userdata = wp_get_user( $user_id );
933                $user->user_login = $wpdb->escape( $userdata->user_login );
934        } else {
935                $update = false;
936@@ -198,7 +198,7 @@
937  * @return object WP_User object with user data.
938  */
939 function get_user_to_edit( $user_id ) {
940-       $user = new WP_User( $user_id );
941+       $user = wp_get_user( $user_id );
942 
943        $user->filter = 'edit';
944 
945@@ -238,7 +238,7 @@
946        global $wpdb;
947 
948        $id = (int) $id;
949-       $user = new WP_User( $id );
950+       $user = wp_get_user( $id );
951 
952        // allow for transaction statement
953        do_action('delete_user', $id);
954@@ -303,7 +303,7 @@
955 function wp_revoke_user($id) {
956        $id = (int) $id;
957 
958-       $user = new WP_User($id);
959+       $user = wp_get_user($id);
960        $user->remove_all_caps();
961 }
962 
963@@ -331,7 +331,7 @@
964        if ( ! get_user_option('default_password_nag', $user_ID) ) //Short circuit it.
965                return;
966 
967-       $new_data = get_userdata($user_ID);
968+       $new_data = wp_get_user($user_ID);
969 
970        if ( $new_data->user_pass != $old_data->user_pass ) { //Remove the nag if the password has been changed.
971                delete_user_setting('default_password_nag', $user_ID);
972Index: wp-admin/includes/ms.php
973===================================================================
974--- wp-admin/includes/ms.php    (revision 21256)
975+++ wp-admin/includes/ms.php    (working copy)
976@@ -132,7 +132,7 @@
977        global $wpdb;
978 
979        $id = (int) $id;
980-       $user = new WP_User( $id );
981+       $user = wp_get_user( $id );
982 
983        do_action( 'wpmu_delete_user', $id );
984 
985@@ -393,7 +393,7 @@
986 
987        $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
988 
989-       $user = new WP_User( $id );
990+       $user = wp_get_user( $id );
991        clean_user_cache( $user );
992 
993        if ( $pref == 'spam' ) {
994@@ -409,7 +409,8 @@
995 function refresh_user_details( $id ) {
996        $id = (int) $id;
997 
998-       if ( !$user = get_userdata( $id ) )
999+       $user = wp_get_user( $id );
1000+       if ( ! $user->exists() )
1001                return false;
1002 
1003        clean_user_cache( $user );
1004@@ -650,7 +651,7 @@
1005        // Directly fetch site_admins instead of using get_super_admins()
1006        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1007 
1008-       $user = new WP_User( $user_id );
1009+       $user = wp_get_user( $user_id );
1010        if ( ! in_array( $user->user_login, $super_admins ) ) {
1011                $super_admins[] = $user->user_login;
1012                update_site_option( 'site_admins' , $super_admins );
1013@@ -678,7 +679,7 @@
1014        // Directly fetch site_admins instead of using get_super_admins()
1015        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1016 
1017-       $user = new WP_User( $user_id );
1018+       $user = wp_get_user( $user_id );
1019        if ( $user->user_email != get_site_option( 'admin_email' ) ) {
1020                if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
1021                        unset( $super_admins[$key] );
1022Index: wp-admin/includes/export.php
1023===================================================================
1024--- wp-admin/includes/export.php        (revision 21256)
1025+++ wp-admin/includes/export.php        (working copy)
1026@@ -239,11 +239,12 @@
1027 
1028                $authors = array();
1029                $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts" );
1030-               foreach ( (array) $results as $result )
1031-                       $authors[] = get_userdata( $result->post_author );
1032+               foreach ( (array) $results as $result ) {
1033+                       $author = wp_get_user( $result->post_author );
1034+                       if ( $author->exists() )
1035+                               $authors[] = $author;
1036+               }
1037 
1038-               $authors = array_filter( $authors );
1039-
1040                foreach ( $authors as $author ) {
1041                        echo "\t<wp:author>";
1042                        echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
1043Index: wp-admin/edit-form-advanced.php
1044===================================================================
1045--- wp-admin/edit-form-advanced.php     (revision 21256)
1046+++ wp-admin/edit-form-advanced.php     (working copy)
1047@@ -322,7 +322,7 @@
1048        if ( 'auto-draft' != $post->post_status ) {
1049                echo '<span id="last-edit">';
1050                if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
1051-                       $last_user = get_userdata($last_id);
1052+                       $last_user = wp_get_user($last_id);
1053                        printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
1054                } else {
1055                        printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
1056Index: wp-admin/network/users.php
1057===================================================================
1058--- wp-admin/network/users.php  (revision 21256)
1059+++ wp-admin/network/users.php  (working copy)
1060@@ -34,7 +34,7 @@
1061 
1062        foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
1063                if ( $val != '' && $val != '0' ) {
1064-                       $delete_user = new WP_User( $val );
1065+                       $delete_user = wp_get_user( $val );
1066 
1067                        if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
1068                                wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
1069@@ -139,7 +139,7 @@
1070                                                        break;
1071 
1072                                                        case 'spam':
1073-                                                               $user = new WP_User( $val );
1074+                                                               $user = wp_get_user( $val );
1075                                                                if ( in_array( $user->user_login, get_super_admins() ) )
1076                                                                        wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
1077 
1078Index: wp-admin/network/site-users.php
1079===================================================================
1080--- wp-admin/network/site-users.php     (revision 21256)
1081+++ wp-admin/network/site-users.php     (working copy)
1082@@ -143,7 +143,7 @@
1083                                        if ( !is_user_member_of_blog( $user_id ) )
1084                                                wp_die(__('Cheatin&#8217; uh?'));
1085 
1086-                                       $user = new WP_User( $user_id );
1087+                                       $user = wp_get_user( $user_id );
1088                                        $user->set_role( $_REQUEST['new_role'] );
1089                                }
1090                        } else {
1091Index: wp-admin/user-edit.php
1092===================================================================
1093--- wp-admin/user-edit.php      (revision 21256)
1094+++ wp-admin/user-edit.php      (working copy)
1095@@ -20,7 +20,7 @@
1096        $user_id = $current_user->ID;
1097 elseif ( ! $user_id && ! IS_PROFILE_PAGE )
1098        wp_die(__( 'Invalid user ID.' ) );
1099-elseif ( ! get_userdata( $user_id ) )
1100+elseif ( ! wp_get_user( $user_id )->exists() )
1101        wp_die( __('Invalid user ID.') );
1102 
1103 wp_enqueue_script('user-profile');
1104@@ -113,7 +113,7 @@
1105 if ( !is_multisite() ) {
1106        $errors = edit_user($user_id);
1107 } else {
1108-       $user = get_userdata( $user_id );
1109+       $user = wp_get_user( $user_id );
1110 
1111        // Update the email address in signups, if present.
1112        if ( $user->user_login && isset( $_POST[ 'email' ] ) && is_email( $_POST[ 'email' ] ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) )