wp_xmlrpc_server::login( string $username, string $password ): WP_User|false

In this article

Logs user in.

Parameters

$usernamestringrequired
User’s username.
$passwordstringrequired
User’s password.

Return

WP_User|false WP_User object if authentication passed, false otherwise.

Source

public function login( $username, $password ) {
	if ( ! $this->is_enabled ) {
		$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
		return false;
	}

	if ( $this->auth_failed ) {
		$user = new WP_Error( 'login_prevented' );
	} else {
		$user = wp_authenticate( $username, $password );
	}

	if ( is_wp_error( $user ) ) {
		$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) );

		// Flag that authentication has failed once on this wp_xmlrpc_server instance.
		$this->auth_failed = true;

		/**
		 * Filters the XML-RPC user login error message.
		 *
		 * @since 3.5.0
		 *
		 * @param IXR_Error $error The XML-RPC error message.
		 * @param WP_Error  $user  WP_Error object.
		 */
		$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user );
		return false;
	}

	wp_set_current_user( $user->ID );
	return $user;
}

Hooks

apply_filters( ‘xmlrpc_login_error’, IXR_Error $error, WP_Error $user )

Filters the XML-RPC user login error message.

Changelog

VersionDescription
2.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.