]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/sites.php
WordPress 4.4-scripts
[autoinstalls/wordpress.git] / wp-admin / network / sites.php
1 <?php
2 /**
3  * Multisite sites administration panel.
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.0.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( ! current_user_can( 'manage_sites' ) )
17         wp_die( __( 'You do not have permission to access this page.' ), 403 );
18
19 $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
20 $pagenum = $wp_list_table->get_pagenum();
21
22 $title = __( 'Sites' );
23 $parent_file = 'sites.php';
24
25 add_screen_option( 'per_page' );
26
27 get_current_screen()->add_help_tab( array(
28         'id'      => 'overview',
29         'title'   => __('Overview'),
30         'content' =>
31                 '<p>' . __('Add New takes you to the Add New Site screen. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.') . '</p>' .
32                 '<p>' . __('This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.') . '</p>' .
33                 '<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' .
34                 '<ul><li>' . __('An Edit link to a separate Edit Site screen.') . '</li>' .
35                 '<li>' . __('Dashboard leads to the Dashboard for that site.') . '</li>' .
36                 '<li>' . __('Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.') . '</li>' .
37                 '<li>' . __('Delete which is a permanent action after the confirmation screens.') . '</li>' .
38                 '<li>' . __('Visit to go to the frontend site live.') . '</li></ul>' .
39                 '<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' .
40                 '<p>' . __('Clicking on bold headings can re-sort this table.') . '</p>'
41 ) );
42
43 get_current_screen()->set_help_sidebar(
44         '<p><strong>' . __('For more information:') . '</strong></p>' .
45         '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
46         '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
47 );
48
49 get_current_screen()->set_screen_reader_content( array(
50         'heading_pagination' => __( 'Sites list navigation' ),
51         'heading_list'       => __( 'Sites list' ),
52 ) );
53
54 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
55
56 if ( isset( $_GET['action'] ) ) {
57         /** This action is documented in wp-admin/network/edit.php */
58         do_action( 'wpmuadminedit' );
59
60         // A list of valid actions and their associated messaging for confirmation output.
61         $manage_actions = array(
62                 'activateblog'   => __( 'You are about to activate the site %s' ),
63                 'deactivateblog' => __( 'You are about to deactivate the site %s' ),
64                 'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
65                 'archiveblog'    => __( 'You are about to archive the site %s.' ),
66                 'unspamblog'     => __( 'You are about to unspam the site %s.' ),
67                 'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
68                 'deleteblog'     => __( 'You are about to delete the site %s.' ),
69                 'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
70                 'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
71         );
72
73         if ( 'confirm' === $_GET['action'] ) {
74                 // The action2 parameter contains the action being taken on the site.
75                 $site_action = $_GET['action2'];
76
77                 if ( ! array_key_exists( $site_action, $manage_actions ) ) {
78                         wp_die( __( 'The requested action is not valid.' ) );
79                 }
80
81                 // The mature/unmature UI exists only as external code. Check the "confirm" nonce for backward compatibility.
82                 if ( 'matureblog' === $site_action || 'unmatureblog' === $site_action ) {
83                         check_admin_referer( 'confirm' );
84                 } else {
85                         check_admin_referer( $site_action . '_' . $id );
86                 }
87
88                 if ( ! headers_sent() ) {
89                         nocache_headers();
90                         header( 'Content-Type: text/html; charset=utf-8' );
91                 }
92
93                 if ( $current_site->blog_id == $id ) {
94                         wp_die( __( 'You are not allowed to change the current site.' ) );
95                 }
96
97                 $site_details = get_blog_details( $id );
98                 $site_address = untrailingslashit( $site_details->domain . $site_details->path );
99
100                 require_once( ABSPATH . 'wp-admin/admin-header.php' );
101                 ?>
102                         <div class="wrap">
103                                 <h1><?php _e( 'Confirm your action' ); ?></h1>
104                                 <form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
105                                         <input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
106                                         <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
107                                         <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
108                                         <?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
109                                         <p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
110                                         <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
111                                 </form>
112                         </div>
113                 <?php
114                 require_once( ABSPATH . 'wp-admin/admin-footer.php' );
115                 exit();
116         } elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
117                 $action = $_GET['action'];
118                 check_admin_referer( $action . '_' . $id );
119         } elseif ( 'allblogs' === $_GET['action'] ) {
120                 check_admin_referer( 'bulk-sites' );
121         }
122
123         $updated_action = '';
124
125         switch ( $_GET['action'] ) {
126
127                 case 'deleteblog':
128                         if ( ! current_user_can( 'delete_sites' ) )
129                                 wp_die( __( 'You do not have permission to access this page.' ), '', array( 'response' => 403 ) );
130
131                         $updated_action = 'not_deleted';
132                         if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
133                                 wpmu_delete_blog( $id, true );
134                                 $updated_action = 'delete';
135                         }
136                 break;
137
138                 case 'allblogs':
139                         if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
140                                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
141
142                                 foreach ( (array) $_POST['allblogs'] as $key => $val ) {
143                                         if ( $val != '0' && $val != $current_site->blog_id ) {
144                                                 switch ( $doaction ) {
145                                                         case 'delete':
146                                                                 if ( ! current_user_can( 'delete_site', $val ) )
147                                                                         wp_die( __( 'You are not allowed to delete the site.' ) );
148
149                                                                 $updated_action = 'all_delete';
150                                                                 wpmu_delete_blog( $val, true );
151                                                         break;
152
153                                                         case 'spam':
154                                                         case 'notspam':
155                                                                 $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
156                                                                 update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
157                                                         break;
158                                                 }
159                                         } else {
160                                                 wp_die( __( 'You are not allowed to change the current site.' ) );
161                                         }
162                                 }
163                         } else {
164                                 wp_redirect( network_admin_url( 'sites.php' ) );
165                                 exit();
166                         }
167                 break;
168
169                 case 'archiveblog':
170                 case 'unarchiveblog':
171                         update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
172                 break;
173
174                 case 'activateblog':
175                         update_blog_status( $id, 'deleted', '0' );
176
177                         /**
178                          * Fires after a network site is activated.
179                          *
180                          * @since MU
181                          *
182                          * @param string $id The ID of the activated site.
183                          */
184                         do_action( 'activate_blog', $id );
185                 break;
186
187                 case 'deactivateblog':
188                         /**
189                          * Fires before a network site is deactivated.
190                          *
191                          * @since MU
192                          *
193                          * @param string $id The ID of the site being deactivated.
194                          */
195                         do_action( 'deactivate_blog', $id );
196                         update_blog_status( $id, 'deleted', '1' );
197                 break;
198
199                 case 'unspamblog':
200                 case 'spamblog':
201                         update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
202                 break;
203
204                 case 'unmatureblog':
205                 case 'matureblog':
206                         update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
207                 break;
208         }
209
210         if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
211                 $updated_action = $_GET['action'];
212         }
213
214         if ( ! empty( $updated_action ) ) {
215                 wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
216                 exit();
217         }
218 }
219
220 $msg = '';
221 if ( isset( $_GET['updated'] ) ) {
222         switch ( $_GET['updated'] ) {
223                 case 'all_notspam':
224                         $msg = __( 'Sites removed from spam.' );
225                 break;
226                 case 'all_spam':
227                         $msg = __( 'Sites marked as spam.' );
228                 break;
229                 case 'all_delete':
230                         $msg = __( 'Sites deleted.' );
231                 break;
232                 case 'delete':
233                         $msg = __( 'Site deleted.' );
234                 break;
235                 case 'not_deleted':
236                         $msg = __( 'You do not have permission to delete that site.' );
237                 break;
238                 case 'archiveblog':
239                         $msg = __( 'Site archived.' );
240                 break;
241                 case 'unarchiveblog':
242                         $msg = __( 'Site unarchived.' );
243                 break;
244                 case 'activateblog':
245                         $msg = __( 'Site activated.' );
246                 break;
247                 case 'deactivateblog':
248                         $msg = __( 'Site deactivated.' );
249                 break;
250                 case 'unspamblog':
251                         $msg = __( 'Site removed from spam.' );
252                 break;
253                 case 'spamblog':
254                         $msg = __( 'Site marked as spam.' );
255                 break;
256                 default:
257                         /**
258                          * Filter a specific, non-default site-updated message in the Network admin.
259                          *
260                          * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
261                          * non-default site update action.
262                          *
263                          * @since 3.1.0
264                          *
265                          * @param string $msg The update message. Default 'Settings saved'.
266                          */
267                         $msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
268                 break;
269         }
270
271         if ( ! empty( $msg ) )
272                 $msg = '<div class="updated" id="message notice is-dismissible"><p>' . $msg . '</p></div>';
273 }
274
275 $wp_list_table->prepare_items();
276
277 require_once( ABSPATH . 'wp-admin/admin-header.php' );
278 ?>
279
280 <div class="wrap">
281 <h1><?php _e( 'Sites' ); ?>
282
283 <?php if ( current_user_can( 'create_sites') ) : ?>
284         <a href="<?php echo network_admin_url('site-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
285 <?php endif; ?>
286
287 <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) {
288         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
289 } ?>
290 </h1>
291
292 <?php echo $msg; ?>
293
294 <form method="get" id="ms-search">
295 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
296 <input type="hidden" name="action" value="blogs" />
297 </form>
298
299 <form id="form-site-list" action="sites.php?action=allblogs" method="post">
300         <?php $wp_list_table->display(); ?>
301 </form>
302 </div>
303 <?php
304
305 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>