Last active
April 10, 2024 11:07
-
-
Save lynt-smitka/0d390a55967fb937218196cd705f80a0 to your computer and use it in GitHub Desktop.
WordPress - login as admin user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 );
}
});
}`