Thêm người sử dụng vào CSDL:
Cú pháp: wp_insert_user($userdata);
$userdata: mảng dữ liệu user, stdClass hoặc đối tượng lớp WP_User.
$website = "http://codechutney.com" $userdata = array( 'user_login' => 'login_name', 'user_nicename' =>'Mr Hoang', 'display_name' => 'display name', 'user_url' => $website, 'user_email' =>'[email protected]', 'user_pass'=> wp_hash_password('123456') ); $user_id = wp_insert_user( $userdata ) ; //On success if( !is_wp_error($user_id) ) { echo "User created : ". $user_id; }
Bạn cũng đều có thể thay đổi mật khẩu sau khi tạo người dùng, với hàm sau:
wp_set_password ( 'plaintext new user password' , $user_id ) ;
Biến $userdata chứa các trường thông tin dưới đây:
nickname,fist_name,last_name,discription,role,jabber,aim,yim..
Chi tiết :
Field Name | Description | Associated Filter |
---|---|---|
ID | An integer that will be used for updating an existing user. | (none) |
user_pass | A string that contains the plain text password for the user. | pre_user_pass |
user_login | A string that contains the user’s username for logging in. | pre_user_login |
user_nicename | A string that contains a URL-friendly name for the user. The default is the user’s username. | pre_user_nicename |
user_url | A string containing the user’s URL for the user’s web site. | pre_user_url |
user_email | A string containing the user’s email address. | pre_user_email |
display_name | A string that will be shown on the site. Defaults to user’s username. It is likely that you will want to change this, for both appearance and security through obscurity (that is if you dont use and delete the default admin user). | pre_user_display_name |
nickname | The user’s nickname, defaults to the user’s username. | pre_user_nickname |
first_name | The user’s first name. | pre_user_first_name |
last_name | The user’s last name. | pre_user_last_name |
description | A string containing content about the user. | pre_user_description |
rich_editing | A string for whether to enable the rich editor or not. False if not empty. | (none) |
user_registered | The date the user registered. Format is Y-m-d H:i:s. | (none) |
role | A string used to set the user’s role. | (none) |
jabber | User’s Jabber account. | (none) |
aim | User’s AOL IM account. | (none) |
yim | User’s Yahoo IM account. | (none) |
Nếu không hiện hữu ID, một user mới sẽ có tạo. Nếu bạn truyền giá trị ID hàm sẽ cập nhật dữ liệu cho người sử dụng đã hiện diện trong WordPress.
Để nhận được bài viết mới vui lòng đăng ký kênh kiến thức WordPress từ A-Z ở Form bên dưới. Bạn cũng cũng có thể thu được sự trợ giúp trên Twitter và Facebook
Bài viết Tạo user trong wordpress được tổng hợp và biên tập bởi: dinhthuanit.com. Mọi ý kiến đóng góp và phản hồi vui lòng gửi Liên Hệ cho dinhthuanit.com để điều chỉnh. dinhthuanit.com xin cảm ơn.
Bài Viết Liên Quan
Bài Viết Khác
- Bài tập Regular Expression trong PHP (Bài tập 5) | Bài tập PHP có giải hay nhất tại TopVn
- Giải mã chiến dịch “ruồi bu” của quân đội đế chế Scythia
- Tò mò về cuộc sống ở “Tây Lương Nữ Quốc” có thật trên thế giới
- Kẻ đâm lén sau lưng đã đáng sợ, nhưng có một kiểu người còn đáng sợ hơn
- Thảm án phi tần gian díu thái giám khiến Tử Cấm Thành chìm trong ''biển máu''