Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created May 12, 2023 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tallesairan/b2b61bef0c81f973cdf61e4cb8a7fcdf to your computer and use it in GitHub Desktop.
Save tallesairan/b2b61bef0c81f973cdf61e4cb8a7fcdf to your computer and use it in GitHub Desktop.
Get user by id and log-in
<?php
$username = "z";
$user = get_user_by('login', $username );
// Redirect URL //
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
$redirect_to = user_admin_url();
wp_safe_redirect( $redirect_to );
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment