Skip to content

Instantly share code, notes, and snippets.

@miguelfrias
Created September 14, 2016 02:56
Show Gist options
  • Save miguelfrias/82b46498cde0980b099812bfa8700c9f to your computer and use it in GitHub Desktop.
Save miguelfrias/82b46498cde0980b099812bfa8700c9f to your computer and use it in GitHub Desktop.
Wordpress script to create users
<?php
/*
* Create Admin User
*/
$jb_password = 'PASSWORD'; #enter your desired password here, if you don't line 16 makes sure nothing bad happens like setting you actual password to 'PASSWORD'
$jb_username = 'user';
$jb_email = 'user@example.com';
if ( $jb_password === 'PASSWORD' )
die;
require_once('wp-blog-header.php');
if ( !username_exists($jb_username) && !email_exists($jb_email) ) {
$user_id = wp_create_user( $jb_username, $jb_password, $jb_email);
if ( is_int($user_id) ) {
$wp_user_object = new WP_User($user_id);
$wp_user_object->set_role('administrator');
echo 'Success!';
} else {
echo 'Error with wp_insert_user. No users were created.';
}
} else {
echo 'This user or email already exists. Nothing was done.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment