Introduction to user management in WordPress
WordPress is one of the most popular platforms for creating websites, and one of the reasons for its success is the ability to manage users and roles effectively. However, on occasion, you may find yourself in a situation where you need to add an administrator user without having access to the WordPress control panel. This can happen for various reasons, such as loss of access to the account or problems with plugins that block the administration. In these cases, an effective solution is to use FTP to perform this task.
Access to your server via FTP
To get started, you will need an FTP client. There are several options available, such as FileZilla, Cyberduck or WinSCP. Once you have downloaded and installed your FTP client, follow these steps to access your server:
- Open FTP client and enter your login credentials (server address, username and password).
- Connect to the server where your WordPress site is hosted.
- Navigate to the main folder of your WordPress installation, which is usually /public_html or /www/.
Once you are in the WordPress root directory, you are ready to make the necessary changes to add a new admin user.
Modifying the functions.php file
To create a new administrator user, we will need to add a code snippet in the file functions.php of your active theme. This file is located in your theme folder, which you might find at /wp-content/themes/your-current-issue/.
Example code for adding an administrator user
Open the file functions.php and add the following code to the end of the file:
function add_user_admin() {
$username = 'new_admin';
$password = 'secure_password';
$email = 'email@ejemplo.com';
if (!username_exists($username) && !email_exists($email)) {
$user_id = wp_create_user($username, $password, $email);
$user = new WP_User($user_id);
$user->set_role('administrator');
}
}
add_action('init', 'add_user_admin');
Replaces new_admin, secure_password y email@ejemplo.com with the values of your choice.
Saving changes and testing access
After adding the code, save the changes to the file functions.php and close the FTP client. Now it is time to test if the new user has been created correctly. To do this, follow these steps:
- Go to your WordPress login page: tusitio.com/wp-admin.
- Log in with the new_username and the password you have created.
If you have followed all the steps correctly, you should be able to access the administration panel as an administrator. Make sure to verify that everything is working correctly and that the new user has full access.
Remove the code from the functions.php file
Once you have created the new user, it is very important that you delete the code you added to the file functions.php. Leaving the code could allow other users to create unwanted accounts on your site, which may pose a security risk.
Access your file again functions.php via FTP and delete the code block you added previously. Save the changes and close the FTP client to ensure your site is protected.
Safety considerations
Adding an administrator user via FTP is a useful process, but it also carries certain risks. Here are some tips to keep in mind:
- Use strong and unique passwords for each user account.
- Consider implementing additional security measures, such as two-step authentication.
- Regularly monitor user activity on your site to detect unauthorized access.
The security of your WordPress site is critical, so be sure to maintain good user and password management practices.
