Skip to content

Instantly share code, notes, and snippets.

@scjudd
Created May 18, 2018 21:53
Show Gist options
  • Save scjudd/13eb842726768ca9ed676259b1f5af93 to your computer and use it in GitHub Desktop.
Save scjudd/13eb842726768ca9ed676259b1f5af93 to your computer and use it in GitHub Desktop.
PHP to create a WordPress admin user
<?php
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
$username = 'spencer';
$password = 'f00b4rb4z!';
$email = 'spencercjudd@gmail.com';
if (!username_exists($username) && !email_exists($email)) {
$user_id = wp_create_user($username, $password, $email);
if (is_int($user_id)) {
$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