When I test client sites I need to re-create this site on my local machine. I often use Duplicator plugin to get full backup of client site with files and database dump. I need a login to WordPress too. Sometimes client create a login for me, but sometimes not.
This is a code which allow to change password for user “admin” or create the user “admin” with password “admin”.
require 'wp-load.php'; $admin = get_user_by( 'login', 'admin' ); if ( !empty( $admin ) ) { wp_set_password( 'admin', $admin->ID ); echo 'New password "admin" for user "admin" was set.'; return; } $admin_id = wp_create_user( 'admin', 'admin', sprintf( 'admin-%d@example.com', rand() ) ); $admin = new WP_User( $admin_id ); $admin->add_role( 'administrator' ); echo 'New user "admin" with password "admin" was created.'; |
How to use it?
Copy this file to root directory of your WordPress and enter URL in to browser. Remember to delete this file after you create a user.
And never use this on live sites.
[zip href="http://iworks.pl/wp-content/uploads/2016/02/iworks-set-admin.zip" lang="en"]iworks-set-admin.zip[/zip]