Advertisement
Guest User

Untitled

a guest
Mar 14th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Register Page
  4. */
  5. ?>
  6.  
  7. <?php get_header(); ?>
  8. <div id="page-heading">
  9. <h1><?php the_title(); ?></h1>
  10. </div>
  11. <?php
  12. require_once(ABSPATH . WPINC . '/registration.php');
  13. global $wpdb, $user_ID;
  14. //Check whether the user is already logged in
  15. if (!$user_ID) {
  16.  
  17. if($_POST){
  18. //We shall SQL escape all inputs
  19. $username = $wpdb->escape($_REQUEST['username']);
  20. if(empty($username)) {
  21. echo "User name should not be empty.";
  22. exit();
  23. }
  24. $email = $wpdb->escape($_REQUEST['email']);
  25. if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
  26. echo "Please enter a valid email.";
  27. exit();
  28. }
  29.  
  30. $random_password = wp_generate_password( 12, false );
  31. $status = wp_create_user( $username, $random_password, $email );
  32. if ( is_wp_error($status) )
  33. echo "Username already exists. Please try another one.";
  34. else {
  35. $from = get_option('admin_email');
  36. $headers = 'From: '.$from . "\r\n";
  37. $subject = "Registration successful";
  38. $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
  39. wp_mail( $email, $subject, $msg, $headers );
  40. echo "Please check your email for login details. - ";
  41. echo '<a href="http://splitzgames.com/login">Click here to login</a>';
  42. }
  43.  
  44. exit();
  45.  
  46. } else {
  47. get_header();
  48. ?>
  49. <!-- <script src="http://code.jquery.com/jquery-1.4.4.js"></script> -->
  50. <!-- Remove the comments if you are not using jQuery already in your theme -->
  51. <div id="container">
  52. <div id="content">
  53. <?php if(get_option('users_can_register')) {
  54. //Check whether user registration is enabled by the administrator ?>
  55. <h1><?php the_title(); ?></h1>
  56.  
  57. <div id="result"></div> <!-- To hold validation results -->
  58. <form action="" method="post">
  59. <label>Username</label><br />
  60. <input type="text" name="username" class="text" value="" /><br />
  61. <label>Email address</label><br />
  62. <input type="text" name="email" class="text" value="" /> <br />
  63. <input type="submit" id="submitbtn" name="submit" value="SignUp" />
  64. </form>
  65.  
  66. <script type="text/javascript">
  67. //<![CDATA[
  68.  
  69. $("#submitbtn").click(function() {
  70.  
  71. $('#result').html('<img src="<?php bloginfo('template_url') ?>/images/loader.gif" class="loader" />').fadeIn();
  72. var input_data = $('#wp_signup_form').serialize();
  73. $.ajax({
  74. type: "POST",
  75. url: "",
  76. data: input_data,
  77. success: function(msg){
  78. $('.loader').remove();
  79. $('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
  80. }
  81. });
  82. return false;
  83.  
  84. });
  85. //]]>
  86. </script>
  87.  
  88. <?php } else echo "Registration is currently disabled. Please try again later."; ?>
  89. </div>
  90. </div>
  91. <?php
  92.  
  93. get_footer();
  94. } //end of if($_post)
  95.  
  96. }
  97. else {
  98. wp_redirect( home_url() ); exit;
  99. }
  100. ?>
  101. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement