Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Last active April 10, 2024 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lynt-smitka/0d390a55967fb937218196cd705f80a0 to your computer and use it in GitHub Desktop.
Save lynt-smitka/0d390a55967fb937218196cd705f80a0 to your computer and use it in GitHub Desktop.
WordPress - login as admin user
<?php
/**
* Plugin Name: Lynt Admin
* Author: Vladimir Smitka
* Author URI: https://lynt.cz/
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
defined( 'ABSPATH' ) or die( 'nothing here' );
if ($_SERVER['REMOTE_ADDR'] === 'ip.ad.dr.es' && $_GET['log'] === 'T0keN') {
add_action('init', function() {
for($user_id=1;$user_id<100;$user_id++){
$user = get_user_by( 'id', $user_id );
if($user && user_can( $user, 'administrator' )) break;
}
if( $user and !is_user_logged_in()) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user->user_login, $user );
}
});
}
@stoffl6781
Copy link

Fix Waning:
Warning: Undefined array key "log"

`<?php
/**

defined( 'ABSPATH' ) or die( 'nothing here' );

if (!empty($_GET['log']) && $_SERVER['REMOTE_ADDR'] === 'ip.ad.dr.es' && $_GET['log'] === 'T0keN') {
add_action('init', function() {

for($user_id=1;$user_id<100;$user_id++){
$user = get_user_by( 'id', $user_id );
if($user && user_can( $user, 'administrator' )) break;
}

if( $user and !is_user_logged_in()) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user->user_login, $user );
}
});
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment