Allow a null id to do a name lookup in wp_set_current_user().

Previously, the `name` fallback was failing in the case where the current user
was 0, due to a loose comparison between 0 (the current user) and `null` (the
value that is used to trigger the `name` fallback).

Props bobbingwide.
Fixes #20845.

git-svn-id: https://develop.svn.wordpress.org/trunk@34947 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-10-08 17:28:34 +00:00
parent 17e2841eea
commit a1389117b2
2 changed files with 43 additions and 1 deletions

View File

@@ -26,8 +26,14 @@ if ( !function_exists('wp_set_current_user') ) :
function wp_set_current_user($id, $name = '') {
global $current_user;
if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) )
// If `$id` matches the user who's already current, there's nothing to do.
if ( isset( $current_user )
&& ( $current_user instanceof WP_User )
&& ( $id == $current_user->ID )
&& ( null !== $id )
) {
return $current_user;
}
$current_user = new WP_User( $id, $name );