wp/wp-admin/network/site-new.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     6  * @subpackage Multisite
     6  * @subpackage Multisite
     7  * @since 3.1.0
     7  * @since 3.1.0
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once __DIR__ . '/admin.php';
    12 
    12 
    13 /** WordPress Translation Installation API */
    13 /** WordPress Translation Installation API */
    14 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    14 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    15 
    15 
    16 if ( ! current_user_can( 'create_sites' ) ) {
    16 if ( ! current_user_can( 'create_sites' ) ) {
    17 	wp_die( __( 'Sorry, you are not allowed to add sites to this network.' ) );
    17 	wp_die( __( 'Sorry, you are not allowed to add sites to this network.' ) );
    18 }
    18 }
    19 
    19 
    27 	)
    27 	)
    28 );
    28 );
    29 
    29 
    30 get_current_screen()->set_help_sidebar(
    30 get_current_screen()->set_help_sidebar(
    31 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    31 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    32 	'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>' ) . '</p>' .
    32 	'<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
    33 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    33 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    34 );
    34 );
    35 
    35 
    36 if ( isset( $_REQUEST['action'] ) && 'add-site' == $_REQUEST['action'] ) {
    36 if ( isset( $_REQUEST['action'] ) && 'add-site' === $_REQUEST['action'] ) {
    37 	check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    37 	check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    38 
    38 
    39 	if ( ! is_array( $_POST['blog'] ) ) {
    39 	if ( ! is_array( $_POST['blog'] ) ) {
    40 		wp_die( __( 'Can&#8217;t create an empty site.' ) );
    40 		wp_die( __( 'Can&#8217;t create an empty site.' ) );
    41 	}
    41 	}
    42 
    42 
    43 	$blog   = $_POST['blog'];
    43 	$blog   = $_POST['blog'];
    44 	$domain = '';
    44 	$domain = '';
       
    45 
       
    46 	$blog['domain'] = trim( $blog['domain'] );
    45 	if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) {
    47 	if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) {
    46 		$domain = strtolower( $blog['domain'] );
    48 		$domain = strtolower( $blog['domain'] );
    47 	}
    49 	}
    48 
    50 
    49 	// If not a subdomain installation, make sure the domain isn't a reserved word
    51 	// If not a subdomain installation, make sure the domain isn't a reserved word.
    50 	if ( ! is_subdomain_install() ) {
    52 	if ( ! is_subdomain_install() ) {
    51 		$subdirectory_reserved_names = get_subdirectory_reserved_names();
    53 		$subdirectory_reserved_names = get_subdirectory_reserved_names();
    52 
    54 
    53 		if ( in_array( $domain, $subdirectory_reserved_names ) ) {
    55 		if ( in_array( $domain, $subdirectory_reserved_names, true ) ) {
    54 			wp_die(
    56 			wp_die(
    55 				/* translators: %s: reserved names list */
       
    56 				sprintf(
    57 				sprintf(
       
    58 					/* translators: %s: Reserved names list. */
    57 					__( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
    59 					__( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
    58 					'<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
    60 					'<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
    59 				)
    61 				)
    60 			);
    62 			);
    61 		}
    63 		}
    69 
    71 
    70 	// Handle translation installation for the new site.
    72 	// Handle translation installation for the new site.
    71 	if ( isset( $_POST['WPLANG'] ) ) {
    73 	if ( isset( $_POST['WPLANG'] ) ) {
    72 		if ( '' === $_POST['WPLANG'] ) {
    74 		if ( '' === $_POST['WPLANG'] ) {
    73 			$meta['WPLANG'] = ''; // en_US
    75 			$meta['WPLANG'] = ''; // en_US
    74 		} elseif ( in_array( $_POST['WPLANG'], get_available_languages() ) ) {
    76 		} elseif ( in_array( $_POST['WPLANG'], get_available_languages(), true ) ) {
    75 			$meta['WPLANG'] = $_POST['WPLANG'];
    77 			$meta['WPLANG'] = $_POST['WPLANG'];
    76 		} elseif ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
    78 		} elseif ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
    77 			$language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
    79 			$language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
    78 			if ( $language ) {
    80 			if ( $language ) {
    79 				$meta['WPLANG'] = $language;
    81 				$meta['WPLANG'] = $language;
   102 		$path      = get_network()->path . $domain . '/';
   104 		$path      = get_network()->path . $domain . '/';
   103 	}
   105 	}
   104 
   106 
   105 	$password = 'N/A';
   107 	$password = 'N/A';
   106 	$user_id  = email_exists( $email );
   108 	$user_id  = email_exists( $email );
   107 	if ( ! $user_id ) { // Create a new user with a random password
   109 	if ( ! $user_id ) { // Create a new user with a random password.
   108 		/**
   110 		/**
   109 		 * Fires immediately before a new user is created via the network site-new.php page.
   111 		 * Fires immediately before a new user is created via the network site-new.php page.
   110 		 *
   112 		 *
   111 		 * @since 4.5.0
   113 		 * @since 4.5.0
   112 		 *
   114 		 *
   135 	}
   137 	}
   136 
   138 
   137 	$wpdb->hide_errors();
   139 	$wpdb->hide_errors();
   138 	$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
   140 	$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
   139 	$wpdb->show_errors();
   141 	$wpdb->show_errors();
       
   142 
   140 	if ( ! is_wp_error( $id ) ) {
   143 	if ( ! is_wp_error( $id ) ) {
   141 		if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) {
   144 		if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) {
   142 			update_user_option( $user_id, 'primary_blog', $id, true );
   145 			update_user_option( $user_id, 'primary_blog', $id, true );
   143 		}
   146 		}
   144 
   147 
   145 		wp_mail(
   148 		wp_mail(
   146 			get_site_option( 'admin_email' ),
   149 			get_site_option( 'admin_email' ),
   147 			sprintf(
   150 			sprintf(
   148 				/* translators: %s: network name */
   151 				/* translators: New site notification email subject. %s: Network title. */
   149 				__( '[%s] New Site Created' ),
   152 				__( '[%s] New Site Created' ),
   150 				get_network()->site_name
   153 				get_network()->site_name
   151 			),
   154 			),
   152 			sprintf(
   155 			sprintf(
   153 				/* translators: 1: user login, 2: site url, 3: site name/title */
   156 				/* translators: New site notification email. 1: User login, 2: Site URL, 3: Site title. */
   154 				__(
   157 				__(
   155 					'New site created by %1$s
   158 					'New site created by %1$s
   156 
   159 
   157 Address: %2$s
   160 Address: %2$s
   158 Name: %3$s'
   161 Name: %3$s'
   183 	}
   186 	}
   184 }
   187 }
   185 
   188 
   186 if ( isset( $_GET['update'] ) ) {
   189 if ( isset( $_GET['update'] ) ) {
   187 	$messages = array();
   190 	$messages = array();
   188 	if ( 'added' == $_GET['update'] ) {
   191 	if ( 'added' === $_GET['update'] ) {
   189 		$messages[] = sprintf(
   192 		$messages[] = sprintf(
   190 			/* translators: 1: dashboard url, 2: network admin edit url */
   193 			/* translators: 1: Dashboard URL, 2: Network admin edit URL. */
   191 			__( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
   194 			__( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
   192 			esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
   195 			esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
   193 			network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
   196 			network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
   194 		);
   197 		);
   195 	}
   198 	}
   198 $title       = __( 'Add New Site' );
   201 $title       = __( 'Add New Site' );
   199 $parent_file = 'sites.php';
   202 $parent_file = 'sites.php';
   200 
   203 
   201 wp_enqueue_script( 'user-suggest' );
   204 wp_enqueue_script( 'user-suggest' );
   202 
   205 
   203 require( ABSPATH . 'wp-admin/admin-header.php' );
   206 require_once ABSPATH . 'wp-admin/admin-header.php';
   204 
   207 
   205 ?>
   208 ?>
   206 
   209 
   207 <div class="wrap">
   210 <div class="wrap">
   208 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
   211 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
   214 }
   217 }
   215 ?>
   218 ?>
   216 <p>
   219 <p>
   217 <?php
   220 <?php
   218 printf(
   221 printf(
   219 	/* translators: %s: asterisk to mark required form fields. */
   222 	/* translators: %s: Asterisk symbol (*). */
   220 	__( 'Required fields are marked %s' ),
   223 	__( 'Required fields are marked %s' ),
   221 	'<span class="required">*</span>'
   224 	'<span class="required">*</span>'
   222 );
   225 );
   223 ?>
   226 ?>
   224 </p>
   227 </p>
   227 	<table class="form-table" role="presentation">
   230 	<table class="form-table" role="presentation">
   228 		<tr class="form-field form-required">
   231 		<tr class="form-field form-required">
   229 			<th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ); ?> <span class="required">*</span></label></th>
   232 			<th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ); ?> <span class="required">*</span></label></th>
   230 			<td>
   233 			<td>
   231 			<?php if ( is_subdomain_install() ) { ?>
   234 			<?php if ( is_subdomain_install() ) { ?>
   232 				<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required /><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
   235 				<input name="blog[domain]" type="text" class="regular-text ltr" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required /><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
   233 				<?php
   236 				<?php
   234 			} else {
   237 			} else {
   235 				echo get_network()->domain . get_network()->path
   238 				echo get_network()->domain . get_network()->path
   236 				?>
   239 				?>
   237 				<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required />
   240 				<input name="blog[domain]" type="text" class="regular-text ltr" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required />
   238 				<?php
   241 				<?php
   239 			}
   242 			}
   240 			echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
   243 			echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
   241 			?>
   244 			?>
   242 			</td>
   245 			</td>
   256 					<?php
   259 					<?php
   257 					// Network default.
   260 					// Network default.
   258 					$lang = get_site_option( 'WPLANG' );
   261 					$lang = get_site_option( 'WPLANG' );
   259 
   262 
   260 					// Use English if the default isn't available.
   263 					// Use English if the default isn't available.
   261 					if ( ! in_array( $lang, $languages ) ) {
   264 					if ( ! in_array( $lang, $languages, true ) ) {
   262 						$lang = '';
   265 						$lang = '';
   263 					}
   266 					}
   264 
   267 
   265 					wp_dropdown_languages(
   268 					wp_dropdown_languages(
   266 						array(
   269 						array(
   296 	submit_button( __( 'Add Site' ), 'primary', 'add-site' );
   299 	submit_button( __( 'Add Site' ), 'primary', 'add-site' );
   297 	?>
   300 	?>
   298 	</form>
   301 	</form>
   299 </div>
   302 </div>
   300 <?php
   303 <?php
   301 require( ABSPATH . 'wp-admin/admin-footer.php' );
   304 require_once ABSPATH . 'wp-admin/admin-footer.php';