gpt4 book ai didi

php - Wordpress,以编程方式创建用户

转载 作者:行者123 更新时间:2023-12-02 21:55:41 26 4
gpt4 key购买 nike

如何以编程方式创建 WordPress 用户?

我正在使用下面的方法,正在创建用户 - 但是当我尝试使用密码登录时,它给了我错误的密码消息,请问有什么建议吗?

include 'wp-blog-header.php';
include 'wp-includes/registration.php';
include 'wp-includes/pluggable.php';
ini_set("memory_limit","1024M");
ini_set("max_execution_time", "240");
global $wpdb;
programmatically
$row = array(
'user_name' => "wacek123",
'password' => "wacek123",
'email_address' => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="07706664626c36353447606a666e6b2964686a" rel="noreferrer noopener nofollow">[email protected]</a>",
'name' => "wacek123",
'surname' => "wacek123"
);



$userdata = array(
'user_login' => $row["user_name"],
'user_pass' => wp_hash_password($row["password"]),
'user_nicename' => $row["user_name"],
'user_email' => $row["email_address"],
'first_name' => $row["name"],
'last_name' => $row["surname"],
'role' => 'subscriber'
);
wp_insert_user($userdata);

最佳答案

我建议使用 wp_create_user 代替: http://codex.wordpress.org/Function_Reference/wp_create_user

示例:

$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
$random_password = __('User already exists. Password inherited.');
}

关于php - Wordpress,以编程方式创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17861590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com