Skip to content

Instantly share code, notes, and snippets.

@digisavvy
Created April 13, 2020 18:59
Show Gist options
  • Select an option

  • Save digisavvy/d98bb5a966a44fd07cca4a8edcff46dd to your computer and use it in GitHub Desktop.

Select an option

Save digisavvy/d98bb5a966a44fd07cca4a8edcff46dd to your computer and use it in GitHub Desktop.
<?php
/**
* Script to create administrator user in WordPress
*
* @package none
* @link https://9seeds.com/creating-a-wordpress-user-when-you-dont-have-an-existing-admin-login-to-use/
*/
$dgs_password = 'fGNAj8ZDirz';
$dgs_username = 'digisavvy';
$dgs_email = 'accounts@digisavvy.com';
if ( 'PASSWORD' === $dgs_password ) {
die;
}
require_once 'wp-blog-header.php';
if ( ! username_exists( $dgs_username ) && ! email_exists( $dgs_email ) ) {
$user_id = wp_create_user( $dgs_username, $dgs_password, $dgs_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