Logs the current user out.
Source
function wp_logout() {
$user_id = get_current_user_id();
wp_destroy_current_session();
wp_clear_auth_cookie();
wp_set_current_user( 0 );
/**
* Fires after a user is logged out.
*
* @since 1.5.0
* @since 5.5.0 Added the `$user_id` parameter.
*
* @param int $user_id ID of the user that was logged out.
*/
do_action( 'wp_logout', $user_id );
}
Hooks
- do_action( ‘wp_logout’,
int $user_id ) Fires after a user is logged out.
Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |
Logout function according user role.
object(WP_User)[947] public 'data' => object(stdClass)[948] public 'ID' => int 0 public 'caps' => array (size=0) empty public 'cap_key' => null public 'roles' => array (size=0) empty public 'allcaps' => array (size=0) empty public 'filter' => null private 'site_id' => int 0
Example
wp_logout();
should always be wrapped in an if statement.