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: https://develop.svn.wordpress.org/trunk@21376 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-07-31 17:45:38 +00:00
parent cd7e3f097d
commit 2c058d3b3a
1 changed files with 3 additions and 0 deletions

View File

@ -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 )