WC_API_Server::check_authentication()publicWC 2.1

Check authentication for the request

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

Хуки из метода

Возвращает

WP_User|WP_Error. WP_User object indicates successful login, WP_Error indicates unsuccessful login

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

$WC_API_Server = new WC_API_Server();
$WC_API_Server->check_authentication();

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

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

Код WC_API_Server::check_authentication() WC 8.7.0

public function check_authentication() {

	// allow plugins to remove default authentication or add their own authentication
	$user = apply_filters( 'woocommerce_api_check_authentication', null, $this );

	if ( is_a( $user, 'WP_User' ) ) {

		// API requests run under the context of the authenticated user
		wp_set_current_user( $user->ID );

	} elseif ( ! is_wp_error( $user ) ) {

		// WP_Errors are handled in serve_request()
		$user = new WP_Error( 'woocommerce_api_authentication_error', __( 'Invalid authentication method', 'woocommerce' ), array( 'code' => 500 ) );

	}

	return $user;
}