settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: How to add user (administrator) to CPanel / FTP for WordPress site?

+10 votes

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!

asked in Web Development category by user Jolie Ann
recategorized by user golearnweb

2 Answers

+9 votes

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:

add user to WordPress site using FTP and CPanel

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:

adding new user to database in WordPress

You can also watch this short video:

https://www.youtube.com/watch?v=HU2SLzWhpJ4

answered by user matthew44
edited by user golearnweb
Nice! Thank you so muuuched!!
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! :-)
+1 vote

If you have access the the mySQL database you can use SQL queries to create ne administrator in couple of seconds: Read HERE how

answered by user golearnweb
...