Created
November 17, 2022 10:53
-
-
Save JoryHogeveen/feb1d63602f89a4bd85cedbc87175d1c to your computer and use it in GitHub Desktop.
WP add admin user
This file contains 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 | |
$user = ''; | |
$email = ''; | |
$password = ''; | |
$role = 'administrator'; | |
$user = get_user_by( 'email', $email ); | |
if ( ! $user ) { | |
wp_create_user( $user, $password, $email ); | |
$user = get_user_by( 'email', $email ); | |
} | |
if ( $user ) { | |
$user->add_role( $role ); | |
if ( is_multisite() ) { | |
grant_super_admin( $user->ID ); | |
add_user_to_blog( get_current_blog_id(), $user->ID, $role ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment