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 ( ! is_multisite() )
17 wp_die( __( 'Multisite support is not enabled.' ) );
19 if ( ! current_user_can( 'manage_sites' ) )
20 wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) );
22 get_current_screen()->add_help_tab( array(
24 'title' => __('Overview'),
26 '<p>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' .
27 '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>'
30 get_current_screen()->set_help_sidebar(
31 '<p><strong>' . __('For more information:') . '</strong></p>' .
32 '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
33 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
36 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
37 check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
39 if ( ! is_array( $_POST['blog'] ) )
40 wp_die( __( 'Can’t create an empty site.' ) );
42 $blog = $_POST['blog'];
44 if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
45 $domain = strtolower( $blog['domain'] );
47 // If not a subdomain install, make sure the domain isn't a reserved word
48 if ( ! is_subdomain_install() ) {
49 $subdirectory_reserved_names = get_subdirectory_reserved_names();
51 if ( in_array( $domain, $subdirectory_reserved_names ) ) {
53 /* translators: %s: reserved names list */
54 sprintf( __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
55 '<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
61 $title = $blog['title'];
67 // Handle translation install for the new site.
68 if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) {
69 $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
71 $meta['WPLANG'] = $language;
75 if ( empty( $domain ) )
76 wp_die( __( 'Missing or invalid site address.' ) );
78 if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
79 wp_die( __( 'Missing email address.' ) );
82 $email = sanitize_email( $blog['email'] );
83 if ( ! is_email( $email ) ) {
84 wp_die( __( 'Invalid email address.' ) );
87 if ( is_subdomain_install() ) {
88 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
89 $path = $current_site->path;
91 $newdomain = $current_site->domain;
92 $path = $current_site->path . $domain . '/';
96 $user_id = email_exists($email);
97 if ( !$user_id ) { // Create a new user with a random password
99 * Fires immediately before a new user is created via the network site-new.php page.
103 * @param string $email Email of the non-existent user.
105 do_action( 'pre_network_site_new_created_user', $email );
107 $user_id = username_exists( $domain );
109 wp_die( __( 'The domain or path entered conflicts with an existing username.' ) );
111 $password = wp_generate_password( 12, false );
112 $user_id = wpmu_create_user( $domain, $password, $email );
113 if ( false === $user_id ) {
114 wp_die( __( 'There was an error creating the user.' ) );
118 * Fires after a new user has been created via the network site-new.php page.
122 * @param int $user_id ID of the newly created user.
124 do_action( 'network_site_new_created_user', $user_id );
127 $wpdb->hide_errors();
128 $id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, $current_site->id );
129 $wpdb->show_errors();
130 if ( ! is_wp_error( $id ) ) {
131 if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
132 update_user_option( $user_id, 'primary_blog', $id, true );
136 get_site_option( 'admin_email' ),
138 /* translators: %s: network name */
139 __( '[%s] New Site Created' ),
140 $current_site->site_name
143 /* translators: 1: user login, 2: site url, 3: site name/title */
144 __( 'New site created by %1$s
148 $current_user->user_login,
153 'From: "%1$s" <%2$s>',
154 _x( 'Site Admin', 'email "From" field' ),
155 get_site_option( 'admin_email' )
158 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
159 wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
162 wp_die( $id->get_error_message() );
166 if ( isset($_GET['update']) ) {
168 if ( 'added' == $_GET['update'] )
169 $messages[] = sprintf(
170 /* translators: 1: dashboard url, 2: network admin edit url */
171 __( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
172 esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
173 network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
177 $title = __('Add New Site');
178 $parent_file = 'sites.php';
180 wp_enqueue_script( 'user-suggest' );
182 require( ABSPATH . 'wp-admin/admin-header.php' );
187 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
189 if ( ! empty( $messages ) ) {
190 foreach ( $messages as $msg )
191 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
193 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
194 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
195 <table class="form-table">
196 <tr class="form-field form-required">
197 <th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ) ?></label></th>
199 <?php if ( is_subdomain_install() ) { ?>
200 <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\.|', '', $current_site->domain ); ?></span>
202 echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" />
204 echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
208 <tr class="form-field form-required">
209 <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th>
210 <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td>
213 $languages = get_available_languages();
214 $translations = wp_get_available_translations();
215 if ( ! empty( $languages ) || ! empty( $translations ) ) :
217 <tr class="form-field form-required">
218 <th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th>
222 $lang = get_site_option( 'WPLANG' );
224 // Use English if the default isn't available.
225 if ( ! in_array( $lang, $languages ) ) {
229 wp_dropdown_languages( array(
231 'id' => 'site-language',
233 'languages' => $languages,
234 'translations' => $translations,
235 'show_available_translations' => wp_can_install_language_pack(),
240 <?php endif; // Languages. ?>
241 <tr class="form-field form-required">
242 <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></th>
243 <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>
245 <tr class="form-field">
246 <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>
252 * Fires at the end of the new site form in network admin.
256 do_action( 'network_site_new_form' );
258 submit_button( __( 'Add Site' ), 'primary', 'add-site' );
263 require( ABSPATH . 'wp-admin/admin-footer.php' );