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

wp_login() WordPress Function

wp_login() is a function used to log a user in to a WordPress site. This function accepts a username and password as parameters and then verifies the user's credentials. If the user is successfully logged in, the function will return true. Otherwise, it will return false.

wp_login( string $username, string $password, string $deprecated = '' ) #

Checks a users login information and logs them in if it checks out. This function is deprecated.


Description

Use the global $error to get the reason why the login failed. If the username is blank, no error will be set, so assume blank username on that case.

Plugins extending this function should also provide the global $error and set what the error is, so that those checking the global for why there was a failure can utilize it later.

Top ↑

See also


Top ↑

Parameters

$username

(string)(Required)User's username

$password

(string)(Required)User's password

$deprecated

(string)(Optional)Not used

Default value: ''


Top ↑

Return

(bool) True on successful check, false on login failure.


Top ↑

Source

File: wp-includes/pluggable-deprecated.php

function wp_login($username, $password, $deprecated = '') {
	_deprecated_function( __FUNCTION__, '2.5.0', 'wp_signon()' );
	global $error;

	$user = wp_authenticate($username, $password);

	if ( ! is_wp_error($user) )
		return true;

	$error = $user->get_error_message();
	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Use wp_signon()
1.2.2Introduced.

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.