Restoring access to WordPress without MySql but via PHP and FTP
Many sites have already described how to recover a password for a wordpress site through a database or a regular access recovery., but today I decided to describe another non-standard way that I had to find while working with the manager of one studio.
There was one case, when the client had access to FTP but did not have access to the CMS admin panel, at the same time, the task was set and it was necessary to urgently begin work.
The first thing that came to my mind was to try to change the database through php, but it took a long time to write and I started to google how to create my own user. The method is really fast..
Creating a WordPress User with a Hook
There is a way to create your own plugin or just put this code in the function.php file in the theme folder. So add code to functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 |
add_action( 'init', function () { $username = 'wpadmin'; $password = 'password'; $email_address = 'webmaster@mydomain.com'; if ( ! username_exists( $username ) ) { $user_id = wp_create_user( $username, $password, $email_address ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } ); |
After pasting the code in the functions.php file, you just need to log in at /wp-admin/ and enter wpadmin login and password password.
If you know other interesting ways, write in the comments, it would be interesting to know. If interested to know, how to recover password through database, then write in the comments, I will write an article.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.