Forked from justingreerbbi/gist:768f1effcca69b4098c9d0f7731deba0
Last active
June 11, 2024 11:43
-
-
Save Aleksandar-Mitic/3d68a4ab24b342ddd89231b9385dfa14 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
add_action( 'rest_api_init', function () { | |
register_rest_route( 'customauthmethods/v1', '/logout/', array( | |
'methods' => 'GET', | |
'callback' => 'custom_logout_user_via_api' | |
) ); | |
} ); | |
function custom_logout_user_via_api() { | |
wp_logout(); | |
wp_redirect(home_url()); | |
exit; | |
} | |
// Call https://site.com/wp-json/customauthmethods/v1/logout/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment