2013-07-25 211 views
1

如何以編程方式創建WordPress用戶?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' => "[email protected]", 
    '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); 
+0

你試過嗎? ''password'=> md5(「wacek123」)' – user2019515

回答

3

我使用推薦替代wp_create_userhttp://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.'); 
} 
相關問題