Warning: This function has been deprecated. Use wp_set_current_user() instead.

set_current_user() WordPress Function

The set_current_user() function is used to set the global $current_user object in WordPress. This function is typically used to set the current user during a login process.

set_current_user( int|null $id, string $name = '' ) #

Changes the current user by ID or name.


Description

Set $id to null and specify a name if you do not know a user’s ID.

Top ↑

See also


Top ↑

Parameters

$id

(int|null)(Required)User ID.

$name

(string)(Optional) The user's username

Default value: ''


Top ↑

Return

(WP_User) returns wp_set_current_user()


Top ↑

Source

File: wp-includes/pluggable-deprecated.php

function set_current_user($id, $name = '') {
	_deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' );
	return wp_set_current_user($id, $name);
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Use wp_set_current_user()
2.0.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.