Skip to content

Instantly share code, notes, and snippets.

@pacotole
Last active January 16, 2026 15:37
Show Gist options
  • Select an option

  • Save pacotole/c50319616dc821f87e1f8c1676e98216 to your computer and use it in GitHub Desktop.

Select an option

Save pacotole/c50319616dc821f87e1f8c1676e98216 to your computer and use it in GitHub Desktop.
Joinchat AI fix expired nonce with page cache
/**
* Joinchat AI disable nonce validation in front requests to prevent page cache with expired nonces.
*/
add_action( 'rest_api_init', function() {
// Only modify the authentication for the Joinchat AI refresh token endpoint.
if ( ! isset( $_SERVER['REQUEST_URI'] ) || ! str_contains( wp_unslash( $_SERVER['REQUEST_URI'] ), '/joinchat-ai/v1/refresh_token' ) ) {
return;
}
// Only modify the authentication if the request comes from the same site.
if ( ! isset( $_SERVER['HTTP_REFERER'] ) || ! str_contains( wp_unslash( $_SERVER['HTTP_REFERER'] ), home_url() ) ) {
return;
}
// Do not modify the authentication if the request comes from the admin area.
if ( str_contains( wp_unslash( $_SERVER['HTTP_REFERER'] ), admin_url() ) ) {
return;
}
remove_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment