Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Created August 24, 2021 08:47
Show Gist options
  • Save vanpariyar/a119b65e4b165583d36dc6406e68812e to your computer and use it in GitHub Desktop.
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.
<?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