SO网友:Dan.
在PHP中,使用wp_create_user().
使用此函数,您可以通过username, email 和“密码”。
然后wp update user() 为用户提供其他信息。
我会将我的用户创建函数挂接到init 钩
此外,您希望在表单中放置一个nonce字段,例如this,在<form> 标签:
<?php wp_nonce_field( \'create_user_form_submit\', \'djie3duhb3edub3u\' ); ?>
例如:。
add_action(\'init\', \'my_theme_create_new_user\');
function my_theme_create_new_user(){
if (
! isset( $_POST[\'djie3duhb3edub3u\'] )
|| ! wp_verify_nonce( $_POST[\'djie3duhb3edub3u\'], \'create_user_form_submit\')
)else{
$username = sanitize_text_field($_POST[\'user_name\'];
$email = sanitize_text_field($_POST[\'user_email\'];
$password = $_POST[\'user_password\'];
$user_id = username_exists( $username );
if ( !$user_id and email_exists($email) == false ) {
// do some code to validate password how ever you want it.
$user_id = wp_create_user( $username, $password, $email );
$stuff = array(\'ID\'=>$user_id,\'another_user_field\'=>\'something\');
wp update user($stuff) // first name, last name etc
} else {
return false; //username exists already
}
}
}