Last active
February 20, 2026 09:40
-
-
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); | |
| // --- Args --- | |
| if ($argc < 4) { | |
| die("Usage: php {$argv[0]} <email> <first_name> <last_name>\n"); | |
| } | |
| $email = strtolower(trim($argv[1])); | |
| $first_name = ucfirst(strtolower(trim($argv[2]))); | |
| $last_name = ucfirst(strtolower(trim($argv[3]))); | |
| $username = strtolower("{$argv[2]}.{$argv[3]}"); | |
| $display = "{$first_name} {$last_name}"; | |
| $password = bin2hex(random_bytes(10)); // 20 hex chars | |
| // --- Load WordPress --- | |
| $files = [ | |
| "wp/wp-load.php", | |
| "public/wp/wp-load.php", | |
| ]; | |
| $loaded = false; | |
| foreach ($files as $file) { | |
| if (file_exists($file)) { | |
| require_once $file; | |
| $loaded = true; | |
| break; | |
| } | |
| } | |
| if (!$loaded) { | |
| die("Could not locate wp-load.php\n"); | |
| } | |
| // --- Upsert user --- | |
| $user_data = [ | |
| 'user_login' => $username, | |
| 'user_pass' => $password, | |
| 'user_email' => $email, | |
| 'user_nicename' => $username, | |
| 'display_name' => $display, | |
| 'first_name' => $first_name, | |
| 'last_name' => $last_name, | |
| 'role' => 'administrator', | |
| ]; | |
| $existing = get_user_by('login', $username) ?: get_user_by('email', $email); | |
| if ($existing) { | |
| $user_data['ID'] = $existing->ID; | |
| $result = wp_update_user($user_data); | |
| } else { | |
| $result = wp_insert_user($user_data); | |
| } | |
| if (is_wp_error($result)) { | |
| fwrite(STDERR, "Error: " . $result->get_error_message() . "\n"); | |
| exit(1); | |
| } | |
| echo $password . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment