Automattic\WooCommerce\Internal\RestApi
InteractiveSessionCheck::require_interactive_session
Check that the current user was authenticated by cookie and that the request carries a valid wp_rest nonce, as a _wpnonce parameter or an X-WP-Nonce header.
Метод класса: InteractiveSessionCheck{}
Хуков нет.
Возвращает
WP_Error|true.
Использование
$result = InteractiveSessionCheck::require_interactive_session( $request );
- $request(обязательный)
- .
Заметки
Global. Разное. $wp_rest_auth_cookie True when core validated an auth cookie for this request. |
Список изменений
| С версии 11.2.2 | Введена. |
Код InteractiveSessionCheck::require_interactive_session() InteractiveSessionCheck::require interactive session WC 11.2.2
public static function require_interactive_session( $request ) {
global $wp_rest_auth_cookie;
$nonce = $request->get_param( '_wpnonce' ) ?? $request->get_header( 'X-WP-Nonce' );
if ( ! is_user_logged_in() || true !== $wp_rest_auth_cookie || ! is_string( $nonce ) || ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
return new WP_Error(
'woocommerce_rest_missing_session',
__( 'Sorry, you cannot perform this action without an interactive admin session.', 'woocommerce' ),
array( 'status' => rest_authorization_required_code() )
);
}
return true;
}