WC_REST_Authentication::authentication_fallback()publicWC 1.0

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

Necessary in cases where wp_get_current_user() is called before WooCommerce is loaded.

Method of the class: WC_REST_Authentication{}

No Hooks.

Return

WP_Error|null|true|false.

Usage

$WC_REST_Authentication = new WC_REST_Authentication();
$WC_REST_Authentication->authentication_fallback( $error );
$error(WP_Error|null|true|false) (required)
Error data.

Notes

WC_REST_Authentication::authentication_fallback() code WC 8.7.0

public function authentication_fallback( $error ) {
	if ( ! empty( $error ) ) {
		// Another plugin has already declared a failure.
		return $error;
	}
	if ( empty( $this->error ) && empty( $this->auth_method ) && empty( $this->user ) && 0 === get_current_user_id() ) {
		// 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 );
			return true;
		}
	}
	return $error;
}