Created
March 26, 2017 19:01
-
-
Save MrJSdev/0114811e380945ca9d2500b2b363f08b to your computer and use it in GitHub Desktop.
PHP code of Registration Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $success = ''; | |
| $error = ''; | |
| global $wpdb, $PasswordHash, $current_user, $user_ID; | |
| if(isset($_POST['task']) && $_POST['task'] == 'register' ) { | |
| $password1 = $wpdb->escape(trim($_POST['password1'])); | |
| $password2 = $wpdb->escape(trim($_POST['password2'])); | |
| $first_name = $wpdb->escape(trim($_POST['first_name'])); | |
| $last_name = $wpdb->escape(trim($_POST['last_name'])); | |
| $email = $wpdb->escape(trim($_POST['email'])); | |
| $username = $wpdb->escape(trim($_POST['username'])); | |
| if( $email == "" || $password1 == "" || $password2 == "" || $username == "" || $first_name == "" || $last_name == "") { | |
| $error = 'Please don\'t leave the required fields.'; | |
| } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| $error = 'Invalid email address.'; | |
| } else if(email_exists($email) ) { | |
| $error = 'Email already exist.'; | |
| } else if($password1 <> $password2 ){ | |
| $error = 'Password do not match.'; | |
| } else { | |
| $user_id = wp_insert_user( array ('first_name' => apply_filters('pre_user_first_name', $first_name), 'last_name' => apply_filters('pre_user_last_name', $last_name), 'user_pass' => apply_filters('pre_user_user_pass', $password1), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'subscriber' ) ); | |
| if( is_wp_error($user_id) ) { | |
| $error = 'Error on user creation.'; | |
| } else { | |
| do_action('user_register', $user_id); | |
| $success = 'You\'re successfully register'; | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment