wp/wp-admin/network/site-new.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    24 			'<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</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 ) );
    25 ) );
    26 
    26 
    27 get_current_screen()->set_help_sidebar(
    27 get_current_screen()->set_help_sidebar(
    28 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    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>' .
    29 	'<p>' . __('<a href="https://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>'
    30 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
    31 );
    31 );
    32 
    32 
    33 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
    33 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
    34 	check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    34 	check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    35 
    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'] ) )
    36 	if ( ! is_array( $_POST['blog'] ) )
    40 		wp_die( __( 'Can&#8217;t create an empty site.' ) );
    37 		wp_die( __( 'Can&#8217;t create an empty site.' ) );
       
    38 
    41 	$blog = $_POST['blog'];
    39 	$blog = $_POST['blog'];
    42 	$domain = '';
    40 	$domain = '';
    43 	if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
    41 	if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
    44 		$domain = strtolower( $blog['domain'] );
    42 		$domain = strtolower( $blog['domain'] );
    45 
    43 
    46 	// If not a subdomain install, make sure the domain isn't a reserved word
    44 	// If not a subdomain install, make sure the domain isn't a reserved word
    47 	if ( ! is_subdomain_install() ) {
    45 	if ( ! is_subdomain_install() ) {
       
    46 		/** This filter is documented in wp-includes/ms-functions.php */
    48 		$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
    47 		$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
    49 		if ( in_array( $domain, $subdirectory_reserved_names ) )
    48 		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 ) ) );
    49 			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 	}
    50 	}
    52 
    51 
    53 	$email = sanitize_email( $blog['email'] );
       
    54 	$title = $blog['title'];
    52 	$title = $blog['title'];
    55 
    53 
    56 	if ( empty( $domain ) )
    54 	if ( empty( $domain ) )
    57 		wp_die( __( 'Missing or invalid site address.' ) );
    55 		wp_die( __( 'Missing or invalid site address.' ) );
    58 	if ( empty( $email ) )
    56 
       
    57 	if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
    59 		wp_die( __( 'Missing email address.' ) );
    58 		wp_die( __( 'Missing email address.' ) );
    60 	if ( !is_email( $email ) )
    59 	}
       
    60 
       
    61 	$email = sanitize_email( $blog['email'] );
       
    62 	if ( ! is_email( $email ) ) {
    61 		wp_die( __( 'Invalid email address.' ) );
    63 		wp_die( __( 'Invalid email address.' ) );
       
    64 	}
    62 
    65 
    63 	if ( is_subdomain_install() ) {
    66 	if ( is_subdomain_install() ) {
    64 		$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    67 		$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    65 		$path      = $current_site->path;
    68 		$path      = $current_site->path;
    66 	} else {
    69 	} else {
    80 	}
    83 	}
    81 
    84 
    82 	$wpdb->hide_errors();
    85 	$wpdb->hide_errors();
    83 	$id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
    86 	$id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
    84 	$wpdb->show_errors();
    87 	$wpdb->show_errors();
    85 	if ( !is_wp_error( $id ) ) {
    88 	if ( ! is_wp_error( $id ) ) {
    86 		if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
    89 		if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
    87 			update_user_option( $user_id, 'primary_blog', $id, true );
    90 			update_user_option( $user_id, 'primary_blog', $id, true );
    88 		$content_mail = sprintf( __( 'New site created by %1$s
    91 		}
       
    92 
       
    93 		$content_mail = sprintf(
       
    94 			/* translators: 1: user login, 2: site url, 3: site name/title */
       
    95 			__( 'New site created by %1$s
    89 
    96 
    90 Address: %2$s
    97 Address: %2$s
    91 Name: %3$s' ), $current_user->user_login , get_site_url( $id ), wp_unslash( $title ) );
    98 Name: %3$s' ),
       
    99 			$current_user->user_login,
       
   100 			get_site_url( $id ),
       
   101 			wp_unslash( $title )
       
   102 		);
    92 		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' ) . '>' );
   103 		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' ) . '>' );
    93 		wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
   104 		wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
    94 		wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
   105 		wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
    95 		exit;
   106 		exit;
    96 	} else {
   107 	} else {
    99 }
   110 }
   100 
   111 
   101 if ( isset($_GET['update']) ) {
   112 if ( isset($_GET['update']) ) {
   102 	$messages = array();
   113 	$messages = array();
   103 	if ( 'added' == $_GET['update'] )
   114 	if ( 'added' == $_GET['update'] )
   104 		$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'] ) ) );
   115 		$messages[] = sprintf(
       
   116 			/* translators: 1: dashboard url, 2: network admin edit url */
       
   117 			__( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
       
   118 			esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
       
   119 			network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
       
   120 		);
   105 }
   121 }
   106 
   122 
   107 $title = __('Add New Site');
   123 $title = __('Add New Site');
   108 $parent_file = 'sites.php';
   124 $parent_file = 'sites.php';
       
   125 
       
   126 wp_enqueue_script( 'user-suggest' );
   109 
   127 
   110 require( ABSPATH . 'wp-admin/admin-header.php' );
   128 require( ABSPATH . 'wp-admin/admin-header.php' );
   111 
   129 
   112 ?>
   130 ?>
   113 
   131 
   114 <div class="wrap">
   132 <div class="wrap">
   115 <?php screen_icon('ms-admin'); ?>
       
   116 <h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
   133 <h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
   117 <?php
   134 <?php
   118 if ( ! empty( $messages ) ) {
   135 if ( ! empty( $messages ) ) {
   119 	foreach ( $messages as $msg )
   136 	foreach ( $messages as $msg )
   120 		echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
   137 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   121 } ?>
   138 } ?>
   122 <form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
   139 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
   123 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
   140 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
   124 	<table class="form-table">
   141 	<table class="form-table">
   125 		<tr class="form-field form-required">
   142 		<tr class="form-field form-required">
   126 			<th scope="row"><?php _e( 'Site Address' ) ?></th>
   143 			<th scope="row"><label for="site-address"><?php _e( 'Site Address' ) ?></label></th>
   127 			<td>
   144 			<td>
   128 			<?php if ( is_subdomain_install() ) { ?>
   145 			<?php if ( is_subdomain_install() ) { ?>
   129 				<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>
   146 				<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" /><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', $current_site->domain ); ?></span>
   130 			<?php } else {
   147 			<?php } else {
   131 				echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php esc_attr_e( 'Domain' ) ?>"/>
   148 				echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" />
   132 			<?php }
   149 			<?php }
   133 			echo '<p>' . __( 'Only lowercase letters (a-z) and numbers are allowed.' ) . '</p>';
   150 			echo '<p id="site-address-desc">' . __( 'Only lowercase letters (a-z) and numbers are allowed.' ) . '</p>';
   134 			?>
   151 			?>
   135 			</td>
   152 			</td>
   136 		</tr>
   153 		</tr>
   137 		<tr class="form-field form-required">
   154 		<tr class="form-field form-required">
   138 			<th scope="row"><?php _e( 'Site Title' ) ?></th>
   155 			<th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th>
   139 			<td><input name="blog[title]" type="text" class="regular-text" title="<?php esc_attr_e( 'Title' ) ?>"/></td>
   156 			<td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td>
   140 		</tr>
   157 		</tr>
   141 		<tr class="form-field form-required">
   158 		<tr class="form-field form-required">
   142 			<th scope="row"><?php _e( 'Admin Email' ) ?></th>
   159 			<th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></td>
   143 			<td><input name="blog[email]" type="text" class="regular-text" title="<?php esc_attr_e( 'Email' ) ?>"/></td>
   160 			<td><input name="blog[email]" type="email" class="regular-text wp-suggest-user" id="admin-email" data-autocomplete-type="search" data-autocomplete-field="user_email" /></td>
   144 		</tr>
   161 		</tr>
   145 		<tr class="form-field">
   162 		<tr class="form-field">
   146 			<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>
   163 			<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>
   147 		</tr>
   164 		</tr>
   148 	</table>
   165 	</table>