PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/network/sites.php

https://gitlab.com/Fullerton/PolitePressCore
PHP | 318 lines | 234 code | 46 blank | 38 comment | 40 complexity | 770d4a2614598fe9a49b81e48f2c8fb3 MD5 | raw file
  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 'allblogs':
  113. if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
  114. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  115. foreach ( (array) $_POST['allblogs'] as $key => $val ) {
  116. if ( $val != '0' && $val != get_network()->site_id ) {
  117. switch ( $doaction ) {
  118. case 'delete':
  119. if ( ! current_user_can( 'delete_site', $val ) )
  120. wp_die( __( 'Sorry, you are not allowed to delete the site.' ) );
  121. $updated_action = 'all_delete';
  122. wpmu_delete_blog( $val, true );
  123. break;
  124. case 'spam':
  125. case 'notspam':
  126. $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
  127. update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
  128. break;
  129. }
  130. } else {
  131. wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
  132. }
  133. }
  134. if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
  135. $redirect_to = wp_get_referer();
  136. $blogs = (array) $_POST['allblogs'];
  137. /** This action is documented in wp-admin/network/site-themes.php */
  138. $redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id );
  139. wp_safe_redirect( $redirect_to );
  140. exit();
  141. }
  142. } else {
  143. $location = network_admin_url( 'sites.php' );
  144. if ( ! empty( $_REQUEST['paged'] ) ) {
  145. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  146. }
  147. wp_redirect( $location );
  148. exit();
  149. }
  150. break;
  151. case 'archiveblog':
  152. case 'unarchiveblog':
  153. update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
  154. break;
  155. case 'activateblog':
  156. update_blog_status( $id, 'deleted', '0' );
  157. /**
  158. * Fires after a network site is activated.
  159. *
  160. * @since MU
  161. *
  162. * @param string $id The ID of the activated site.
  163. */
  164. do_action( 'activate_blog', $id );
  165. break;
  166. case 'deactivateblog':
  167. /**
  168. * Fires before a network site is deactivated.
  169. *
  170. * @since MU
  171. *
  172. * @param string $id The ID of the site being deactivated.
  173. */
  174. do_action( 'deactivate_blog', $id );
  175. update_blog_status( $id, 'deleted', '1' );
  176. break;
  177. case 'unspamblog':
  178. case 'spamblog':
  179. update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
  180. break;
  181. case 'unmatureblog':
  182. case 'matureblog':
  183. update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
  184. break;
  185. }
  186. if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
  187. $updated_action = $_GET['action'];
  188. }
  189. if ( ! empty( $updated_action ) ) {
  190. wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
  191. exit();
  192. }
  193. }
  194. $msg = '';
  195. if ( isset( $_GET['updated'] ) ) {
  196. switch ( $_GET['updated'] ) {
  197. case 'all_notspam':
  198. $msg = __( 'Sites removed from spam.' );
  199. break;
  200. case 'all_spam':
  201. $msg = __( 'Sites marked as spam.' );
  202. break;
  203. case 'all_delete':
  204. $msg = __( 'Sites deleted.' );
  205. break;
  206. case 'delete':
  207. $msg = __( 'Site deleted.' );
  208. break;
  209. case 'not_deleted':
  210. $msg = __( 'Sorry, you are not allowed to delete that site.' );
  211. break;
  212. case 'archiveblog':
  213. $msg = __( 'Site archived.' );
  214. break;
  215. case 'unarchiveblog':
  216. $msg = __( 'Site unarchived.' );
  217. break;
  218. case 'activateblog':
  219. $msg = __( 'Site activated.' );
  220. break;
  221. case 'deactivateblog':
  222. $msg = __( 'Site deactivated.' );
  223. break;
  224. case 'unspamblog':
  225. $msg = __( 'Site removed from spam.' );
  226. break;
  227. case 'spamblog':
  228. $msg = __( 'Site marked as spam.' );
  229. break;
  230. default:
  231. /**
  232. * Filters a specific, non-default site-updated message in the Network admin.
  233. *
  234. * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
  235. * non-default site update action.
  236. *
  237. * @since 3.1.0
  238. *
  239. * @param string $msg The update message. Default 'Settings saved'.
  240. */
  241. $msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
  242. break;
  243. }
  244. if ( ! empty( $msg ) )
  245. $msg = '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  246. }
  247. $wp_list_table->prepare_items();
  248. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  249. ?>
  250. <div class="wrap">
  251. <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
  252. <?php if ( current_user_can( 'create_sites') ) : ?>
  253. <a href="<?php echo network_admin_url('site-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
  254. <?php endif; ?>
  255. <?php
  256. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  257. /* translators: %s: search keywords */
  258. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
  259. }
  260. ?>
  261. <hr class="wp-header-end">
  262. <?php echo $msg; ?>
  263. <form method="get" id="ms-search">
  264. <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
  265. <input type="hidden" name="action" value="blogs" />
  266. </form>
  267. <form id="form-site-list" action="sites.php?action=allblogs" method="post">
  268. <?php $wp_list_table->display(); ?>
  269. </form>
  270. </div>
  271. <?php
  272. require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>