Home / WP Register new user CODEX

WP Register new user CODEX

// Start of validation
	if(!$_agree){
		$error['_agree'] = __('Must need to accept terms');
	}
	if(!$_email){
		$error['_email'] = __('Enter email');
	}elseif ( email_exists( $_email ) ) {
		$error['_email'] = 'Email already exists';
	}
	if(!$_phone){
		$error['_phone'] = __('Enter phone');
	}
	if(!$_password1){
		$error['_password1'] = __('Enter password');
	}elseif(strlen($_password1) < 6){
		$error['_password1'] = __('Password minimum 6 character');
	}
	if(!$_password2){
		$error['_password2'] = __('Re Enter password');
	}elseif($_password1 != $_password2){
		$error['_password2'] = __('Password didn\'t match');
	}
// End of validation

// Start of insert user

// Create user
	if(!$error){
		$user_id = wp_create_user( $_email, $_password1, $_email );
		// $user    = new WP_User( $user_id );
		// $user->set_role( 'subscriber' );

		// Update user info
		wp_update_user( array(
				'ID'           => $user_id,
				'display_name' => "$_first_name $_last_name",
				'first_name'   => $_first_name,
				'last_name'    => $_last_name,
			) );
		// Your action here
	}
// End of insert user

all rights reserved