]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/site-new.php
WordPress 4.4.2-scripts
[autoinstalls/wordpress.git] / wp-admin / network / site-new.php
1 <?php
2 /**
3  * Add Site Administration Screen
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.1.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
12
13 /** WordPress Translation Install API */
14 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
15
16 if ( ! is_multisite() )
17         wp_die( __( 'Multisite support is not enabled.' ) );
18
19 if ( ! current_user_can( 'manage_sites' ) )
20         wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) );
21
22 get_current_screen()->add_help_tab( array(
23         'id'      => 'overview',
24         'title'   => __('Overview'),
25         'content' =>
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>'
28 ) );
29
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>'
34 );
35
36 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
37         check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
38
39         if ( ! is_array( $_POST['blog'] ) )
40                 wp_die( __( 'Can&#8217;t create an empty site.' ) );
41
42         $blog = $_POST['blog'];
43         $domain = '';
44         if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
45                 $domain = strtolower( $blog['domain'] );
46
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();
50
51                 if ( in_array( $domain, $subdirectory_reserved_names ) ) {
52                         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 ) ) );
53                 }
54         }
55
56         $title = $blog['title'];
57
58         $meta = array(
59                 'public' => 1
60         );
61
62         // Handle translation install for the new site.
63         if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) {
64                 $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
65                 if ( $language ) {
66                         $meta['WPLANG'] = $language;
67                 }
68         }
69
70         if ( empty( $domain ) )
71                 wp_die( __( 'Missing or invalid site address.' ) );
72
73         if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
74                 wp_die( __( 'Missing email address.' ) );
75         }
76
77         $email = sanitize_email( $blog['email'] );
78         if ( ! is_email( $email ) ) {
79                 wp_die( __( 'Invalid email address.' ) );
80         }
81
82         if ( is_subdomain_install() ) {
83                 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
84                 $path      = $current_site->path;
85         } else {
86                 $newdomain = $current_site->domain;
87                 $path      = $current_site->path . $domain . '/';
88         }
89
90         $password = 'N/A';
91         $user_id = email_exists($email);
92         if ( !$user_id ) { // Create a new user with a random password
93                 $user_id = username_exists( $domain );
94                 if ( $user_id ) {
95                         wp_die( __( 'The domain or path entered conflicts with an existing username.' ) );
96                 }
97                 $password = wp_generate_password( 12, false );
98                 $user_id = wpmu_create_user( $domain, $password, $email );
99                 if ( false === $user_id ) {
100                         wp_die( __( 'There was an error creating the user.' ) );
101                 }
102
103                 /**
104                   * Fires after a new user has been created via the network site-new.php page.
105                   *
106                   * @since 4.4.0
107                   *
108                   * @param int $user_id ID of the newly created user.
109                   */
110                 do_action( 'network_site_new_created_user', $user_id );
111         }
112
113         $wpdb->hide_errors();
114         $id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, $current_site->id );
115         $wpdb->show_errors();
116         if ( ! is_wp_error( $id ) ) {
117                 if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
118                         update_user_option( $user_id, 'primary_blog', $id, true );
119                 }
120
121                 $content_mail = sprintf(
122                         /* translators: 1: user login, 2: site url, 3: site name/title */
123                         __( 'New site created by %1$s
124
125 Address: %2$s
126 Name: %3$s' ),
127                         $current_user->user_login,
128                         get_site_url( $id ),
129                         wp_unslash( $title )
130                 );
131                 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' ) . '>' );
132                 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
133                 wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) );
134                 exit;
135         } else {
136                 wp_die( $id->get_error_message() );
137         }
138 }
139
140 if ( isset($_GET['update']) ) {
141         $messages = array();
142         if ( 'added' == $_GET['update'] )
143                 $messages[] = sprintf(
144                         /* translators: 1: dashboard url, 2: network admin edit url */
145                         __( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
146                         esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
147                         network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
148                 );
149 }
150
151 $title = __('Add New Site');
152 $parent_file = 'sites.php';
153
154 wp_enqueue_script( 'user-suggest' );
155
156 require( ABSPATH . 'wp-admin/admin-header.php' );
157
158 ?>
159
160 <div class="wrap">
161 <h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
162 <?php
163 if ( ! empty( $messages ) ) {
164         foreach ( $messages as $msg )
165                 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
166 } ?>
167 <form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
168 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
169         <table class="form-table">
170                 <tr class="form-field form-required">
171                         <th scope="row"><label for="site-address"><?php _e( 'Site Address' ) ?></label></th>
172                         <td>
173                         <?php if ( is_subdomain_install() ) { ?>
174                                 <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>
175                         <?php } else {
176                                 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" />
177                         <?php }
178                         echo '<p id="site-address-desc">' . __( 'Only lowercase letters (a-z) and numbers are allowed.' ) . '</p>';
179                         ?>
180                         </td>
181                 </tr>
182                 <tr class="form-field form-required">
183                         <th scope="row"><label for="site-title"><?php _e( 'Site Title' ) ?></label></th>
184                         <td><input name="blog[title]" type="text" class="regular-text" id="site-title" /></td>
185                 </tr>
186                 <?php
187                 $languages    = get_available_languages();
188                 $translations = wp_get_available_translations();
189                 if ( ! empty( $languages ) || ! empty( $translations ) ) :
190                         ?>
191                         <tr class="form-field form-required">
192                                 <th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th>
193                                 <td>
194                                         <?php
195                                         // Network default.
196                                         $lang = get_site_option( 'WPLANG' );
197
198                                         // Use English if the default isn't available.
199                                         if ( ! in_array( $lang, $languages ) ) {
200                                                 $lang = '';
201                                         }
202
203                                         wp_dropdown_languages( array(
204                                                 'name'                        => 'WPLANG',
205                                                 'id'                          => 'site-language',
206                                                 'selected'                    => $lang,
207                                                 'languages'                   => $languages,
208                                                 'translations'                => $translations,
209                                                 'show_available_translations' => wp_can_install_language_pack(),
210                                         ) );
211                                         ?>
212                                 </td>
213                         </tr>
214                 <?php endif; // Languages. ?>
215                 <tr class="form-field form-required">
216                         <th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ) ?></label></th>
217                         <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>
218                 </tr>
219                 <tr class="form-field">
220                         <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>
221                 </tr>
222         </table>
223         <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>
224         </form>
225 </div>
226 <?php
227 require( ABSPATH . 'wp-admin/admin-footer.php' );