Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Aleksandar-Mitic/3d68a4ab24b342ddd89231b9385dfa14 to your computer and use it in GitHub Desktop.
Save Aleksandar-Mitic/3d68a4ab24b342ddd89231b9385dfa14 to your computer and use it in GitHub Desktop.
Logout user using WP REST API WordPress Custom Endpoint
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