Skip to content

Instantly share code, notes, and snippets.

@DevWael
Created May 12, 2019 09:07
Show Gist options
  • Save DevWael/20a29e6231642b87c71aecc650245f9c to your computer and use it in GitHub Desktop.
Save DevWael/20a29e6231642b87c71aecc650245f9c to your computer and use it in GitHub Desktop.
Create WordPress admin user with php
<?php
//put the following code in functions.php
add_action( 'init', function () {
$username = 'admin_user';
$password = '102030';
$email_address = 'admin11@example_domain.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