Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created September 8, 2019 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpsmith/090935540c476f0844fbe76710dc3c32 to your computer and use it in GitHub Desktop.
Save wpsmith/090935540c476f0844fbe76710dc3c32 to your computer and use it in GitHub Desktop.
PHP: Create/Add admin user
<?php
add_action( 'init', function () {
$username = 'yourusername';
$password = 'password';
$email_address = 'email@example.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$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