Friday 20 October 2017

Create admin through using FTP: WordPress

There may be some scenarios when you have to implement the changes in website content for WP where client do not have administrator credentials with him which he can share or he has forget about it or there would could be other reasons he don't have the credentials,

If you have cPanel details you can manage the things from there, and if client only shares FTP details, in that case you can follow the below steps to create a new Administrator user:
  1. Connect through valid FTP details:
  2. Visit the website and through view source code confirm the Active theme in your WP.
  3. Through FTP go to your active theme functions.php file and at the very end use the following code with proper admin details you would like to have.

  4.   function wpb_admin_account(){
       $user = 'Username';
       $pass = 'Password';
       $email = '';
       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' );

  5. And do not forget to use unique username and email (as with same details you can't have other WP users).
  6. After user has been created do not forget to use delete this code from your functions.php file.
  7. And you are done!

Below is the video demonstration for above mentioned points.

Version at the time of demonstration
WP: 4.8.2

Load disqus comments