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