Last active
August 6, 2025 06:15
-
-
Save justingreerbbi/768f1effcca69b4098c9d0f7731deba0 to your computer and use it in GitHub Desktop.
Logout user using WP REST API WordPress Custom Endpoint
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
| /** | |
| * Head to https://wp-oauth.com for more info on user authentication and custom login and out solutions | |
| * for WordPress | |
| */ | |
| add_action( 'rest_api_init', function () { | |
| register_rest_route( 'wpoauthserver/v1', '/logout/', array( | |
| 'methods' => 'GET', | |
| 'callback' => 'wp_oauth_server_logout' | |
| ) ); | |
| } ); | |
| function wp_oauth_server_logout() { | |
| wp_logout(); | |
| wp_redirect('https://redirect-location.com'); | |
| exit; | |
| } | |
| // Call https://site.com/wp-json/wpoauthserver/v1/logout/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it not work ?