3 * Add Site Administration Screen
6 * @subpackage Multisite
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
13 /** WordPress Translation Install API */
14 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
16 if ( ! current_user_can( 'manage_sites' ) )
17 wp_die( __( 'Sorry, you are not allowed to add sites to this network.' ) );
19 get_current_screen()->add_help_tab( array(
21 'title' => __('Overview'),
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>'
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_Sites_Screen">Documentation on Site Management</a>') . '</p>' .
30 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
33 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
34 check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
36 if ( ! is_array( $_POST['blog'] ) )
37 wp_die( __( 'Can’t create an empty site.' ) );
39 $blog = $_POST['blog'];
41 if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
42 $domain = strtolower( $blog['domain'] );
44 // If not a subdomain install, make sure the domain isn't a reserved word
45 if ( ! is_subdomain_install() ) {
46 $subdirectory_reserved_names = get_subdirectory_reserved_names();
48 if ( in_array( $domain, $subdirectory_reserved_names ) ) {
50 /* translators: %s: reserved names list */
51 sprintf( __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
52 '<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
58 $title = $blog['title'];
64 // Handle translation install for the new site.
65 if ( isset( $_POST['WPLANG'] ) ) {
66 if ( '' === $_POST['WPLANG'] ) {
67 $meta['WPLANG'] = ''; // en_US
68 } elseif ( wp_can_install_language_pack() ) {
69 $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
71 $meta['WPLANG'] = $language;
76 if ( empty( $domain ) )
77 wp_die( __( 'Missing or invalid site address.' ) );
79 if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
80 wp_die( __( 'Missing email address.' ) );
83 $email = sanitize_email( $blog['email'] );
84 if ( ! is_email( $email ) ) {
85 wp_die( __( 'Invalid email address.' ) );
88 if ( is_subdomain_install() ) {
89 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', get_network()->domain );
90 $path = get_network()->path;
92 $newdomain = get_network()->domain;
93 $path = get_network()->path . $domain . '/';
97 $user_id = email_exists($email);
98 if ( !$user_id ) { // Create a new user with a random password
100 * Fires immediately before a new user is created via the network site-new.php page.
104 * @param string $email Email of the non-existent user.
106 do_action( 'pre_network_site_new_created_user', $email );
108 $user_id = username_exists( $domain );
110 wp_die( __( 'The domain or path entered conflicts with an existing username.' ) );
112 $password = wp_generate_password( 12, false );
113 $user_id = wpmu_create_user( $domain, $password, $email );
114 if ( false === $user_id ) {
115 wp_die( __( 'There was an error creating the user.' ) );
119 * Fires after a new user has been created via the network site-new.php page.
123 * @param int $user_id ID of the newly created user.
125 do_action( 'network_site_new_created_user', $user_id );
128 $wpdb->hide_errors();
129 $id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
130 $wpdb->show_errors();
131 if ( ! is_wp_error( $id ) ) {
132 if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
133 update_user_option( $user_id, 'primary_blog', $id, true );
137 get_site_option( 'admin_email' ),
139 /* translators: %s: network name */
140 __( '[%s] New Site Created' ),
141 get_network()->site_name
144 /* translators: 1: user login, 2: site url, 3: site name/title */
145 __( 'New site created by %1$s
149 $current_user->user_login,
154 'From: "%1$s" <%2$s>',
155 _x( 'Site Admin', 'email "From" field' ),
156 get_site_option( 'admin_email' )
159 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
160 wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
163 wp_die( $id->get_error_message() );
167 if ( isset($_GET['update']) ) {
169 if ( 'added' == $_GET['update'] )
170 $messages[] = sprintf(
171 /* translators: 1: dashboard url, 2: network admin edit url */
172 __( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
173 esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
174 network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
178 $title = __('Add New Site');
179 $parent_file = 'sites.php';
181 wp_enqueue_script( 'user-suggest' );
183 require( ABSPATH . 'wp-admin/admin-header.php' );
188 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
190 if ( ! empty( $messages ) ) {
191 foreach ( $messages as $msg )
192 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
194 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
195 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
196 <table class="form-table">
197 <tr class="form-field form-required">
198 <th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ) ?></label></th>
200 <?php if ( is_subdomain_install() ) { ?>
201 <input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
203 echo get_network()->domain . get_network()->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" />
205 echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
209 <tr class="form-field form-required">
210 <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th>
211 <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td>
214 $languages = get_available_languages();
215 $translations = wp_get_available_translations();
216 if ( ! empty( $languages ) || ! empty( $translations ) ) :
218 <tr class="form-field form-required">
219 <th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th>
223 $lang = get_site_option( 'WPLANG' );
225 // Use English if the default isn't available.
226 if ( ! in_array( $lang, $languages ) ) {
230 wp_dropdown_languages( array(
232 'id' => 'site-language',
234 'languages' => $languages,
235 'translations' => $translations,
236 'show_available_translations' => wp_can_install_language_pack(),
241 <?php endif; // Languages. ?>
242 <tr class="form-field form-required">
243 <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></th>
244 <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>
246 <tr class="form-field">
247 <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>
253 * Fires at the end of the new site form in network admin.
257 do_action( 'network_site_new_form' );
259 submit_button( __( 'Add Site' ), 'primary', 'add-site' );
264 require( ABSPATH . 'wp-admin/admin-footer.php' );