8 */ |
8 */ |
9 |
9 |
10 /** Load WordPress Administration Bootstrap */ |
10 /** Load WordPress Administration Bootstrap */ |
11 require_once( dirname( __FILE__ ) . '/admin.php' ); |
11 require_once( dirname( __FILE__ ) . '/admin.php' ); |
12 |
12 |
13 if ( ! is_multisite() ) |
13 /** WordPress Translation Installation API */ |
14 wp_die( __( 'Multisite support is not enabled.' ) ); |
14 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
15 |
15 |
16 if ( ! current_user_can( 'manage_sites' ) ) |
16 if ( ! current_user_can( 'create_sites' ) ) { |
17 wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) ); |
17 wp_die( __( 'Sorry, you are not allowed to add sites to this network.' ) ); |
18 |
18 } |
19 get_current_screen()->add_help_tab( array( |
19 |
20 'id' => 'overview', |
20 get_current_screen()->add_help_tab( array( |
21 'title' => __('Overview'), |
21 'id' => 'overview', |
22 'content' => |
22 '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>' . |
23 'content' => |
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>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' . |
|
25 '<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 ) ); |
26 |
27 |
27 get_current_screen()->set_help_sidebar( |
28 get_current_screen()->set_help_sidebar( |
28 '<p><strong>' . __('For more information:') . '</strong></p>' . |
29 '<p><strong>' . __('For more information:') . '</strong></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="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>') . '</p>' . |
30 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' |
31 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>' |
31 ); |
32 ); |
32 |
33 |
33 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { |
34 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { |
34 check_admin_referer( 'add-blog', '_wpnonce_add-blog' ); |
35 check_admin_referer( 'add-blog', '_wpnonce_add-blog' ); |
35 |
36 |
39 $blog = $_POST['blog']; |
40 $blog = $_POST['blog']; |
40 $domain = ''; |
41 $domain = ''; |
41 if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) |
42 if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) |
42 $domain = strtolower( $blog['domain'] ); |
43 $domain = strtolower( $blog['domain'] ); |
43 |
44 |
44 // If not a subdomain install, make sure the domain isn't a reserved word |
45 // If not a subdomain installation, make sure the domain isn't a reserved word |
45 if ( ! is_subdomain_install() ) { |
46 if ( ! is_subdomain_install() ) { |
46 /** This filter is documented in wp-includes/ms-functions.php */ |
47 $subdirectory_reserved_names = get_subdirectory_reserved_names(); |
47 $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) ); |
48 |
48 if ( in_array( $domain, $subdirectory_reserved_names ) ) |
49 if ( in_array( $domain, $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 ) ) ); |
50 wp_die( |
|
51 /* translators: %s: reserved names list */ |
|
52 sprintf( __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ), |
|
53 '<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>' |
|
54 ) |
|
55 ); |
|
56 } |
50 } |
57 } |
51 |
58 |
52 $title = $blog['title']; |
59 $title = $blog['title']; |
|
60 |
|
61 $meta = array( |
|
62 'public' => 1 |
|
63 ); |
|
64 |
|
65 // Handle translation installation for the new site. |
|
66 if ( isset( $_POST['WPLANG'] ) ) { |
|
67 if ( '' === $_POST['WPLANG'] ) { |
|
68 $meta['WPLANG'] = ''; // en_US |
|
69 } elseif ( in_array( $_POST['WPLANG'], get_available_languages() ) ) { |
|
70 $meta['WPLANG'] = $_POST['WPLANG']; |
|
71 } elseif ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) { |
|
72 $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) ); |
|
73 if ( $language ) { |
|
74 $meta['WPLANG'] = $language; |
|
75 } |
|
76 } |
|
77 } |
53 |
78 |
54 if ( empty( $domain ) ) |
79 if ( empty( $domain ) ) |
55 wp_die( __( 'Missing or invalid site address.' ) ); |
80 wp_die( __( 'Missing or invalid site address.' ) ); |
56 |
81 |
57 if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) { |
82 if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) { |
62 if ( ! is_email( $email ) ) { |
87 if ( ! is_email( $email ) ) { |
63 wp_die( __( 'Invalid email address.' ) ); |
88 wp_die( __( 'Invalid email address.' ) ); |
64 } |
89 } |
65 |
90 |
66 if ( is_subdomain_install() ) { |
91 if ( is_subdomain_install() ) { |
67 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); |
92 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', get_network()->domain ); |
68 $path = $current_site->path; |
93 $path = get_network()->path; |
69 } else { |
94 } else { |
70 $newdomain = $current_site->domain; |
95 $newdomain = get_network()->domain; |
71 $path = $current_site->path . $domain . '/'; |
96 $path = get_network()->path . $domain . '/'; |
72 } |
97 } |
73 |
98 |
74 $password = 'N/A'; |
99 $password = 'N/A'; |
75 $user_id = email_exists($email); |
100 $user_id = email_exists($email); |
76 if ( !$user_id ) { // Create a new user with a random password |
101 if ( !$user_id ) { // Create a new user with a random password |
|
102 /** |
|
103 * Fires immediately before a new user is created via the network site-new.php page. |
|
104 * |
|
105 * @since 4.5.0 |
|
106 * |
|
107 * @param string $email Email of the non-existent user. |
|
108 */ |
|
109 do_action( 'pre_network_site_new_created_user', $email ); |
|
110 |
|
111 $user_id = username_exists( $domain ); |
|
112 if ( $user_id ) { |
|
113 wp_die( __( 'The domain or path entered conflicts with an existing username.' ) ); |
|
114 } |
77 $password = wp_generate_password( 12, false ); |
115 $password = wp_generate_password( 12, false ); |
78 $user_id = wpmu_create_user( $domain, $password, $email ); |
116 $user_id = wpmu_create_user( $domain, $password, $email ); |
79 if ( false == $user_id ) |
117 if ( false === $user_id ) { |
80 wp_die( __( 'There was an error creating the user.' ) ); |
118 wp_die( __( 'There was an error creating the user.' ) ); |
81 else |
119 } |
82 wp_new_user_notification( $user_id, $password ); |
120 |
|
121 /** |
|
122 * Fires after a new user has been created via the network site-new.php page. |
|
123 * |
|
124 * @since 4.4.0 |
|
125 * |
|
126 * @param int $user_id ID of the newly created user. |
|
127 */ |
|
128 do_action( 'network_site_new_created_user', $user_id ); |
83 } |
129 } |
84 |
130 |
85 $wpdb->hide_errors(); |
131 $wpdb->hide_errors(); |
86 $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id ); |
132 $id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() ); |
87 $wpdb->show_errors(); |
133 $wpdb->show_errors(); |
88 if ( ! is_wp_error( $id ) ) { |
134 if ( ! is_wp_error( $id ) ) { |
89 if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) { |
135 if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) { |
90 update_user_option( $user_id, 'primary_blog', $id, true ); |
136 update_user_option( $user_id, 'primary_blog', $id, true ); |
91 } |
137 } |
92 |
138 |
93 $content_mail = sprintf( |
139 wp_mail( |
94 /* translators: 1: user login, 2: site url, 3: site name/title */ |
140 get_site_option( 'admin_email' ), |
95 __( 'New site created by %1$s |
141 sprintf( |
|
142 /* translators: %s: network name */ |
|
143 __( '[%s] New Site Created' ), |
|
144 get_network()->site_name |
|
145 ), |
|
146 sprintf( |
|
147 /* translators: 1: user login, 2: site url, 3: site name/title */ |
|
148 __( 'New site created by %1$s |
96 |
149 |
97 Address: %2$s |
150 Address: %2$s |
98 Name: %3$s' ), |
151 Name: %3$s' ), |
99 $current_user->user_login, |
152 $current_user->user_login, |
100 get_site_url( $id ), |
153 get_site_url( $id ), |
101 wp_unslash( $title ) |
154 wp_unslash( $title ) |
|
155 ), |
|
156 sprintf( |
|
157 'From: "%1$s" <%2$s>', |
|
158 _x( 'Site Admin', 'email "From" field' ), |
|
159 get_site_option( 'admin_email' ) |
|
160 ) |
102 ); |
161 ); |
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' ) . '>' ); |
|
104 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) ); |
162 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) ); |
105 wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); |
163 wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); |
106 exit; |
164 exit; |
107 } else { |
165 } else { |
108 wp_die( $id->get_error_message() ); |
166 wp_die( $id->get_error_message() ); |
128 require( ABSPATH . 'wp-admin/admin-header.php' ); |
186 require( ABSPATH . 'wp-admin/admin-header.php' ); |
129 |
187 |
130 ?> |
188 ?> |
131 |
189 |
132 <div class="wrap"> |
190 <div class="wrap"> |
133 <h2 id="add-new-site"><?php _e('Add New Site') ?></h2> |
191 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1> |
134 <?php |
192 <?php |
135 if ( ! empty( $messages ) ) { |
193 if ( ! empty( $messages ) ) { |
136 foreach ( $messages as $msg ) |
194 foreach ( $messages as $msg ) |
137 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
195 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
138 } ?> |
196 } ?> |
139 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate"> |
197 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate"> |
140 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?> |
198 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?> |
141 <table class="form-table"> |
199 <table class="form-table"> |
142 <tr class="form-field form-required"> |
200 <tr class="form-field form-required"> |
143 <th scope="row"><label for="site-address"><?php _e( 'Site Address' ) ?></label></th> |
201 <th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ) ?></label></th> |
144 <td> |
202 <td> |
145 <?php if ( is_subdomain_install() ) { ?> |
203 <?php if ( is_subdomain_install() ) { ?> |
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> |
204 <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> |
147 <?php } else { |
205 <?php } else { |
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" /> |
206 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" /> |
149 <?php } |
207 <?php } |
150 echo '<p id="site-address-desc">' . __( 'Only lowercase letters (a-z) and numbers are allowed.' ) . '</p>'; |
208 echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>'; |
151 ?> |
209 ?> |
152 </td> |
210 </td> |
153 </tr> |
211 </tr> |
154 <tr class="form-field form-required"> |
212 <tr class="form-field form-required"> |
155 <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th> |
213 <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th> |
156 <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td> |
214 <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td> |
157 </tr> |
215 </tr> |
|
216 <?php |
|
217 $languages = get_available_languages(); |
|
218 $translations = wp_get_available_translations(); |
|
219 if ( ! empty( $languages ) || ! empty( $translations ) ) : |
|
220 ?> |
|
221 <tr class="form-field form-required"> |
|
222 <th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th> |
|
223 <td> |
|
224 <?php |
|
225 // Network default. |
|
226 $lang = get_site_option( 'WPLANG' ); |
|
227 |
|
228 // Use English if the default isn't available. |
|
229 if ( ! in_array( $lang, $languages ) ) { |
|
230 $lang = ''; |
|
231 } |
|
232 |
|
233 wp_dropdown_languages( |
|
234 array( |
|
235 'name' => 'WPLANG', |
|
236 'id' => 'site-language', |
|
237 'selected' => $lang, |
|
238 'languages' => $languages, |
|
239 'translations' => $translations, |
|
240 'show_available_translations' => current_user_can( 'install_languages' ) && wp_can_install_language_pack(), |
|
241 ) |
|
242 ); |
|
243 ?> |
|
244 </td> |
|
245 </tr> |
|
246 <?php endif; // Languages. ?> |
158 <tr class="form-field form-required"> |
247 <tr class="form-field form-required"> |
159 <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></td> |
248 <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></th> |
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> |
249 <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> |
161 </tr> |
250 </tr> |
162 <tr class="form-field"> |
251 <tr class="form-field"> |
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> |
252 <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 a link to set the password will be mailed to this email address.' ) ?></td> |
164 </tr> |
253 </tr> |
165 </table> |
254 </table> |
166 <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?> |
255 |
|
256 <?php |
|
257 /** |
|
258 * Fires at the end of the new site form in network admin. |
|
259 * |
|
260 * @since 4.5.0 |
|
261 */ |
|
262 do_action( 'network_site_new_form' ); |
|
263 |
|
264 submit_button( __( 'Add Site' ), 'primary', 'add-site' ); |
|
265 ?> |
167 </form> |
266 </form> |
168 </div> |
267 </div> |
169 <?php |
268 <?php |
170 require( ABSPATH . 'wp-admin/admin-footer.php' ); |
269 require( ABSPATH . 'wp-admin/admin-footer.php' ); |