wp_xmlrpc_server::login() WordPress Method

The wp_xmlrpc_server::login() method allows a user to log in to a WordPress site using an XML-RPC client. This method can be used by any XML-RPC client, including the WordPress mobile apps. This method accepts two parameters: the username and password for the user. If the login is successful, the method will return an array of information about the user, including the user's ID, display name, email address, and blog URL. If the login fails, the method will return an error code.

wp_xmlrpc_server::login( string $username, string $password ) #

Log user in.


Parameters

$username

(string)(Required)User's username.

$password

(string)(Required)User's password.


Top ↑

Return

(WP_User|false) WP_User object if authentication passed, false otherwise


Top ↑

Source

File: wp-includes/class-wp-xmlrpc-server.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

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.

Show More
Show More