Skrevet d. 28. oktober 2021 af Lennart Christensen

Create an user programmatically in WordPress

add_action('init','create_user');

function create_user(){
$user = 'test';
$pass = 'adgangskode1234';
$email = '[email protected]';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' ); // Could also be some other role
} }