[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress 3.0

Provided by Yoast

title

Body

[close]

/wp-admin/ -> user-new.php (source)

   1  <?php
   2  /**
   3   * New User Administration Panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('./admin.php');
  11  
  12  if ( !current_user_can('create_users') )
  13      wp_die(__('Cheatin&#8217; uh?'));
  14  
  15  if ( is_multisite() && !get_site_option( 'add_new_users' ) )
  16      wp_die( __('Page disabled by the administrator') );
  17  
  18  /** WordPress Registration API */
  19  require_once( ABSPATH . WPINC . '/registration.php');
  20  
  21  if ( is_multisite() ) {
  22  	function admin_created_user_email( $text ) {
  23          return sprintf( __( "Hi,
  24  You've been invited to join '%s' at
  25  %s as a %s.
  26  If you do not want to join this site please ignore
  27  this email. This invitation will expire in a few days.
  28  
  29  Please click the following link to activate your user account:
  30  %%s" ), get_bloginfo('name'), site_url(), esc_html( $_REQUEST[ 'role' ] ) );
  31      }
  32      add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
  33  
  34  	function admin_created_user_subject( $text ) {
  35          return "[" . get_bloginfo('name') . "] Your site invite";
  36      }
  37  }
  38  
  39  if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
  40      check_admin_referer('add-user');
  41  
  42      if ( !is_multisite() ) {
  43          $user_id = add_user();
  44  
  45          if ( is_wp_error( $user_id ) ) {
  46              $add_user_errors = $user_id;
  47          } else {
  48              if ( current_user_can('edit_users') ) {
  49                  $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
  50                  $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add' . '#user-' . $user_id;
  51              } else {
  52                  $redirect = add_query_arg( 'update', 'add', 'user-new.php' );
  53              }
  54              wp_redirect( $redirect );
  55              die();
  56          }
  57      } else {
  58          $user_login = preg_replace( "/\s+/", '', sanitize_user( $_REQUEST[ 'user_login' ], true ) );
  59          $user_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE user_login = %s AND user_email = %s", $user_login, $_REQUEST[ 'email' ] ) );
  60          if ( $user_details ) {
  61              // Adding an existing user to this blog
  62              $new_user_email = esc_html(trim($_REQUEST['email']));
  63              $redirect = 'user-new.php';
  64              $username = $user_details->user_login;
  65              $user_id = $user_details->ID;
  66              if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
  67                  $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
  68              } else {
  69                  if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
  70                      add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
  71                      $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
  72                  } else {
  73                      $newuser_key = substr( md5( $user_id ), 0, 5 );
  74                      add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
  75                      $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s as a %s.\nPlease click the following link to confirm the invite:\n%s\n");
  76                      wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
  77                      $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
  78                  }
  79              }
  80              wp_redirect( $redirect );
  81              die();
  82          } else {
  83              // Adding a new user to this blog
  84              $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] );
  85              unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] );
  86              if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
  87                  $add_user_errors = $user_details[ 'errors' ];
  88              } else {
  89                  $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
  90                  if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
  91                      add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
  92                  }
  93                  wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) );
  94                  if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
  95                      $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $_REQUEST[ 'email' ] ) );
  96                      wpmu_activate_signup( $key );
  97                      $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
  98                  } else {
  99                      $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' );
 100                  }
 101                  wp_redirect( $redirect );
 102                  die();
 103              }
 104          }
 105      }
 106  }
 107  
 108  $title = __('Add New User');
 109  $parent_file = 'users.php';
 110  
 111  add_contextual_help($current_screen,
 112      '<p>' . __('To add a new user to your site, fill in the form on this screen. If you&#8217;re not sure which role to assign, you can use the link below to review the different roles and their capabilities. Here is a basic overview of roles:') . '</p>' .
 113      '<ul>' .
 114          '<li>' . __('Administrators have access to all the administration features.') . '</li>' .
 115          '<li>' . __('Editors can publish posts, manage posts as well as manage other people&#8217;s posts, etc.')  . '</li>' .
 116          '<li>' . __('Authors can publish and manage their own posts.') . '</li>' .
 117          '<li>' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '</li>' .
 118          '<li>' . __('Subscribers can read comments/comment/receive newsletters, etc.') . '</li>' .
 119      '</ul>' .
 120      '<p>' . __('You must assign a password to the new user, but don&#8217;t worry; when they log in for the first time they will be prompted to change it. The username, however, cannot be changed.') . '</p>' .
 121      '<p>' . __('New users will receive an email letting them know they&#8217;ve been added as a user for your site. By default, this email will also contain their password. Uncheck the box if you do not the password to be included in the welcome email.') . '</p>' .
 122      '<p>' . __('Remember to click the Add User button at the bottom of this screen when you are finished.') . '</p>' .
 123      '<p><strong>' . __('For more information:') . '</strong></p>' .
 124      '<p>' . __('<a href="http://codex.wordpress.org/Users_Add_New_SubPanel" target="_blank">Documentation on Adding New Users</a>') . '</p>' .
 125      '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
 126  );
 127  
 128  wp_enqueue_script('wp-ajax-response');
 129  wp_enqueue_script('user-profile');
 130  wp_enqueue_script('password-strength-meter');
 131  
 132  require_once  ('admin-header.php');
 133  
 134  if ( isset($_GET['update']) ) {
 135      $messages = array();
 136      if ( is_multisite() ) {
 137          switch ( $_GET['update'] ) {
 138              case "newuserconfimation":
 139                  $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
 140                  break;
 141              case "add":
 142                  $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
 143                  break;
 144              case "addnoconfirmation":
 145                  $messages[] = __('User has been added to your site.');
 146                  break;
 147              case "addexisting":
 148                  $messages[] = __('That user is already a member of this site.');
 149                  break;
 150          }
 151      } else {
 152          if ( 'add' == $_GET['update'] )
 153              $messages[] = __('User added.');
 154      }
 155  }
 156  ?>
 157  <div class="wrap">
 158  <?php screen_icon(); ?>
 159  <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
 160  
 161  <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
 162      <div class="error">
 163          <ul>
 164          <?php
 165              foreach ( $errors->get_error_messages() as $err )
 166                  echo "<li>$err</li>\n";
 167          ?>
 168          </ul>
 169      </div>
 170  <?php endif;
 171  
 172  if ( ! empty( $messages ) ) {
 173      foreach ( $messages as $msg )
 174          echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
 175  } ?>
 176  
 177  <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?>
 178      <div class="error">
 179          <?php
 180              foreach ( $add_user_errors->get_error_messages() as $message )
 181                  echo "<p>$message</p>";
 182          ?>
 183      </div>
 184  <?php endif; ?>
 185  <div id="ajax-response"></div>
 186  
 187  <?php
 188  if ( !is_multisite() ) {
 189      if ( get_option('users_can_register') )
 190          echo '<p>' . sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), site_url('wp-register.php')) . '</p>';
 191      else
 192          echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), admin_url('options-general.php#users_can_register')) . '</p>';
 193  } else {
 194      echo '<p>' . __( 'You can add new users to your site in two ways:' ) . '<ol><li> ' . __( 'Enter the username and email address of an existing user on this site.' ) . '</li><li> ' . __( 'Enter the username and the email address of a person who is not already a member of this site. Choose the username carefully, it cannot be changed.' ) . '</li></ol></p>';
 195      echo '<p>' . __( 'That person will be sent an email asking them to click a link confirming the invite. New users will then be sent an email with a randomly generated password and a login link.' ) . '</p>';
 196  }
 197  ?>
 198  <form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:users: validate"<?php do_action('user_new_form_tag');?>>
 199  <?php wp_nonce_field('add-user') ?>
 200  <?php
 201  //Load up the passed data, else set to a default.
 202  foreach ( array('user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname',
 203                  'email' => 'email', 'url' => 'uri', 'role' => 'role') as $post_field => $var ) {
 204      $var = "new_user_$var";
 205      if ( ! isset($$var) )
 206          $$var = isset($_POST[$post_field]) ? stripslashes($_POST[$post_field]) : '';
 207  }
 208  $new_user_send_password = !$_POST || isset($_POST['send_password']);
 209  ?>
 210  <table class="form-table">
 211      <tr class="form-field form-required">
 212          <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
 213          <input name="action" type="hidden" id="action" value="adduser" /></th>
 214          <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
 215      </tr>
 216      <tr class="form-field form-required">
 217          <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
 218          <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td>
 219      </tr>
 220  <?php if ( !is_multisite() ) { ?>
 221      <tr class="form-field">
 222          <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
 223          <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
 224      </tr>
 225      <tr class="form-field">
 226          <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
 227          <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
 228      </tr>
 229      <tr class="form-field">
 230          <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
 231          <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td>
 232      </tr>
 233  <?php if ( apply_filters('show_password_fields', true) ) : ?>
 234      <tr class="form-field form-required">
 235          <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(twice, required)'); ?></span></label></th>
 236          <td><input name="pass1" type="password" id="pass1" autocomplete="off" />
 237          <br />
 238          <input name="pass2" type="password" id="pass2" autocomplete="off" />
 239          <br />
 240          <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
 241          <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
 242          </td>
 243      </tr>
 244      <tr>
 245          <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th>
 246          <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked($new_user_send_password, true); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
 247      </tr>
 248  <?php endif; ?>
 249  <?php } // !is_multisite ?>
 250      <tr class="form-field">
 251          <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
 252          <td><select name="role" id="role">
 253              <?php
 254              if ( !$new_user_role )
 255                  $new_user_role = !empty($current_role) ? $current_role : get_option('default_role');
 256              wp_dropdown_roles($new_user_role);
 257              ?>
 258              </select>
 259          </td>
 260      </tr>
 261      <?php if ( is_multisite() && is_super_admin() ) { ?>
 262      <tr>
 263          <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
 264          <td><label for="noconfirmation"><input type="checkbox" name="noconfirmation" id="noconfirmation" value="1" /> <?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
 265      </tr>
 266      <?php } ?>
 267  </table>
 268  <p class="submit">
 269      <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" />
 270  </p>
 271  </form>
 272  
 273  </div>
 274  <?php
 275  include ('./admin-footer.php');
 276  ?>


Generated: Thu Oct 14 05:11:12 2010 Cross-referenced by PHPXref 0.7