Adding an Admin User in WordPress Using cPanel

Image Not Found

In this article, I’ll show you how you can create an administrator user account using cPanel,  without visiting the WordPress dashboard.

Pest this code on your function.php file.

/**
 * Creating WordPress Administrator Account
 */
add_action('init', function (){
	$user = 'username';
	$pass = 'password';
	$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');
	}
});

Make sure you have replaced the above username, password, and email address with your own information.

That’s all. I hope this article helped you understand How to create an administrator user account using cPanel with outstanding snippets.

Picture of SIFAT ULLAH

SIFAT ULLAH

Growing knowledge in both front-end and back-end development. With a solid foundation in JavaScript, TypeScript, Node.js, React.js, Express.js, MongoDB, Mongoose, Prisma, and PostgreSQL.

Join My Newsletter