site-themes.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * Edit Site Themes Administration Screen
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.1.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 manage themes for this site.' ) );
  13. get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
  14. get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
  15. get_current_screen()->set_screen_reader_content( array(
  16. 'heading_views' => __( 'Filter site themes list' ),
  17. 'heading_pagination' => __( 'Site themes list navigation' ),
  18. 'heading_list' => __( 'Site themes list' ),
  19. ) );
  20. $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
  21. $action = $wp_list_table->current_action();
  22. $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
  23. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  24. $temp_args = array( 'enabled', 'disabled', 'error' );
  25. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  26. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  27. if ( ! empty( $_REQUEST['paged'] ) ) {
  28. $referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
  29. }
  30. $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  31. if ( ! $id )
  32. wp_die( __('Invalid site ID.') );
  33. $wp_list_table->prepare_items();
  34. $details = get_site( $id );
  35. if ( ! $details ) {
  36. wp_die( __( 'The requested site does not exist.' ) );
  37. }
  38. if ( !can_edit_network( $details->site_id ) )
  39. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  40. $is_main_site = is_main_site( $id );
  41. if ( $action ) {
  42. switch_to_blog( $id );
  43. $allowed_themes = get_option( 'allowedthemes' );
  44. switch ( $action ) {
  45. case 'enable':
  46. check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  47. $theme = $_GET['theme'];
  48. $action = 'enabled';
  49. $n = 1;
  50. if ( !$allowed_themes )
  51. $allowed_themes = array( $theme => true );
  52. else
  53. $allowed_themes[$theme] = true;
  54. break;
  55. case 'disable':
  56. check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  57. $theme = $_GET['theme'];
  58. $action = 'disabled';
  59. $n = 1;
  60. if ( !$allowed_themes )
  61. $allowed_themes = array();
  62. else
  63. unset( $allowed_themes[$theme] );
  64. break;
  65. case 'enable-selected':
  66. check_admin_referer( 'bulk-themes' );
  67. if ( isset( $_POST['checked'] ) ) {
  68. $themes = (array) $_POST['checked'];
  69. $action = 'enabled';
  70. $n = count( $themes );
  71. foreach ( (array) $themes as $theme )
  72. $allowed_themes[ $theme ] = true;
  73. } else {
  74. $action = 'error';
  75. $n = 'none';
  76. }
  77. break;
  78. case 'disable-selected':
  79. check_admin_referer( 'bulk-themes' );
  80. if ( isset( $_POST['checked'] ) ) {
  81. $themes = (array) $_POST['checked'];
  82. $action = 'disabled';
  83. $n = count( $themes );
  84. foreach ( (array) $themes as $theme )
  85. unset( $allowed_themes[ $theme ] );
  86. } else {
  87. $action = 'error';
  88. $n = 'none';
  89. }
  90. break;
  91. default:
  92. if ( isset( $_POST['checked'] ) ) {
  93. check_admin_referer( 'bulk-themes' );
  94. $themes = (array) $_POST['checked'];
  95. $n = count( $themes );
  96. $screen = get_current_screen()->id;
  97. /**
  98. * Fires when a custom bulk action should be handled.
  99. *
  100. * The redirect link should be modified with success or failure feedback
  101. * from the action to be used to display feedback to the user.
  102. *
  103. * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
  104. *
  105. * @since 4.7.0
  106. *
  107. * @param string $redirect_url The redirect URL.
  108. * @param string $action The action being taken.
  109. * @param array $items The items to take the action on.
  110. * @param int $site_id The site ID.
  111. */
  112. $referer = apply_filters( "handle_network_bulk_actions-{$screen}", $referer, $action, $themes, $id );
  113. } else {
  114. $action = 'error';
  115. $n = 'none';
  116. }
  117. }
  118. update_option( 'allowedthemes', $allowed_themes );
  119. restore_current_blog();
  120. wp_safe_redirect( add_query_arg( array( 'id' => $id, $action => $n ), $referer ) );
  121. exit;
  122. }
  123. if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
  124. wp_safe_redirect( $referer );
  125. exit();
  126. }
  127. add_thickbox();
  128. add_screen_option( 'per_page' );
  129. /* translators: %s: site name */
  130. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  131. $parent_file = 'sites.php';
  132. $submenu_file = 'sites.php';
  133. require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
  134. <div class="wrap">
  135. <h1 id="edit-site"><?php echo $title; ?></h1>
  136. <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
  137. <?php
  138. network_edit_site_nav( array(
  139. 'blog_id' => $id,
  140. 'selected' => 'site-themes'
  141. ) );
  142. if ( isset( $_GET['enabled'] ) ) {
  143. $enabled = absint( $_GET['enabled'] );
  144. if ( 1 == $enabled ) {
  145. $message = __( 'Theme enabled.' );
  146. } else {
  147. $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
  148. }
  149. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  150. } elseif ( isset( $_GET['disabled'] ) ) {
  151. $disabled = absint( $_GET['disabled'] );
  152. if ( 1 == $disabled ) {
  153. $message = __( 'Theme disabled.' );
  154. } else {
  155. $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
  156. }
  157. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  158. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  159. echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
  160. } ?>
  161. <p><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
  162. <form method="get">
  163. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  164. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  165. </form>
  166. <?php $wp_list_table->views(); ?>
  167. <form method="post" action="site-themes.php?action=update-site">
  168. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  169. <?php $wp_list_table->display(); ?>
  170. </form>
  171. </div>
  172. <?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>