From 174dad02bc2370ff559ed63a10d11d54ce25b139 Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 31 Jul 2012 17:45:38 +0000 Subject: [PATCH] Optimize get_user_by( 'id', $id ) to return wp_get_current_user() when the current user ID is requested. Provides for a major performance improvement by preventing repeated instantiations of WP_User in the capabilities API. see #21120. git-svn-id: http://core.svn.wordpress.org/trunk@21376 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index ac308a9966..49208e6a73 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -133,6 +133,9 @@ if ( !function_exists('get_user_by') ) : * @return bool|object False on failure, WP_User object on success */ function get_user_by( $field, $value ) { + if ( 'id' === $field && (int) $value && get_current_user_id() === (int) $value ) + return wp_get_current_user(); + $userdata = WP_User::get_data_by( $field, $value ); if ( !$userdata )