Advertisement
numinous

signuppage.php

Nov 27th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.91 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4.     This file is part of Join My Multisite, a plugin for WordPress.
  5.  
  6.     Join My Multisite is free software: you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation, either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     Sitewide Comment Control is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with WordPress.  If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('ABSPATH')) {
  20.     die();
  21. }
  22.  
  23. //$jmm_options = get_option( 'helfjmm_options' );
  24. //    if ( !is_null($jmm_options['perpage']) && $jmm_options['perpage'] != "XXXXXX"  )
  25. //        {$goto = get_permalink($jmm_options['perpage']); echo get_permalink($jmm_options['perpage']); echo $goto; }
  26. //    else
  27. //        {$goto = '/wp-signup.php'; echo 'hi2'; }
  28. ?>
  29.     <style type="text/css">
  30.         .mu_register { width: 90%; margin:0 auto; }
  31.         .mu_register form { margin-top: 2em; }
  32.         .mu_register .error { font-weight:700; padding:10px; color:#333333; background:#FFEBE8; border:1px solid #CC0000; }
  33.         .mu_register input[type="submit"],
  34.             .mu_register #blog_title,
  35.             .mu_register #user_email,
  36.             .mu_register #blogname,
  37.             .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
  38.         .mu_register .prefix_address,
  39.             .mu_register .suffix_address {font-size: 18px;display:inline; }
  40.         .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
  41.         .mu_register label.checkbox { display:inline; }
  42.         .mu_register .mu_alert { font-weight:700; padding:10px; color:#333333; background:#ffffe0; border:1px solid #e6db55; }
  43.     </style>
  44.  
  45. <div id="content" class="widecolumn">
  46. <div class="mu_register">
  47. <?php
  48.  
  49. function show_user_form($user_name = '', $user_email = '', $errors = '') {
  50.     // User name
  51.     echo '<label for="user_name">' . __('Username:', 'helfjmm') . '</label>';
  52.     if ( $errmsg = $errors->get_error_message('user_name') ) {
  53.         echo '<p class="error">'.$errmsg.'</p>';
  54.     }
  55.     echo '<input name="user_name" type="text" id="user_name" value="'. esc_attr($user_name) .'" maxlength="60" /><br />';
  56.     _e( '(Must be at least 4 characters, letters and numbers only.)', 'helfjmm' );
  57.     ?>
  58.  
  59.     <label for="user_email"><?php _e( 'Email&nbsp;Address:', 'helfjmm' ) ?></label>
  60.     <?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
  61.         <p class="error"><?php echo $errmsg ?></p>
  62.     <?php } ?>
  63.     <input name="user_email" type="text" id="user_email" value="<?php  echo esc_attr($user_email) ?>" maxlength="200" /><br /><?php _e('We send your registration email to this address. (Double-check your email address before continuing.)', 'helfjmm') ?>
  64.     <?php
  65.     if ( $errmsg = $errors->get_error_message('generic') ) {
  66.         echo '<p class="error">' . $errmsg . '</p>';
  67.     }
  68.     do_action( 'signup_extra_fields', $errors );
  69. }
  70.  
  71. function validate_user_form() {
  72.     return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
  73. }
  74.  
  75. function signup_user($user_name = '', $user_email = '', $errors = '') {
  76.     global $current_site, $active_signup;
  77.  
  78.  
  79. $jmm_options = get_option( 'helfjmm_options' );
  80.     if ( !is_null($jmm_options['perpage']) && $jmm_options['perpage'] != "XXXXXX"  )
  81.         {$goto = get_permalink($jmm_options['perpage']); }
  82.     else
  83.         {$goto = '/wp-signup.php';}
  84.  
  85.  
  86.     if ( !is_wp_error($errors) )
  87.         $errors = new WP_Error();
  88.  
  89.     $signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
  90.  
  91.     // allow definition of default variables
  92.     $filtered_results = apply_filters('signup_user_init', array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ));
  93.     $user_name = $filtered_results['user_name'];
  94.     $user_email = $filtered_results['user_email'];
  95.     $errors = $filtered_results['errors'];
  96.    
  97.     $blog_details = get_blog_details($current_site->blog_id);
  98.  
  99.     ?>
  100.  
  101.     <h2><?php printf( __( 'Get a user account on %s in seconds', 'helfjmm' ), $blog_details->blogname ) ?></h2>
  102.     <form id="setupform" method="post" action="<?php echo $goto; ?>">
  103.         <input type="hidden" name="stage" value="validate-user-signup" />
  104.         <?php do_action( 'signup_hidden_fields' ); ?>
  105.         <?php show_user_form($user_name, $user_email, $errors); ?>
  106.  
  107.         <p>
  108.             <input id="signupblog" type="hidden" name="signup_for" value="user" />
  109.         </p>
  110.  
  111.         <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Sign Up', 'helfjmm') ?>" /></p>
  112.     </form>
  113.     <?php
  114. }
  115.  
  116. function validate_user_signup() {
  117.     $result = validate_user_form();
  118.     extract($result);
  119.  
  120.     if ( $errors->get_error_code() ) {
  121.         $errors = rewrite_errors_for_translation($errors);
  122.         signup_user($user_name, $user_email, $errors);
  123.         return false;
  124.     }
  125.  
  126.     if ( 'blog' == $_POST['signup_for'] ) {
  127.         signup_blog($user_name, $user_email);
  128.         return false;
  129.     }
  130.  
  131.     wpmu_signup_user($user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
  132.  
  133.     confirm_user_signup($user_name, $user_email);
  134.     return true;
  135. }
  136.  
  137. function rewrite_errors_for_translation($errors) {
  138.     $rewritten_errors = new WP_Error();
  139.    
  140.     $messages = $errors->get_error_messages();
  141.     foreach ($messages as $value) {
  142.         switch ($value) {
  143.             case 'Only lowercase letters (a-z) and numbers are allowed.':
  144.                 $rewritten_errors->add( 'user_name', __( 'Only lowercase letters (a-z) and numbers are allowed.', 'helfjmm' ) );
  145.                 break;
  146.             case 'Please enter a username.':
  147.                 $rewritten_errors->add( 'user_name', __( 'Please enter a username.', 'helfjmm' ) );
  148.                 break;
  149.             case 'That username is not allowed.':
  150.                 $rewritten_errors->add( 'user_name', __( 'That username is not allowed.', 'helfjmm' ) );
  151.                 break;
  152.             case 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.':
  153.                 $rewritten_errors->add( 'user_name', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.', 'helfjmm' ) );
  154.                 break;
  155.             case 'Username must be at least 4 characters.':
  156.                 $rewritten_errors->add('user_name',  __( 'Username must be at least 4 characters.', 'helfjmm' ) );
  157.                 break;
  158.             case 'Sorry, usernames may not contain the character &#8220;_&#8221;!':
  159.                 $rewritten_errors->add('user_name',  __( 'Sorry, usernames may not contain the character &#8220;_&#8221;!', 'helfjmm' ) );
  160.                 break;
  161.             case 'Sorry, usernames must have letters too!':
  162.                 $rewritten_errors->add('user_name',  __( 'Sorry, usernames must have letters too!', 'helfjmm' ) );
  163.                 break;
  164.             case 'Please enter a correct email address.':
  165.                 $rewritten_errors->add('user_email',  __( 'Please enter a correct email address.', 'helfjmm' ) );
  166.                 break;
  167.             case 'Sorry, that email address is not allowed!':
  168.                 $rewritten_errors->add('user_email',  __( 'Sorry, that email address is not allowed!', 'helfjmm' ) );
  169.                 break;
  170.             case 'Sorry, that username already exists!':
  171.                 $rewritten_errors->add('user_name',  __( 'Sorry, that username already exists!', 'helfjmm' ) );
  172.                 break;
  173.             case 'Sorry, that email address is already used!':
  174.                 $rewritten_errors->add('user_email',  __( 'Sorry, that email address is already used!', 'helfjmm' ) );
  175.                 break;
  176.             case 'That username is currently reserved but may be available in a couple of days.':
  177.                 $rewritten_errors->add('user_name',  __( 'That username is currently reserved but may be available in a couple of days.', 'helfjmm' ) );
  178.                 break;
  179.             case 'username and email used':
  180.                 $rewritten_errors->add('user_email_used',  __( 'username and email used', 'helfjmm' ) );
  181.                 break;
  182.             case 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.':
  183.                 $rewritten_errors->add('user_email',  __( 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.', 'helfjmm' ) );
  184.                 break;
  185.         }
  186.     }
  187.     return $rewritten_errors;
  188. }
  189.  
  190. function confirm_user_signup($user_name, $user_email) {
  191.     ?>
  192.     <h2><?php printf( __( '%s is your new username', 'helfjmm' ), $user_name) ?></h2>
  193.     <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.', 'helfjmm' ) ?></p>
  194.     <p><?php printf( __( 'Check your inbox at <strong>%s</strong> and click the link given.', 'helfjmm' ), $user_email ); ?></p>
  195.     <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.', 'helfjmm' ); ?></p>
  196.     <?php
  197.     do_action( 'signup_finished' );
  198. }
  199.  
  200. // Main
  201. $active_signup = get_site_option( 'registration' );
  202. if ( !$active_signup )
  203.     $active_signup = 'all';
  204.  
  205. $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
  206.  
  207. // Make the signup type translatable.
  208. $i18n_signup['all'] = _x('all', 'Multisite active signup type');
  209. $i18n_signup['none'] = _x('none', 'Multisite active signup type');
  210. $i18n_signup['blog'] = _x('blog', 'Multisite active signup type');
  211. $i18n_signup['user'] = _x('user', 'Multisite active signup type');
  212.  
  213. if ( is_super_admin() )
  214.     echo '<div class="mu_alert">' . sprintf( __( 'Greetings Site Administrator! You are currently allowing &#8220;%s&#8221; registrations. To change or disable registration go to your <a href="%s">Options page</a>.', 'helfjmm' ), $i18n_signup[$active_signup], esc_url( network_admin_url( 'settings.php' ) ) ) . '</div>';
  215.  
  216. $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
  217.  
  218. $current_user = wp_get_current_user();
  219. if ( $active_signup == 'none' ) {
  220.     _e( 'Registration has been disabled.' );
  221. } else {
  222.     $stage = isset( $_POST['stage'] ) ?  $_POST['stage'] : 'default';
  223.     switch ( $stage ) {
  224.         case 'validate-user-signup' :
  225.             if ( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
  226.                 validate_user_signup();
  227.             else
  228.                 _e( 'User registration has been disabled.', 'helfjmm' );
  229.         break;
  230.         case 'default':
  231.         default :
  232.             $user_email = isset( $_POST[ 'user_email' ] ) ? $_POST[ 'user_email' ] : '';
  233.             do_action( 'preprocess_signup_form' ); // populate the form from invites, elsewhere?
  234.             if ( is_user_logged_in() == false && ( $active_signup == 'all' || $active_signup == 'user' ) )
  235.                 signup_user( $user_email );
  236.             else
  237.                 _e( 'You are logged in already. No need to register again!', 'helfjmm' );
  238.             break;
  239.     }
  240. }
  241. ?>
  242. </div>
  243. </div>
  244. <?php do_action( 'after_signup_form' ); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement