[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Add New User network administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.1.0
   8   */
   9  
  10  /** Load WordPress Administration Bootstrap */
  11  require_once( dirname( __FILE__ ) . '/admin.php' );
  12  
  13  if ( ! current_user_can( 'create_users' ) ) {
  14      wp_die( __( 'Sorry, you are not allowed to add users to this network.' ) );
  15  }
  16  
  17  get_current_screen()->add_help_tab(
  18      array(
  19          'id'      => 'overview',
  20          'title'   => __( 'Overview' ),
  21          'content' =>
  22              '<p>' . __( 'Add User will set up a new user account on the network and send that person an email with username and password.' ) . '</p>' .
  23              '<p>' . __( 'Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.' ) . '</p>',
  24      )
  25  );
  26  
  27  get_current_screen()->set_help_sidebar(
  28      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  29      '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
  30      '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
  31  );
  32  
  33  if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) {
  34      check_admin_referer( 'add-user', '_wpnonce_add-user' );
  35  
  36      if ( ! current_user_can( 'manage_network_users' ) ) {
  37          wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  38      }
  39  
  40      if ( ! is_array( $_POST['user'] ) ) {
  41          wp_die( __( 'Cannot create an empty user.' ) );
  42      }
  43  
  44      $user = wp_unslash( $_POST['user'] );
  45  
  46      $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
  47      if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) {
  48          $add_user_errors = $user_details['errors'];
  49      } else {
  50          $password = wp_generate_password( 12, false );
  51          $user_id  = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) );
  52  
  53          if ( ! $user_id ) {
  54              $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
  55          } else {
  56              /**
  57               * Fires after a new user has been created via the network user-new.php page.
  58               *
  59               * @since 4.4.0
  60               *
  61               * @param int $user_id ID of the newly created user.
  62               */
  63              do_action( 'network_user_new_created_user', $user_id );
  64              wp_redirect(
  65                  add_query_arg(
  66                      array(
  67                          'update'  => 'added',
  68                          'user_id' => $user_id,
  69                      ),
  70                      'user-new.php'
  71                  )
  72              );
  73              exit;
  74          }
  75      }
  76  }
  77  
  78  if ( isset( $_GET['update'] ) ) {
  79      $messages = array();
  80      if ( 'added' == $_GET['update'] ) {
  81          $edit_link = '';
  82          if ( isset( $_GET['user_id'] ) ) {
  83              $user_id_new = absint( $_GET['user_id'] );
  84              if ( $user_id_new ) {
  85                  $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) );
  86              }
  87          }
  88  
  89          $message = __( 'User added.' );
  90  
  91          if ( $edit_link ) {
  92              $message .= sprintf(
  93                  ' <a href="%s">%s</a>',
  94                  $edit_link,
  95                  __( 'Edit user' )
  96              );
  97          }
  98  
  99          $messages[] = $message;
 100      }
 101  }
 102  
 103  $title       = __( 'Add New User' );
 104  $parent_file = 'users.php';
 105  
 106  require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
 107  
 108  <div class="wrap">
 109  <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1>
 110  <?php
 111  if ( ! empty( $messages ) ) {
 112      foreach ( $messages as $msg ) {
 113          echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
 114      }
 115  }
 116  
 117  if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) {
 118      ?>
 119      <div class="error">
 120          <?php
 121          foreach ( $add_user_errors->get_error_messages() as $message ) {
 122              echo "<p>$message</p>";
 123          }
 124          ?>
 125      </div>
 126  <?php } ?>
 127      <form action="<?php echo network_admin_url( 'user-new.php?action=add-user' ); ?>" id="adduser" method="post" novalidate="novalidate">
 128      <table class="form-table" role="presentation">
 129          <tr class="form-field form-required">
 130              <th scope="row"><label for="username"><?php _e( 'Username' ); ?></label></th>
 131              <td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" /></td>
 132          </tr>
 133          <tr class="form-field form-required">
 134              <th scope="row"><label for="email"><?php _e( 'Email' ); ?></label></th>
 135              <td><input type="email" class="regular-text" name="user[email]" id="email"/></td>
 136          </tr>
 137          <tr class="form-field">
 138              <td colspan="2" class="td-full"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></td>
 139          </tr>
 140      </table>
 141      <?php
 142      /**
 143       * Fires at the end of the new user form in network admin.
 144       *
 145       * @since 4.5.0
 146       */
 147      do_action( 'network_user_new_form' );
 148  
 149      wp_nonce_field( 'add-user', '_wpnonce_add-user' );
 150      submit_button( __( 'Add User' ), 'primary', 'add-user' );
 151      ?>
 152      </form>
 153  </div>
 154  <?php
 155  require( ABSPATH . 'wp-admin/admin-footer.php' );


Generated: Wed Jul 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1