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.
Built from https://develop.svn.wordpress.org/trunk@34947


git-svn-id: http://core.svn.wordpress.org/trunk@34912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-10-08 17:29:24 +00:00
parent db4f4c5538
commit 48493cdf3a
2 changed files with 8 additions and 2 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 );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34946';
$wp_version = '4.4-alpha-34947';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.