PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/2.0.1/wp-register.php

#
PHP | 158 lines | 126 code | 29 blank | 3 comment | 16 complexity | f91f6decd342d2d212092c62faf6e829 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. require('./wp-config.php');
  3. require_once( ABSPATH . WPINC . '/registration-functions.php');
  4. $action = $_REQUEST['action'];
  5. if ( !get_settings('users_can_register') )
  6. $action = 'disabled';
  7. header( 'Content-Type: ' . get_bloginfo('html_type') . '; charset=' . get_bloginfo('charset') );
  8. switch( $action ) {
  9. case 'register':
  10. $user_login = sanitize_user( $_POST['user_login'] );
  11. $user_email = $_POST['user_email'];
  12. $errors = array();
  13. if ( $user_login == '' )
  14. $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
  15. /* checking e-mail address */
  16. if ($user_email == '') {
  17. $errors['user_email'] = __('<strong>ERROR</strong>: Please type your e-mail address.');
  18. } else if (!is_email($user_email)) {
  19. $errors['user_email'] = __('<strong>ERROR</strong>: The email address isn&#8217;t correct.');
  20. }
  21. if ( ! validate_username($user_login) )
  22. $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');
  23. if ( username_exists( $user_login ) )
  24. $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
  25. /* checking the email isn't already used by another user */
  26. $email_exists = $wpdb->get_row("SELECT user_email FROM $wpdb->users WHERE user_email = '$user_email'");
  27. if ( $email_exists)
  28. die (__('<strong>ERROR</strong>: This email address is already registered, please supply another.'));
  29. if ( 0 == count($errors) ) {
  30. $password = substr( md5( uniqid( microtime() ) ), 0, 7);
  31. $user_id = wp_create_user( $user_login, $password, $user_email );
  32. if ( !$user_id )
  33. $errors['user_id'] = sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'));
  34. else
  35. wp_new_user_notification($user_id, $password);
  36. }
  37. if ( 0 == count($errors) ) {
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <title>WordPress &raquo; <?php _e('Registration Complete') ?></title>
  43. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
  44. <link rel="stylesheet" href="wp-admin/wp-admin.css" type="text/css" />
  45. <style type="text/css">
  46. .submit {
  47. font-size: 1.7em;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="login">
  53. <h2><?php _e('Registration Complete') ?></h2>
  54. <p><?php printf(__('Username: %s'), "<strong>$user_login</strong>") ?><br />
  55. <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>') ?> <br />
  56. <?php printf(__('E-mail: %s'), "<strong>$user_email</strong>") ?></p>
  57. <p class="submit"><a href="wp-login.php"><?php _e('Login'); ?> &raquo;</a></p>
  58. </div>
  59. </body>
  60. </html>
  61. <?php
  62. break;
  63. }
  64. default:
  65. ?>
  66. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  67. <html xmlns="http://www.w3.org/1999/xhtml">
  68. <head>
  69. <title>WordPress &raquo; <?php _e('Registration Form') ?></title>
  70. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
  71. <link rel="stylesheet" href="wp-admin/wp-admin.css" type="text/css" />
  72. <style type="text/css">
  73. #user_email, #user_login, #submit {
  74. font-size: 1.7em;
  75. }
  76. </style>
  77. </head>
  78. <body>
  79. <div id="login">
  80. <h1><a href="http://wordpress.org/">WordPress</a></h1>
  81. <h2><?php _e('Register for this blog') ?></h2>
  82. <?php if ( isset($errors) ) : ?>
  83. <div class="error">
  84. <ul>
  85. <?php
  86. foreach($errors as $error) echo "<li>$error</li>";
  87. ?>
  88. </ul>
  89. </div>
  90. <?php endif; ?>
  91. <form method="post" action="wp-register.php" id="registerform">
  92. <p><input type="hidden" name="action" value="register" />
  93. <label for="user_login"><?php _e('Username:') ?></label><br /> <input type="text" name="user_login" id="user_login" size="20" maxlength="20" value="<?php echo $user_login; ?>" /><br /></p>
  94. <p><label for="user_email"><?php _e('E-mail:') ?></label><br /> <input type="text" name="user_email" id="user_email" size="25" maxlength="100" value="<?php echo $user_email; ?>" /></p>
  95. <p><?php _e('A password will be emailed to you.') ?></p>
  96. <p class="submit"><input type="submit" value="<?php _e('Register') ?> &raquo;" id="submit" name="submit" /></p>
  97. </form>
  98. <ul>
  99. <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>">&laquo; <?php _e('Back to blog') ?></a></li>
  100. <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li>
  101. <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
  102. </ul>
  103. </div>
  104. </body>
  105. </html>
  106. <?php
  107. break;
  108. case 'disabled':
  109. ?>
  110. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  111. <html xmlns="http://www.w3.org/1999/xhtml">
  112. <head>
  113. <title>WordPress &raquo; <?php _e('Registration Currently Disabled') ?></title>
  114. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
  115. <link rel="stylesheet" href="wp-admin/wp-admin.css" type="text/css">
  116. </head>
  117. <body>
  118. <div id="login">
  119. <h2><?php _e('Registration Disabled') ?></h2>
  120. <p><?php _e('User registration is currently not allowed.') ?><br />
  121. <a href="<?php echo get_settings('home'); ?>/" title="<?php _e('Go back to the blog') ?>"><?php _e('Home') ?></a>
  122. </p>
  123. </div>
  124. </body>
  125. </html>
  126. <?php
  127. break;
  128. }
  129. ?>