Created
August 24, 2021 08:47
-
-
Save vanpariyar/a119b65e4b165583d36dc6406e68812e to your computer and use it in GitHub Desktop.
Create a user in the wordpress dashboard using the PHP in the 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 | |
/** | |
* Create a user in the wordpress dashboard using the PHP in the wordpress. | |
*/ | |
add_action('init', 'create_user_account'); | |
function create_user_account() { | |
$username = 'username123'; | |
$email = '[email protected]'; | |
$password = 'pasword123'; | |
$user_id = username_exists( $username ); | |
if ( !$user_id && email_exists($email) == false ) { | |
$user_id = wp_create_user( $username, $password, $email ); | |
if( !is_wp_error($user_id) ) { | |
$user = get_user_by( 'id', $user_id ); | |
$user->set_role( 'administrator' ); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment