WC_REST_Authentication::authentication_fallback │ public │ WC 1.0

Authenticate the user if authentication wasn't performed during the determine_current_user action.

This is the usual place a WooCommerce REST API key gets authenticated: it happens here because wp_get_current_user() usually resolves before REST dispatch is confirmed.

Runs at priority 8, just ahead of the default priority other plugins tend to use on this filter, so our own call to get_current_user_id() below is what resolves the real user first.

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

Хуков нет.

Возвращает

WP_Error|null|bool.

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

$WC_REST_Authentication = new WC_REST_Authentication();
$WC_REST_Authentication->authentication_fallback( $error );
$error(WP_Error|null|true|false) (обязательный)
Error data.

Заметки

Смотрите: https://github.com/woocommerce/woocommerce/issues/26847

Код WC_REST_Authentication::authentication_fallback() WC 11.2.2

public function authentication_fallback( $error ) {
	if ( is_wp_error( $error ) ) {
		// Another plugin has already declared a failure. A plain `true` falls through instead.
		return $error;
	}
	if ( 0 === get_current_user_id() && empty( $this->error ) && empty( $this->auth_method ) && empty( $this->user ) ) {
		// Authentication hasn't occurred during `determine_current_user`, so check auth.
		$user_id = $this->authenticate( false );
		if ( $user_id ) {
			wp_set_current_user( $user_id );
		}
	}
	if ( $this->user ) {
		return true;
	}
	return $error;
}