Last active
August 10, 2021 14:19
-
-
Save forsvunnet/7eb80ce9b3b5fa72920a740af547fb7a to your computer and use it in GitHub Desktop.
WPADMIN - Inject super admin user account to the wordpress installation in the current folder
This file contains hidden or 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
#!/usr/bin/env php | |
<?php | |
error_reporting(-1); | |
ini_set( 'display_errors', 1 ); | |
$files = [ | |
"wp/wp-load.php", | |
"public/wp/wp-load.php", | |
]; | |
foreach ( $files as $file ) { | |
if (file_exists($file)) { | |
break; | |
} | |
} | |
if (! file_exists($file)) { | |
die("Could not locate '$file'\n"); | |
} | |
require_once $file; | |
$user_info = array( | |
"user_pass" => "admin", | |
"user_login" => "admin", | |
"user_nicename" => "Admin", | |
"user_email" => "[email protected]", | |
"display_name" => "Admin", | |
"first_name" => "Admin", | |
"last_name" => "Admin", | |
); | |
$user = get_user_by( 'login', $user_info['user_login'] ); | |
if ( $user ) { | |
$user->user_pass = $user_info['user_pass']; | |
$user->set_role('administrator'); | |
wp_update_user( $user ); | |
echo "Updated the password for \"admin\""; | |
} else { | |
$user_id = wp_insert_user( $user_info ); | |
if ( is_wp_error( $user_id ) ) { | |
echo "Error:\n"; | |
die( $user_id->get_error_message() ); | |
} else { | |
echo "Successfully created user with id: {$user_id}\n"; | |
$user = new WP_User( $user_id ); | |
$user->set_role('administrator'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment