WC_API_Authentication::authenticate()publicWC 2.1

Authenticate the request. The authentication method varies based on whether the request was made over SSL or not.

Метод класса: WC_API_Authentication{}

Хуков нет.

Возвращает

null|WP_Error|WP_User.

Использование

$WC_API_Authentication = new WC_API_Authentication();
$WC_API_Authentication->authenticate( $user );
$user(WP_User) (обязательный)
-

Список изменений

С версии 2.1 Введена.

Код WC_API_Authentication::authenticate() WC 8.7.0

public function authenticate( $user ) {

	// Allow access to the index by default
	if ( '/' === WC()->api->server->path ) {
		return new WP_User( 0 );
	}

	try {
		if ( is_ssl() ) {
			$keys = $this->perform_ssl_authentication();
		} else {
			$keys = $this->perform_oauth_authentication();
		}

		// Check API key-specific permission
		$this->check_api_key_permissions( $keys['permissions'] );

		$user = $this->get_user_by_id( $keys['user_id'] );

		$this->update_api_key_last_access( $keys['key_id'] );

	} catch ( Exception $e ) {
		$user = new WP_Error( 'woocommerce_api_authentication_error', $e->getMessage(), array( 'status' => $e->getCode() ) );
	}

	return $user;
}