If you provide WordPress station and maintenance services, at the same time to maintain a lot of customer's website, it is unavoidable to register their own administrator account on the customer's website, every time the operation is not very troublesome? In fact, you can add the following code to the customer's theme of the functions.php file, and then arbitrarily open a page of the site, you can automatically create an administrator account for you.
1Add_action (' Template_redirect ', ' Wpdaxue_create_admin_user ' );2 functionWpdaxue_create_admin_user () {3 4 $username=FALSE;//change false to your user name, including quotation marks (e.g. ' username '),5 $password=FALSE;//change False to your password (e.g. ' password ')6 $email _address=FALSE;//change False to your email address (e.g. ' [email protected] ')7 8 if(isset($username) &&isset($password) &&isset($email _address ) ) {9 if(! username_exists ($username) &&! Email_exists ($email _address ) ) {Ten One $user _id= Wp_create_user ($username,$password,$email _address ); A if(Is_int($user _id ) ) { - $WP _user_object=NewWp_user ($user _id ); - $WP _user_object->set_role (' Administrator ' ); the } - } - } -}
Note: User names, passwords, and mailboxes need to be enclosed in quotation marks. Once the account has been created, delete the above code immediately to prevent security problems.
This method can be directly created by PHP Administrator account, and thus remind us to check the user list of their own site from time to time, whether there is an unknown user account. Also consider this when testing some topics to prevent others from creating administrator accounts with similar code in the topic.
Create a WordPress admin account