In your PHP, use wp_create_user()
.
With this function, you can pass username
, email
and `password’.
Then, wp update user()
to give the user the other bits of info.
I would hook my user-creation function to the init
hook.
Also, you want to put a nonce field in your form e.g. this, between the <form>
tags:
<?php wp_nonce_field( 'create_user_form_submit', 'djie3duhb3edub3u' ); ?>
E.g.
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
}
}
}