dsdv76767671 2013-07-25 14:57
浏览 61
已采纳

Wordpress,以编程方式创建用户

How do I go about creating wordpress users programmatically?

I am using the method below, user is being created - but when I try to login with a password it gives me wrong password message, any suggestions please?

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' => "wacek123@gmail.com",
    '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);
  • 写回答

1条回答 默认 最新

  • douyi4912 2013-09-24 12:14
    关注

    I'd recommand using wp_create_user instead: http://codex.wordpress.org/Function_Reference/wp_create_user

    Example:

    $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.');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle