If you want to create an admin user programmatically in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* * Create an admin user silently */ add_action('init', 'add_user'); function add_user() { $username = 'username123'; $password = 'pasword123'; // Create the new user $user_id = wp_create_user( $username, $password, $email ); // Get current user object $user = get_user_by( 'id', $user_id ); // Remove role $user->remove_role( 'subscriber' ); // Add role $user->add_role( 'administrator' ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.