[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Add Site Administration Screen
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.1.0
   8   */
   9  
  10  /** Load WordPress Administration Bootstrap */
  11  require_once ( './admin.php' );
  12  
  13  if ( ! is_multisite() )
  14      wp_die( __( 'Multisite support is not enabled.' ) );
  15  
  16  if ( ! current_user_can( 'manage_sites' ) )
  17      wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) );
  18  
  19      get_current_screen()->add_help_tab( array(
  20          'id'      => 'overview',
  21          'title'   => __('Overview'),
  22          'content' =>
  23              '<p>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' .
  24              '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>'
  25  ) );
  26  
  27  get_current_screen()->set_help_sidebar(
  28      '<p><strong>' . __('For more information:') . '</strong></p>' .
  29      '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
  30      '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
  31  );
  32  
  33  if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
  34      check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
  35  
  36      if ( ! current_user_can( 'manage_sites' ) )
  37          wp_die( __( 'You do not have permission to access this page.' ) );
  38  
  39      if ( ! is_array( $_POST['blog'] ) )
  40          wp_die( __( 'Can&#8217;t create an empty site.' ) );
  41      $blog = $_POST['blog'];
  42      $domain = '';
  43      if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
  44          $domain = strtolower( $blog['domain'] );
  45  
  46      // If not a subdomain install, make sure the domain isn't a reserved word
  47      if ( ! is_subdomain_install() ) {
  48          $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
  49          if ( in_array( $domain, $subdirectory_reserved_names ) )
  50              wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
  51      }
  52  
  53      $email = sanitize_email( $blog['email'] );
  54      $title = $blog['title'];
  55  
  56      if ( empty( $domain ) )
  57          wp_die( __( 'Missing or invalid site address.' ) );
  58      if ( empty( $email ) )
  59          wp_die( __( 'Missing email address.' ) );
  60      if ( !is_email( $email ) )
  61          wp_die( __( 'Invalid email address.' ) );
  62  
  63      if ( is_subdomain_install() ) {
  64          $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
  65          $path = $base;
  66      } else {
  67          $newdomain = $current_site->domain;
  68          $path = $base . $domain . '/';
  69      }
  70  
  71      $password = 'N/A';
  72      $user_id = email_exists($email);
  73      if ( !$user_id ) { // Create a new user with a random password
  74          $password = wp_generate_password( 12, false );
  75          $user_id = wpmu_create_user( $domain, $password, $email );
  76          if ( false == $user_id )
  77              wp_die( __( 'There was an error creating the user.' ) );
  78          else
  79              wp_new_user_notification( $user_id, $password );
  80      }
  81  
  82      $wpdb->hide_errors();
  83      $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
  84      $wpdb->show_errors();
  85      if ( !is_wp_error( $id ) ) {
  86          if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
  87              update_user_option( $user_id, 'primary_blog', $id, true );
  88          $content_mail = sprintf( __( "New site created by %1s\n\nAddress: %2s\nName: %3s"), $current_user->user_login , get_site_url( $id ), stripslashes( $title ) );
  89          wp_mail( get_site_option('admin_email'), sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );
  90          wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
  91          wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
  92          exit;
  93      } else {
  94          wp_die( $id->get_error_message() );
  95      }
  96  }
  97  
  98  if ( isset($_GET['update']) ) {
  99      $messages = array();
 100      if ( 'added' == $_GET['update'] )
 101          $messages[] = sprintf( __( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ), esc_url( get_admin_url( absint( $_GET['id'] ) ) ), network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) ) );
 102  }
 103  
 104  $title = __('Add New Site');
 105  $parent_file = 'sites.php';
 106  
 107  require ('../admin-header.php');
 108  
 109  ?>
 110  
 111  <div class="wrap">
 112  <?php screen_icon('ms-admin'); ?>
 113  <h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
 114  <?php
 115  if ( ! empty( $messages ) ) {
 116      foreach ( $messages as $msg )
 117          echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
 118  } ?>
 119  <form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
 120  <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
 121      <table class="form-table">
 122          <tr class="form-field form-required">
 123              <th scope="row"><?php _e( 'Site Address' ) ?></th>
 124              <td>
 125              <?php if ( is_subdomain_install() ) { ?>
 126                  <input name="blog[domain]" type="text" class="regular-text" title="<?php esc_attr_e( 'Domain' ) ?>"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', $current_site->domain ); ?></span>
 127              <?php } else {
 128                  echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php esc_attr_e( 'Domain' ) ?>"/>
 129              <?php }
 130              echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
 131              ?>
 132              </td>
 133          </tr>
 134          <tr class="form-field form-required">
 135              <th scope="row"><?php _e( 'Site Title' ) ?></th>
 136              <td><input name="blog[title]" type="text" class="regular-text" title="<?php esc_attr_e( 'Title' ) ?>"/></td>
 137          </tr>
 138          <tr class="form-field form-required">
 139              <th scope="row"><?php _e( 'Admin Email' ) ?></th>
 140              <td><input name="blog[email]" type="text" class="regular-text" title="<?php esc_attr_e( 'Email' ) ?>"/></td>
 141          </tr>
 142          <tr class="form-field">
 143              <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td>
 144          </tr>
 145      </table>
 146      <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>
 147      </form>
 148  </div>
 149  <?php
 150  require ('../admin-footer.php');


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.