__( 'Invalid or expired nonce.', 'postlinkly' ) ), 403 ); } } /** * Returns whether the request carries a valid nonce for the given action. * * Does not exit on failure. Use this when the caller needs to handle * the failure case itself. * * @since 1.0.0 * * @param string $action The action key the nonce was created for. * @param string $field Optional. Request field name. Default `_wpnonce`. * * @return bool True when the nonce verifies. */ public static function is_valid( string $action, string $field = '_wpnonce' ): bool { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- we are the verifier. $value = isset( $_REQUEST[ $field ] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST[ $field ] ) ) : ''; if ( '' === $value ) { return false; } return (bool) wp_verify_nonce( $value, $action ); } }