
WordPress FTP
Being locked of your WordPress admin is frustrating. That’s why we have shown you 如何通过 MySQL 在 WordPress 中添加管理员用户. Recently one of our readers asked if it was possible to add an admin user in WordPress using FTP. Ofcourse it is. In this article, we will show you how to add an admin user in WordPress using FTP.
被您的WordPress管理员锁定很令人沮丧。 这就是为什么我们向您展示如何通过 MySQL 在 WordPress 中添加管理员用户的原因。 最近,我们的一位读者询问是否可以使用FTP在WordPress中添加管理员用户。 当然是的。 在本文中,我们将向您展示如何使用FTP在WordPress中添加管理员用户。

为什么您可能需要使用FTP在WordPress中添加管理员用户? (Why You May Need to Add an Admin User in WordPress Using FTP?)
Sometimes you may forget your username or email address on a WordPress site and cannot login to the 管理区.
有时,您可能会忘记WordPress网站上的用户名或电子邮件地址,而无法登录到管理区 。
One way to do this is by adding an admin user to the WordPress 数据库 using MySQL. But you may be unable to connect to phpMyAdmin or don’t want to run MySQL queries directly.
一种实现方法是使用MySQL将管理员用户添加到WordPress 数据库中。 但是您可能无法连接到phpMyAdmin或不想直接运行MySQL查询。
某些用户的网站可能会被黑客攻击,管理员帐户可能会被删除。在这种情况下,使用 FTP 添加管理员用户可以快速恢复您对 WordPress 管理区域的访问权限。
某些用户可能会被列入网站黑名单,并删除其管理员帐户。在这种情况下,使用 FTP 添加管理员用户可以快速恢复对 WordPress 管理区域的访问。
话虽如此,让我们看看如何使用 FTP 访问轻松在 WordPress 中添加管理员用户。
话虽如此,让我们看看如何使用 FTP 访问轻松在 WordPress 中添加管理员用户。
使用FTP在WordPress中添加管理员用户 (Adding an Admin User in WordPress Using FTP)
First thing you will need is an FTP客户端. If you are new to using FTP, then see our guide on 如何在WordPress中使用FTP上传文件.
您需要的第一件事是FTP客户端 。 如果您不熟悉FTP,请参阅有关如何使用FTP在WordPress中上传文件指南。
Once connected to your WordPress site, you need to locate your WordPress theme’s 函数.php file. It would be at a location like this:
连接到WordPress网站后,您需要找到WordPress主题的函数.php文件。 它将位于这样的位置:
/yoursite.com/wp-content/themes/your-current-theme/functions.php
/yoursite.com/wp-content/themes/your-current-theme/functions.php
Right click on functions.php
file and then select download. Your FTP client will download the functions.php file to your computer.
右键单击functions.php
文件,然后选择下载。 您的FTP客户端将把functions.php文件下载到您的计算机上。

使用记事本等纯文本编辑器打开刚刚下载到计算机上的文件。现在您需要在文件底部添加此代码。
使用纯文本编辑器(例如记事本)打开刚刚下载到计算机的文件。现在您需要在文件底部添加此代码。
function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
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' );
} }
add_action('init','wpb_admin_account');
不要忘记将用户名、密码和 email@domain.com 替换为您自己的值。
不要忘记将“用户名”、“密码”和“email@domain.com”替换为您自己的值。
接下来,保存文件,然后使用 FTP 客户端将其上传回您的网站。
接下来,保存文件并使用 FTP 客户端将其上传回您的网站。
您现在可以访问 WordPress 网站的登录区域并使用刚刚添加的用户帐户登录。
您现在可以访问 WordPress 网站的登录区域并使用刚刚添加的用户帐户登录。
Once you have logged in to your WordPress site, please edit the functions.php file and 删除您添加的代码. Deleting the code will not remove the user you added, and you can always 将新用户和作者添加到您的 WordPress 网站.
登录WordPress网站后,请编辑functions.php文件并删除添加的代码 。 删除代码不会删除您添加的用户,您始终可以将新用户和作者添加到 WordPress 网站 。
We hope this article helped you learn how to add an admin user to WordPress using FTP. You may also want to see our list of 保护 WordPress 管理区域的 13 个重要提示和技巧.
我们希望本文能帮助您学习如何使用FTP将管理员用户添加到WordPress。 您可能还需要查看我们的13 个重要提示和技巧列表, 保护 WordPress 管理区域 。
If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特和Facebook上找到我们。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-in-wordpress-using-ftp/
WordPress FTP