Last active
January 16, 2026 15:37
-
-
Save pacotole/c50319616dc821f87e1f8c1676e98216 to your computer and use it in GitHub Desktop.
Joinchat AI fix expired nonce with page cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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