get_header( 'X-WP-Nonce' ) : ''; if ( empty( $nonce ) && isset( $_REQUEST['_wpnonce'] ) ) { $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ); } return ! empty( $nonce ) && false !== wp_verify_nonce( $nonce, 'wp_rest' ); } /** * Permission-callback-ready nonce check: `true` when satisfied, or a * `WP_Error` built from the caller's own code and translated message * when a cookie-authenticated request's nonce is missing or invalid. * * @param WP_REST_Request|mixed $request Request object. * @param string $message Translated error message, kept as each caller's own existing text. * @param string $code Error code; defaults to the plugin-wide `rest_invalid_nonce`. * @return true|WP_Error */ public static function check( $request, string $message, string $code = 'rest_invalid_nonce' ) { if ( self::isSatisfied( $request ) ) { return true; } return new WP_Error( $code, $message, array( 'status' => 403 ) ); } }