themes.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /**
  3. * Multisite themes administration panel.
  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_network_themes' ) ) {
  12. wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
  13. }
  14. $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
  15. $pagenum = $wp_list_table->get_pagenum();
  16. $action = $wp_list_table->current_action();
  17. $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
  18. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  19. $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
  20. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  21. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  22. if ( $action ) {
  23. switch ( $action ) {
  24. case 'enable':
  25. check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  26. WP_Theme::network_enable_theme( $_GET['theme'] );
  27. if ( false === strpos( $referer, '/network/themes.php' ) ) {
  28. wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  29. } else {
  30. wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
  31. }
  32. exit;
  33. case 'disable':
  34. check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  35. WP_Theme::network_disable_theme( $_GET['theme'] );
  36. wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  37. exit;
  38. case 'enable-selected':
  39. check_admin_referer( 'bulk-themes' );
  40. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  41. if ( empty( $themes ) ) {
  42. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  43. exit;
  44. }
  45. WP_Theme::network_enable_theme( (array) $themes );
  46. wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  47. exit;
  48. case 'disable-selected':
  49. check_admin_referer( 'bulk-themes' );
  50. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  51. if ( empty( $themes ) ) {
  52. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  53. exit;
  54. }
  55. WP_Theme::network_disable_theme( (array) $themes );
  56. wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  57. exit;
  58. case 'update-selected':
  59. check_admin_referer( 'bulk-themes' );
  60. if ( isset( $_GET['themes'] ) ) {
  61. $themes = explode( ',', $_GET['themes'] );
  62. } elseif ( isset( $_POST['checked'] ) ) {
  63. $themes = (array) $_POST['checked'];
  64. } else {
  65. $themes = array();
  66. }
  67. $title = __( 'Update Themes' );
  68. $parent_file = 'themes.php';
  69. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  70. echo '<div class="wrap">';
  71. echo '<h1>' . esc_html( $title ) . '</h1>';
  72. $url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( join( ',', $themes ) ) );
  73. $url = wp_nonce_url( $url, 'bulk-update-themes' );
  74. echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  75. echo '</div>';
  76. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  77. exit;
  78. case 'delete-selected':
  79. if ( ! current_user_can( 'delete_themes' ) ) {
  80. wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
  81. }
  82. check_admin_referer( 'bulk-themes' );
  83. $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  84. if ( empty( $themes ) ) {
  85. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  86. exit;
  87. }
  88. $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
  89. if ( empty( $themes ) ) {
  90. wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
  91. exit;
  92. }
  93. $theme_info = array();
  94. foreach ( $themes as $key => $theme ) {
  95. $theme_info[ $theme ] = wp_get_theme( $theme );
  96. }
  97. include( ABSPATH . 'wp-admin/update.php' );
  98. $parent_file = 'themes.php';
  99. if ( ! isset( $_REQUEST['verify-delete'] ) ) {
  100. wp_enqueue_script( 'jquery' );
  101. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  102. $themes_to_delete = count( $themes );
  103. ?>
  104. <div class="wrap">
  105. <?php if ( 1 == $themes_to_delete ) : ?>
  106. <h1><?php _e( 'Delete Theme' ); ?></h1>
  107. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
  108. <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
  109. <?php else : ?>
  110. <h1><?php _e( 'Delete Themes' ); ?></h1>
  111. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
  112. <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
  113. <?php endif; ?>
  114. <ul class="ul-disc">
  115. <?php
  116. foreach ( $theme_info as $theme ) {
  117. echo '<li>' . sprintf(
  118. /* translators: 1: Theme name, 2: Theme author. */
  119. _x( '%1$s by %2$s', 'theme' ),
  120. '<strong>' . $theme->display( 'Name' ) . '</strong>',
  121. '<em>' . $theme->display( 'Author' ) . '</em>'
  122. ) . '</li>';
  123. }
  124. ?>
  125. </ul>
  126. <?php if ( 1 == $themes_to_delete ) : ?>
  127. <p><?php _e( 'Are you sure you want to delete this theme?' ); ?></p>
  128. <?php else : ?>
  129. <p><?php _e( 'Are you sure you want to delete these themes?' ); ?></p>
  130. <?php endif; ?>
  131. <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
  132. <input type="hidden" name="verify-delete" value="1" />
  133. <input type="hidden" name="action" value="delete-selected" />
  134. <?php
  135. foreach ( (array) $themes as $theme ) {
  136. echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
  137. }
  138. wp_nonce_field( 'bulk-themes' );
  139. if ( 1 == $themes_to_delete ) {
  140. submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
  141. } else {
  142. submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
  143. }
  144. ?>
  145. </form>
  146. <?php
  147. $referer = wp_get_referer();
  148. ?>
  149. <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
  150. <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
  151. </form>
  152. </div>
  153. <?php
  154. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  155. exit;
  156. } // Endif verify-delete
  157. foreach ( $themes as $theme ) {
  158. $delete_result = delete_theme(
  159. $theme,
  160. esc_url(
  161. add_query_arg(
  162. array(
  163. 'verify-delete' => 1,
  164. 'action' => 'delete-selected',
  165. 'checked' => $_REQUEST['checked'],
  166. '_wpnonce' => $_REQUEST['_wpnonce'],
  167. ),
  168. network_admin_url( 'themes.php' )
  169. )
  170. )
  171. );
  172. }
  173. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  174. wp_redirect(
  175. add_query_arg(
  176. array(
  177. 'deleted' => count( $themes ),
  178. 'paged' => $paged,
  179. 's' => $s,
  180. ),
  181. network_admin_url( 'themes.php' )
  182. )
  183. );
  184. exit;
  185. default:
  186. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  187. if ( empty( $themes ) ) {
  188. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  189. exit;
  190. }
  191. check_admin_referer( 'bulk-themes' );
  192. /** This action is documented in wp-admin/network/site-themes.php */
  193. $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  194. wp_safe_redirect( $referer );
  195. exit;
  196. }
  197. }
  198. $wp_list_table->prepare_items();
  199. add_thickbox();
  200. add_screen_option( 'per_page' );
  201. get_current_screen()->add_help_tab(
  202. array(
  203. 'id' => 'overview',
  204. 'title' => __( 'Overview' ),
  205. 'content' =>
  206. '<p>' . __( 'This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.' ) . '</p>' .
  207. '<p>' . __( 'If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.' ) . '</p>' .
  208. '<p>' . __( 'Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.' ) . '</p>',
  209. )
  210. );
  211. get_current_screen()->set_help_sidebar(
  212. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  213. '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
  214. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  215. );
  216. get_current_screen()->set_screen_reader_content(
  217. array(
  218. 'heading_views' => __( 'Filter themes list' ),
  219. 'heading_pagination' => __( 'Themes list navigation' ),
  220. 'heading_list' => __( 'Themes list' ),
  221. )
  222. );
  223. $title = __( 'Themes' );
  224. $parent_file = 'themes.php';
  225. wp_enqueue_script( 'updates' );
  226. wp_enqueue_script( 'theme-preview' );
  227. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  228. ?>
  229. <div class="wrap">
  230. <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
  231. <?php if ( current_user_can( 'install_themes' ) ) : ?>
  232. <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
  233. <?php endif; ?>
  234. <?php
  235. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  236. /* translators: %s: Search query. */
  237. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
  238. }
  239. ?>
  240. <hr class="wp-header-end">
  241. <?php
  242. if ( isset( $_GET['enabled'] ) ) {
  243. $enabled = absint( $_GET['enabled'] );
  244. if ( 1 == $enabled ) {
  245. $message = __( 'Theme enabled.' );
  246. } else {
  247. /* translators: %s: Number of themes. */
  248. $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
  249. }
  250. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  251. } elseif ( isset( $_GET['disabled'] ) ) {
  252. $disabled = absint( $_GET['disabled'] );
  253. if ( 1 == $disabled ) {
  254. $message = __( 'Theme disabled.' );
  255. } else {
  256. /* translators: %s: Number of themes. */
  257. $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
  258. }
  259. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  260. } elseif ( isset( $_GET['deleted'] ) ) {
  261. $deleted = absint( $_GET['deleted'] );
  262. if ( 1 == $deleted ) {
  263. $message = __( 'Theme deleted.' );
  264. } else {
  265. /* translators: %s: Number of themes. */
  266. $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
  267. }
  268. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
  269. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  270. echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
  271. } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
  272. echo '<div class="error notice is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  273. }
  274. ?>
  275. <form method="get">
  276. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  277. </form>
  278. <?php
  279. $wp_list_table->views();
  280. if ( 'broken' == $status ) {
  281. echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
  282. }
  283. ?>
  284. <form id="bulk-action-form" method="post">
  285. <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
  286. <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
  287. <?php $wp_list_table->display(); ?>
  288. </form>
  289. </div>
  290. <?php
  291. wp_print_request_filesystem_credentials_modal();
  292. wp_print_admin_notice_templates();
  293. wp_print_update_row_templates();
  294. include( ABSPATH . 'wp-admin/admin-footer.php' );