Skip to content

Instantly share code, notes, and snippets.

@JoryHogeveen
Created November 17, 2022 10:53
Show Gist options
  • Save JoryHogeveen/feb1d63602f89a4bd85cedbc87175d1c to your computer and use it in GitHub Desktop.
Save JoryHogeveen/feb1d63602f89a4bd85cedbc87175d1c to your computer and use it in GitHub Desktop.
WP add admin user
<?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