Created
March 4, 2017 17:02
-
-
Save tranquangchau/cd15f676e35ac28f746ece5a2a9650b4 to your computer and use it in GitHub Desktop.
wp Signup basic
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 | |
| // Template Name: -- Signup | |
| // get header.php | |
| get_header(); | |
| // get theme customizer data | |
| $comments_general = get_option('royal_comments_general'); | |
| if ( is_user_logged_in() ) { | |
| //echo 'Welcome, registered user!'; | |
| //wp_redirect(get_site_url() ); exit; | |
| // auth_redirect(); | |
| // wp_redirect(get_site_url() ); | |
| } else { | |
| // echo 'Welcome, visitor!'; | |
| } | |
| //while( have_posts() ) : the_post(); | |
| the_post(); | |
| get_header(); | |
| ?> | |
| <div class="wrapper"> | |
| <?php | |
| $err = ''; | |
| $success = ''; | |
| global $wpdb, $PasswordHash, $current_user, $user_ID; | |
| if(isset($_POST['task']) && $_POST['task'] == 'register' ) { | |
| $pwd1 = $wpdb->escape(trim($_POST['pwd1'])); | |
| $pwd2 = $wpdb->escape(trim($_POST['pwd2'])); | |
| $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 == "" || $pwd1 == "" || $pwd2 == "" || $username == "" || $first_name == "" || $last_name == "") { | |
| $err = 'Please don\'t leave the required fields.'; | |
| } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| $err = 'Invalid email address.'; | |
| } else if(email_exists($email) ) { | |
| $err = 'Email already exist.'; | |
| } else if($pwd1 <> $pwd2 ){ | |
| $err = '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', $pwd1), '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) ) { | |
| $err = 'Error on user creation.'; | |
| } else { | |
| do_action('user_register', $user_id); | |
| $success = 'You\'re successfully register'; | |
| } | |
| } | |
| } | |
| ?> | |
| <!--display error/success message--> | |
| <div id="message"> | |
| <?php | |
| if(! empty($err) ) : | |
| echo '<p class="error">'.$err.''; | |
| endif; | |
| ?> | |
| <?php | |
| if(! empty($success) ) : | |
| echo '<p class="error">'.$success.''; | |
| endif; | |
| ?> | |
| </div> | |
| <form method="post"> | |
| <h3>Don't have an account?<br /> Create one now.</h3> | |
| <p><label>Last Name</label></p> | |
| <p><input type="text" value="" name="last_name" id="last_name" /></p> | |
| <p><label>First Name</label></p> | |
| <p><input type="text" value="" name="first_name" id="first_name" /></p> | |
| <p><label>Email</label></p> | |
| <p><input type="text" value="" name="email" id="email" /></p> | |
| <p><label>Username</label></p> | |
| <p><input type="text" value="" name="username" id="username" /></p> | |
| <p><label>Password</label></p> | |
| <p><input type="password" value="" name="pwd1" id="pwd1" /></p> | |
| <p><label>Password again</label></p> | |
| <p><input type="password" value="" name="pwd2" id="pwd2" /></p> | |
| <div class="alignleft"><p><?php if($sucess != "") { echo $sucess; } ?> <?php if($err != "") { echo $err; } ?></p></div> | |
| <button type="submit" name="btnregister" class="button" >Submit</button> | |
| <input type="hidden" name="task" value="register" /> | |
| </form> | |
| </div> | |
| <?php get_footer() ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment