在WordPress中以编程方式创建管理员用户 [英] Create an admin user programmatically in WordPress
本文介绍了在WordPress中以编程方式创建管理员用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个问答集:
最近我有一个客户来找我来建立一个新网站。他们也忘记了所有登录详细信息,但是他们确实具有FTP访问权限。
Recently I had a client come to me to build a new website. They had also forgotten all their login details, but they did have FTP access.
那么,如何通过代码创建管理员用户?
推荐答案
如果放在主题functions.php文件中,则会创建一个管理员用户。
This will create an admin user if placed in a themes functions.php file.
请根据需要更改前三个变量。
Please change the first three variables as needed.
/*
* Create an admin user silently
*/
add_action('init', 'add_user');
function add_user() {
$username = 'username123';
$password = 'pasword123';
$email = 'drew@example.com';
// Create the new user
$user_id = wp_create_user( $username, $password, $email );
// Get current user object
$user = get_user_by( 'id', $user_id );
// Remove role
$user->remove_role( 'subscriber' );
// Add role
$user->add_role( 'administrator' );
}
这篇关于在WordPress中以编程方式创建管理员用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文