[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress MU 2.9.2

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  /** WordPress Registration API */
  16  require_once( ABSPATH . WPINC . '/registration.php');
  17  
  18  function admin_created_user_email( $text ) {
  19      return sprintf( __( "Hi,
  20  You've been invited to join '%s' at
  21  %s as a %s.
  22  If you do not want to join this blog please ignore
  23  this email. This invitation will expire in a few days.
  24  
  25  Please click the following link to activate your user account:
  26  %%s" ), get_bloginfo('name'), site_url(), wp_specialchars( $_REQUEST[ 'role' ] ) );
  27  }
  28  add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
  29  
  30  function admin_created_user_subject( $text ) {
  31      return "[" . get_bloginfo('name') . "] Your blog invite";
  32  }
  33  add_filter( 'wpmu_signup_user_notification_subject', 'admin_created_user_subject' );
  34  
  35  if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
  36      check_admin_referer('add-user');
  37  
  38      if ( ! current_user_can('create_users') )
  39          wp_die(__('You can&#8217;t create users.'));
  40  
  41      $user_login = preg_replace( "/\s+/", '', sanitize_user( $_REQUEST[ 'user_login' ], true ) );
  42      $user_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE user_login = %s AND user_email = %s", $user_login, $_REQUEST[ 'email' ] ) );
  43      if( $user_details ) {
  44          // Adding an existing user to this blog
  45          $new_user_email = wp_specialchars(trim($_REQUEST['email']));
  46          $redirect = 'user-new.php';
  47          $username = $user_details->user_login;
  48          $user_id = $user_details->ID;
  49          if( ($username != null && is_site_admin( $username ) == false ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
  50              $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
  51          } else {
  52              if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
  53                  add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
  54                  $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
  55              } else {
  56                  $newuser_key = substr( md5( $user_id ), 0, 5 );
  57                  add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
  58                  $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");
  59                  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/")));
  60                  $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
  61              }
  62          }
  63          wp_redirect( $redirect );
  64          die();
  65      } else {
  66          // Adding a new user to this blog
  67          $user_details = wpmu_validate_user_signup( $_REQUEST[ 'user_login' ], $_REQUEST[ 'email' ] );
  68          unset( $user_details[ 'errors' ]->errors[ 'user_email_used' ] );
  69          if ( is_wp_error( $user_details[ 'errors' ] ) && !empty( $user_details[ 'errors' ]->errors ) ) {
  70              $add_user_errors = $user_details[ 'errors' ];
  71          } else {
  72              $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
  73              if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
  74                  add_filter( 'wpmu_signup_user_notification', create_function('', '{return false;}') ); // Disable confirmation email
  75              }
  76              wpmu_signup_user( $new_user_login, $_REQUEST[ 'email' ], array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST[ 'role' ] ) );
  77              if ( isset( $_POST[ 'noconfirmation' ] ) && is_site_admin() ) {
  78                  $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' ] ) );
  79                  wpmu_activate_signup( $key );
  80                  $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
  81              } else {
  82                  $redirect = add_query_arg( array('update' => 'newuserconfimation'), 'user-new.php' );
  83              }
  84              wp_redirect( $redirect );
  85              die();
  86          }
  87      }
  88  }
  89  
  90  $title = __('Add New User');
  91  $parent_file = 'users.php';
  92  
  93  wp_enqueue_script('wp-ajax-response');
  94  wp_enqueue_script('user-profile');
  95  wp_enqueue_script('password-strength-meter');
  96  
  97  require_once  ('admin-header.php');
  98  
  99  switch( $_GET[ 'update' ] ) {
 100      case "newuserconfimation":
 101          $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.') . '</p></div>';
 102          break;
 103      case "add":
 104          $messages[] = '<div id="message" class="updated fade"><p>' . __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your blog.') . '</p></div>';
 105          break;
 106      case "addnoconfirmation":
 107          $messages[] = '<div id="message" class="updated fade"><p>' . __('User has been added to your blog.') . '</p></div>';
 108          break;
 109      case "addexisting":
 110          $messages[] = '<div id="message" class="updated fade"><p>' . __('That user is already a member of this blog.') . '</p></div>';
 111          break;
 112  }
 113  
 114  ?>
 115  <div class="wrap">
 116  <?php screen_icon(); ?>
 117  <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
 118  
 119  <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
 120      <div class="error">
 121          <ul>
 122          <?php
 123              foreach ( $errors->get_error_messages() as $err )
 124                  echo "<li>$err</li>\n";
 125          ?>
 126          </ul>
 127      </div>
 128  <?php endif;
 129  
 130  if ( ! empty($messages) ) {
 131      foreach ( $messages as $msg )
 132          echo $msg;
 133  } ?>
 134  
 135  <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?>
 136      <div class="error">
 137          <?php
 138              foreach ( $add_user_errors->get_error_messages() as $message )
 139                  echo "<p>$message</p>";
 140          ?>
 141      </div>
 142  <?php endif; ?>
 143  <div id="ajax-response"></div>
 144  
 145  <?php
 146  echo '<p>' . __( 'You can add new users to your blog 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>';
 147  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>';
 148  ?>
 149  <form action="" method="post" name="adduser" id="adduser" class="add:users: validate">
 150  <?php wp_nonce_field('add-user') ?>
 151  <?php
 152  //Load up the passed data, else set to a default.
 153  foreach ( array('user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname',
 154                  'email' => 'email', 'url' => 'uri', 'role' => 'role') as $post_field => $var ) {
 155      $var = "new_user_$var";
 156      if ( ! isset($$var) )
 157          $$var = isset($_POST[$post_field]) ? stripslashes($_POST[$post_field]) : '';
 158  }
 159  ?>
 160  <table class="form-table">
 161      <tr class="form-field form-required">
 162          <th scope="row"><label for="user_login"><?php _e('Username (required)') ?></label><input name="action" type="hidden" id="action" value="adduser" /></th>
 163          <td ><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" aria-required="true" /></td>
 164      </tr>
 165      <tr class="form-field form-required">
 166          <th scope="row"><label for="email"><?php _e('E-mail (required)') ?></label></th>
 167          <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td>
 168      </tr>
 169  
 170      <tr class="form-field">
 171          <th scope="row"><label for="role"><?php _e('Role'); ?></label></th>
 172          <td><select name="role" id="role">
 173              <?php
 174              if ( !$new_user_role )
 175                  $new_user_role = !empty($current_role) ? $current_role : get_option('default_role');
 176              wp_dropdown_roles($new_user_role);
 177              ?>
 178              </select>
 179          </td>
 180      </tr>
 181      <?php if ( is_site_admin() ) { ?>
 182      <tr class="form-field">
 183          <th scope="row"><label for="noconfirmation"><?php _e('Skip Confirmation Email') ?></label></th>
 184          <td><input name="noconfirmation" type="checkbox" id="noconfirmation" value="1" /> <label for="noconfirmation"><?php _e( 'Site administrators can add a user without sending the confirmation email.' ); ?></label></td>
 185      </tr>
 186      <?php } ?>
 187  </table>
 188  <p class="submit">
 189      <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" />
 190  </p>
 191  </form>
 192  
 193  </div>
 194  <?php
 195  include ('admin-footer.php');
 196  ?>


Generated: Mon May 3 12:25:32 2010 Cross-referenced by PHPXref 0.7