Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. <?php
  2. /* Template Name: My-register */
  3.  
  4. get_header(); ?>
  5.  
  6. <div id="primary" class="content-area">
  7. <main id="main" class="site-main" role="main">
  8. <?php
  9. if(is_user_logged_in()) {
  10. $user_id = get_current_user_id();
  11. $current_user = wp_get_current_user();
  12. $profile_url = get_author_posts_url($user_id);
  13. $edit_profile_url = get_edit_profile_url($user_id);
  14. ?>
  15. <div class="regted">
  16. 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> ?
  17. </div>
  18. <?php } else { ?>
  19. <div class="dangkytaikhoan">
  20. <?php
  21. $err = ''; $success = '';
  22. global $wpdb, $PasswordHash, $current_user, $user_ID;
  23. if(isset($_POST['task']) && $_POST['task'] == 'register' ) {
  24. $pwd1 = $wpdb->escape(trim($_POST['pwd1']));
  25. $pwd2 = $wpdb->escape(trim($_POST['pwd2']));
  26. $email = $wpdb->escape(trim($_POST['email']));
  27. $username = $wpdb->escape(trim($_POST['username']));
  28. $delivery = $wpdb->escape(trim($_POST['delivery_address']));
  29. $notification = $wpdb->escape(trim($_POST['notification']));
  30. if( $email == "" || $pwd1 == "" || $pwd2 == "" || $username == "") {
  31. $err = 'All fields (*) are required';
  32. } else if(username_exists($username)) {
  33. $err = 'You have entered an exist username!';
  34. } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  35. $err = 'You have entered an invalid email address!';
  36. } else if(email_exists($email) ) {
  37. $err = 'You have entered an exist email address!';
  38. } else if($pwd1 <> $pwd2 ){
  39. $err = 'Passwords do not match!';
  40. } else {
  41. $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' ) );
  42. if( is_wp_error($user_id) ) {
  43. $err = 'Error on user creation.';
  44. } else {
  45. //add_user_meta($user_id, 'delivery_address', $delivery);
  46. //add_user_meta($user_id, 'notification', $notification);
  47. do_action('user_register',$user_id);
  48. //$success = 'You registered successfully!';
  49. //ob_start();
  50. wp_redirect( 'http://www.google.com' ); exit;
  51. }
  52. }
  53. }
  54. ?>
  55. <!--display error/success message-->
  56. <div id="message">
  57. <?php
  58. if(! empty($err) ) :
  59. echo ''.$err.'';
  60. endif;
  61. ?>
  62. <?php
  63. if(! empty($success) ) :
  64. $login_page = home_url( '/dang-nhap.html' );
  65. echo ''.$success. '<a href='.$login_page.'> Đăng nhập</a>'.'';
  66. endif;
  67. ?>
  68. </div>
  69. <form class="form-horizontal" method="post" role="form">
  70. <div class="form-group">
  71. <label class="control-label col-sm-3" for="username">Username:</label>
  72. <div class="col-sm-9">
  73. <input type="text" class="form-control" name="username" id="username" placeholder="Username">
  74. </div>
  75. </div>
  76. <div class="form-group">
  77. <label class="control-label col-sm-3" for="email">Email:</label>
  78. <div class="col-sm-9">
  79. <input type="email" class="form-control" name="email" id="email" placeholder="Email">
  80. </div>
  81. </div>
  82. <div class="form-group">
  83. <label class="control-label col-sm-3" for="pwd1">Password:</label>
  84. <div class="col-sm-9">
  85. <input type="password" class="form-control" name="pwd1" id="pwd1" placeholder="Password">
  86. </div>
  87. </div>
  88. <div class="form-group">
  89. <label class="control-label col-sm-3" for="pwd2">Confirm password</label>
  90. <div class="col-sm-9">
  91. <input type="password" class="form-control" name="pwd2" id="pwd2" placeholder="Password">
  92. </div>
  93. </div>
  94.  
  95. <div class="form-group">
  96. <label class="control-label col-sm-3" for="delivery_address">Dinner delivery address:</label>
  97. <div class="col-sm-9">
  98. <select id = "delivery_address" name="delivery_address">
  99. <option valule="1">Harvard T-Station</option>
  100. </select>
  101. </div>
  102. </div>
  103.  
  104. <div class="form-group">
  105. <label class="control-label col-sm-3" for="delivery_address">Daily dinner notification:</label>
  106. <div class="col-sm-9">
  107. <select id = "notification" name="notification">
  108. <option valule="0">OFF</option>
  109. <option valule="1">ON</option>
  110. </select>
  111. </div>
  112. </div>
  113.  
  114. <?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
  115. <div class="form-group">
  116. <div >
  117. <button type="submit" class="btn btn-primary">Register</button>
  118. <input type="hidden" name="task" value="register" />
  119. </div>
  120. </div>
  121. </form>
  122. </div>
  123. <div class="thongbaologin">
  124. <?php
  125. $login = (isset($_GET['login']) ) ? $_GET['login'] : 0;
  126. if ( $login === "failed" ) {
  127. echo '<strong>ERROR:</strong> Username or Password is incorrect';
  128. } elseif ( $login === "empty" ) {
  129. echo '<strong>ERROR:</strong> Username and Password are required';
  130. } elseif ( $login === "false" ) {
  131. echo '<strong>ERROR:</strong> You loged out!';
  132. }
  133. ?>
  134. </div>
  135.  
  136. <?php } ?>
  137. </main><!-- .site-main -->
  138.  
  139. <?php get_sidebar( 'content-bottom' ); ?>
  140.  
  141. </div><!-- .content-area -->
  142.  
  143. <?php get_sidebar(); ?>
  144. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement