sites.php 12 KB

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