Last active
February 6, 2022 08:56
-
-
Save aobasar/debcdcaf5ea99f9133c9 to your computer and use it in GitHub Desktop.
quickly adding new user in Wordpress
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
file name: quick-add-new-user-wp.php and open this link on browser (for example): http://domain.com/quick-add-new-user-wp.php | |
<?php | |
// Adding a new user in Wordpress quickly | |
// coded by Ahmet Oguzhan Basar for OZIVISION | |
// 5:43 PM 9/15/2015 | |
$new_username = "oadmin"; | |
$new_username_password = generate_password(); | |
$new_username_email = "[email protected]"; | |
function generate_password( $length = 8 ) { | |
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*()+"; $password = substr( str_shuffle( $chars ), 0, $length ); | |
return $password; | |
} | |
define('WP_USE_THEMES', false); | |
require("wp-load.php"); | |
$wp_name = get_bloginfo('name'); | |
$wp_url = get_bloginfo('url'); | |
$wp_admin_url = admin_url(); | |
$userdata = array( 'user_login' => $new_username, 'user_pass' => $new_username_password, 'user_email' => $new_username_email, 'role' => 'administrator' ); | |
$user_id = wp_insert_user( $userdata ) ; | |
echo "<pre><style>* { line-height: 18px; } input { position: absolute; left: 130px; height: 18px; }</style>"; | |
//On success | |
if ( ! is_wp_error( $user_id ) ) { | |
echo <<< HTML | |
$wp_name | |
-------------- | |
Congratulations! | |
New user created successfully! | |
Userid: $user_id | |
$wp_admin_url | |
Username: $new_username | |
User password: $new_username_password | |
User email: $new_username_email | |
Default <a href="$wp_url/wp-admin/" target="_blank">WP admin</a> - <a href="?delete=yes">Remove Script</a> | |
HTML; | |
} | |
else { | |
echo <<< HTML | |
$wp_name | |
-------------- | |
Error! | |
This user already created! | |
- Username: <b>$new_username</b> | |
Default <a href="$wp_admin_url" target="_blank">WP admin</a> - <a href="?delete=yes">Remove Script</a> | |
HTML; | |
} | |
$filename= str_replace("/","",$_SERVER['PHP_SELF']); | |
if ($_GET['delete']=="yes") { unlink($filename); echo " | |
SCRIPT REMOVED SUCCESSFULLY!"; | |
} | |
else { } | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment