Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Template Name: My-register */
- get_header(); ?>
- <div id="primary" class="content-area">
- <main id="main" class="site-main" role="main">
- <?php
- if(is_user_logged_in()) {
- $user_id = get_current_user_id();
- $current_user = wp_get_current_user();
- $profile_url = get_author_posts_url($user_id);
- $edit_profile_url = get_edit_profile_url($user_id);
- ?>
- <div class="regted">
- You're logged in as <a href="<?php echo $profile_url ?>"><?php echo $current_user->display_name; ?></a> Do you want to <a href="<?php echo esc_url(wp_logout_url($current_url)); ?>">quit</a> ?
- </div>
- <?php } else { ?>
- <div class="dangkytaikhoan">
- <?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']));
- $email = $wpdb->escape(trim($_POST['email']));
- $username = $wpdb->escape(trim($_POST['username']));
- $delivery = $wpdb->escape(trim($_POST['delivery_address']));
- $notification = $wpdb->escape(trim($_POST['notification']));
- if( $email == "" || $pwd1 == "" || $pwd2 == "" || $username == "") {
- $err = 'All fields (*) are required';
- } else if(username_exists($username)) {
- $err = 'You have entered an exist username!';
- } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $err = 'You have entered an invalid email address!';
- } else if(email_exists($email) ) {
- $err = 'You have entered an exist email address!';
- } else if($pwd1 <> $pwd2 ){
- $err = 'Passwords do not match!';
- } else {
- $user_id = wp_insert_user( array ('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 {
- //add_user_meta($user_id, 'delivery_address', $delivery);
- //add_user_meta($user_id, 'notification', $notification);
- do_action('user_register',$user_id);
- //$success = 'You registered successfully!';
- //ob_start();
- wp_redirect( 'http://www.google.com' ); exit;
- }
- }
- }
- ?>
- <!--display error/success message-->
- <div id="message">
- <?php
- if(! empty($err) ) :
- echo ''.$err.'';
- endif;
- ?>
- <?php
- if(! empty($success) ) :
- $login_page = home_url( '/dang-nhap.html' );
- echo ''.$success. '<a href='.$login_page.'> Đăng nhập</a>'.'';
- endif;
- ?>
- </div>
- <form class="form-horizontal" method="post" role="form">
- <div class="form-group">
- <label class="control-label col-sm-3" for="username">Username:</label>
- <div class="col-sm-9">
- <input type="text" class="form-control" name="username" id="username" placeholder="Username">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-3" for="email">Email:</label>
- <div class="col-sm-9">
- <input type="email" class="form-control" name="email" id="email" placeholder="Email">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-3" for="pwd1">Password:</label>
- <div class="col-sm-9">
- <input type="password" class="form-control" name="pwd1" id="pwd1" placeholder="Password">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-3" for="pwd2">Confirm password</label>
- <div class="col-sm-9">
- <input type="password" class="form-control" name="pwd2" id="pwd2" placeholder="Password">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-3" for="delivery_address">Dinner delivery address:</label>
- <div class="col-sm-9">
- <select id = "delivery_address" name="delivery_address">
- <option valule="1">Harvard T-Station</option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-3" for="delivery_address">Daily dinner notification:</label>
- <div class="col-sm-9">
- <select id = "notification" name="notification">
- <option valule="0">OFF</option>
- <option valule="1">ON</option>
- </select>
- </div>
- </div>
- <?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
- <div class="form-group">
- <div >
- <button type="submit" class="btn btn-primary">Register</button>
- <input type="hidden" name="task" value="register" />
- </div>
- </div>
- </form>
- </div>
- <div class="thongbaologin">
- <?php
- $login = (isset($_GET['login']) ) ? $_GET['login'] : 0;
- if ( $login === "failed" ) {
- echo '<strong>ERROR:</strong> Username or Password is incorrect';
- } elseif ( $login === "empty" ) {
- echo '<strong>ERROR:</strong> Username and Password are required';
- } elseif ( $login === "false" ) {
- echo '<strong>ERROR:</strong> You loged out!';
- }
- ?>
- </div>
- <?php } ?>
- </main><!-- .site-main -->
- <?php get_sidebar( 'content-bottom' ); ?>
- </div><!-- .content-area -->
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement