Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <?php require_once(ABSPATH . WPINC . '/registration.php'); global $wpdb, $user_ID; //Check whether the user is already logged in if ($user_ID) {
  2.  
  3. // They're already logged in, so we bounce them back to the homepage.
  4.  
  5. header( 'Location:' . home_url() ); } else {
  6.  
  7. $errors = array();
  8.  
  9. if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  10.  
  11. // Check username is present and not already in use
  12. $username = $wpdb->escape($_REQUEST['username']);
  13. if ( strpos($username, ' ') !== false ) {
  14. $errors['username'] = "Sorry, no spaces allowed in usernames";
  15. }
  16. if(empty($username)) {
  17. $errors['username'] = "Please enter a username";
  18. } elseif( username_exists( $username ) ) {
  19. $errors['username'] = "Username already exists, please try another";
  20. }
  21.  
  22. // Check email address is present and valid
  23. $email = $wpdb->escape($_REQUEST['email']);
  24. if( !is_email( $email ) ) {
  25. $errors['email'] = "Please enter a valid email";
  26. } elseif( email_exists( $email ) ) {
  27. $errors['email'] = "This email address is already in use";
  28. }
  29.  
  30. // Check password is valid
  31. if(0 === preg_match("/.{6,}/", $_POST['password'])){
  32. $errors['password'] = "Password must be at least six characters";
  33. }
  34.  
  35. // Check password confirmation_matches
  36. if(0 !== strcmp($_POST['password'], $_POST['password_confirmation'])){
  37. $errors['password_confirmation'] = "Passwords do not match";
  38. }
  39.  
  40. // Check terms of service is agreed to
  41. if($_POST['terms'] != "Yes"){
  42. $errors['terms'] = "You must agree to Terms of Service";
  43. }
  44.  
  45. if(0 === count($errors)) {
  46.  
  47. $password = $_POST['password'];
  48.  
  49. $new_user_id = wp_create_user( $username, $password, $email );
  50.  
  51. // You could do all manner of other things here like send an email to the user, etc. I leave that to you.
  52.  
  53. $success = 1;
  54.  
  55. header( 'Location:' . get_bloginfo('url') . '/login/?success=1&u=' . $username );
  56.  
  57. }
  58.  
  59. } } ?>
  60.  
  61. <form id="wp_signup_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  62.  
  63. <label for="username">نام کاربری</label>
  64. <input type="text" name="username" id="username"><br>
  65. <label for="email">پست الکترونیکی</label>
  66. <input type="text" name="email" id="email"><br>
  67. <label for="password">کلمه عبور</label>
  68. <input type="password" name="password" id="password"><br>
  69. <label for="password_confirmation">تائید کلمه عبور</label>
  70. <input type="password" name="password_confirmation" id="password_confirmation"><br>
  71.  
  72. <input name="terms" id="terms" type="checkbox" value="Yes">
  73. <label for="terms">من با شرایط استفاده از سرویس موافقم</label>
  74.  
  75. <input type="submit" id="submitbtn" name="submit" value="ایجاد حساب" /> </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement