Hoi.
I've lost my WordPress username password and e-mail (cannot remember it) 🙁
If I want to add a new user (with username + password) with administrator priviliges to my CPanel for my WordPress web-site, how can I do it?
- Maybe by using PHP My Admin?
- Should I use FTP program?
- Or should I add some function in the theme?
- Which function?
Please help resolve this issue!
Thanks!
Hi. Here are the steps:
1. Use FTP program (I use https://filezilla-project.org/ ) - fill your username + password there (you can also use Cpanel File editor)
2. Go to YOUR ACTIVE WordPress CMS theme: public_html/wp-content/themes/YOUR_THEME/functions.php
3. Edit functions.php and add the following code at the bottom:
function admin_account() {
$user = 'YOUR_USERNAME';
$pass = 'YOUR_PASSWORD';
$email = 'YOUR_E-MAIL';
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' );
}
}
add_action( 'init', 'admin_account' );
Make sure to fill lines 2,3 and 4 with your information!
It should like like this:

You can also check PHP My Admin in your Cpanel to see whether there is new user there;
Go to: Your WP Data Base >> wp_users
Here how it looks like:

You can also watch this short video:
You can also create mu-plugins directory in wp-content folder and create there .php file with the same function; This way no matter what your current theme is - the code will work like a charm! 🙂
