Last active
June 11, 2024 11:40
-
-
Save justingreerbbi/768f1effcca69b4098c9d0f7731deba0 to your computer and use it in GitHub Desktop.
Logout user using WP REST API WordPress Custom Endpoint
This file contains 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
myplugin can be anything you need it to be. Typically this is the custom name for your custom API.
Be sure to change the redirect URL in the
wp_redirect
function