sites.php 13 KB

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