Bez popisu

themes.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 __DIR__ . '/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(
  20. 'enabled',
  21. 'disabled',
  22. 'deleted',
  23. 'error',
  24. 'enabled-auto-update',
  25. 'disabled-auto-update',
  26. );
  27. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  28. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  29. if ( $action ) {
  30. switch ( $action ) {
  31. case 'enable':
  32. check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  33. WP_Theme::network_enable_theme( $_GET['theme'] );
  34. if ( false === strpos( $referer, '/network/themes.php' ) ) {
  35. wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  36. } else {
  37. wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
  38. }
  39. exit;
  40. case 'disable':
  41. check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  42. WP_Theme::network_disable_theme( $_GET['theme'] );
  43. wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  44. exit;
  45. case 'enable-selected':
  46. check_admin_referer( 'bulk-themes' );
  47. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  48. if ( empty( $themes ) ) {
  49. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  50. exit;
  51. }
  52. WP_Theme::network_enable_theme( (array) $themes );
  53. wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  54. exit;
  55. case 'disable-selected':
  56. check_admin_referer( 'bulk-themes' );
  57. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  58. if ( empty( $themes ) ) {
  59. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  60. exit;
  61. }
  62. WP_Theme::network_disable_theme( (array) $themes );
  63. wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  64. exit;
  65. case 'update-selected':
  66. check_admin_referer( 'bulk-themes' );
  67. if ( isset( $_GET['themes'] ) ) {
  68. $themes = explode( ',', $_GET['themes'] );
  69. } elseif ( isset( $_POST['checked'] ) ) {
  70. $themes = (array) $_POST['checked'];
  71. } else {
  72. $themes = array();
  73. }
  74. $title = __( 'Update Themes' );
  75. $parent_file = 'themes.php';
  76. require_once ABSPATH . 'wp-admin/admin-header.php';
  77. echo '<div class="wrap">';
  78. echo '<h1>' . esc_html( $title ) . '</h1>';
  79. $url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) ) );
  80. $url = wp_nonce_url( $url, 'bulk-update-themes' );
  81. echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  82. echo '</div>';
  83. require_once ABSPATH . 'wp-admin/admin-footer.php';
  84. exit;
  85. case 'delete-selected':
  86. if ( ! current_user_can( 'delete_themes' ) ) {
  87. wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
  88. }
  89. check_admin_referer( 'bulk-themes' );
  90. $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  91. if ( empty( $themes ) ) {
  92. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  93. exit;
  94. }
  95. $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
  96. if ( empty( $themes ) ) {
  97. wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
  98. exit;
  99. }
  100. $theme_info = array();
  101. foreach ( $themes as $key => $theme ) {
  102. $theme_info[ $theme ] = wp_get_theme( $theme );
  103. }
  104. require ABSPATH . 'wp-admin/update.php';
  105. $parent_file = 'themes.php';
  106. if ( ! isset( $_REQUEST['verify-delete'] ) ) {
  107. wp_enqueue_script( 'jquery' );
  108. require_once ABSPATH . 'wp-admin/admin-header.php';
  109. $themes_to_delete = count( $themes );
  110. ?>
  111. <div class="wrap">
  112. <?php if ( 1 === $themes_to_delete ) : ?>
  113. <h1><?php _e( 'Delete Theme' ); ?></h1>
  114. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
  115. <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
  116. <?php else : ?>
  117. <h1><?php _e( 'Delete Themes' ); ?></h1>
  118. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
  119. <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
  120. <?php endif; ?>
  121. <ul class="ul-disc">
  122. <?php
  123. foreach ( $theme_info as $theme ) {
  124. echo '<li>' . sprintf(
  125. /* translators: 1: Theme name, 2: Theme author. */
  126. _x( '%1$s by %2$s', 'theme' ),
  127. '<strong>' . $theme->display( 'Name' ) . '</strong>',
  128. '<em>' . $theme->display( 'Author' ) . '</em>'
  129. ) . '</li>';
  130. }
  131. ?>
  132. </ul>
  133. <?php if ( 1 === $themes_to_delete ) : ?>
  134. <p><?php _e( 'Are you sure you want to delete this theme?' ); ?></p>
  135. <?php else : ?>
  136. <p><?php _e( 'Are you sure you want to delete these themes?' ); ?></p>
  137. <?php endif; ?>
  138. <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
  139. <input type="hidden" name="verify-delete" value="1" />
  140. <input type="hidden" name="action" value="delete-selected" />
  141. <?php
  142. foreach ( (array) $themes as $theme ) {
  143. echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
  144. }
  145. wp_nonce_field( 'bulk-themes' );
  146. if ( 1 === $themes_to_delete ) {
  147. submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
  148. } else {
  149. submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
  150. }
  151. ?>
  152. </form>
  153. <?php $referer = wp_get_referer(); ?>
  154. <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
  155. <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
  156. </form>
  157. </div>
  158. <?php
  159. require_once ABSPATH . 'wp-admin/admin-footer.php';
  160. exit;
  161. } // End if verify-delete.
  162. foreach ( $themes as $theme ) {
  163. $delete_result = delete_theme(
  164. $theme,
  165. esc_url(
  166. add_query_arg(
  167. array(
  168. 'verify-delete' => 1,
  169. 'action' => 'delete-selected',
  170. 'checked' => $_REQUEST['checked'],
  171. '_wpnonce' => $_REQUEST['_wpnonce'],
  172. ),
  173. network_admin_url( 'themes.php' )
  174. )
  175. )
  176. );
  177. }
  178. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  179. wp_redirect(
  180. add_query_arg(
  181. array(
  182. 'deleted' => count( $themes ),
  183. 'paged' => $paged,
  184. 's' => $s,
  185. ),
  186. network_admin_url( 'themes.php' )
  187. )
  188. );
  189. exit;
  190. case 'enable-auto-update':
  191. case 'disable-auto-update':
  192. case 'enable-auto-update-selected':
  193. case 'disable-auto-update-selected':
  194. if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
  195. wp_die( __( 'Sorry, you are not allowed to change themes automatic update settings.' ) );
  196. }
  197. if ( 'enable-auto-update' === $action || 'disable-auto-update' === $action ) {
  198. check_admin_referer( 'updates' );
  199. } else {
  200. if ( empty( $_POST['checked'] ) ) {
  201. // Nothing to do.
  202. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  203. exit;
  204. }
  205. check_admin_referer( 'bulk-themes' );
  206. }
  207. $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
  208. if ( 'enable-auto-update' === $action ) {
  209. $auto_updates[] = $_GET['theme'];
  210. $auto_updates = array_unique( $auto_updates );
  211. $referer = add_query_arg( 'enabled-auto-update', 1, $referer );
  212. } elseif ( 'disable-auto-update' === $action ) {
  213. $auto_updates = array_diff( $auto_updates, array( $_GET['theme'] ) );
  214. $referer = add_query_arg( 'disabled-auto-update', 1, $referer );
  215. } else {
  216. // Bulk enable/disable.
  217. $themes = (array) wp_unslash( $_POST['checked'] );
  218. if ( 'enable-auto-update-selected' === $action ) {
  219. $auto_updates = array_merge( $auto_updates, $themes );
  220. $auto_updates = array_unique( $auto_updates );
  221. $referer = add_query_arg( 'enabled-auto-update', count( $themes ), $referer );
  222. } else {
  223. $auto_updates = array_diff( $auto_updates, $themes );
  224. $referer = add_query_arg( 'disabled-auto-update', count( $themes ), $referer );
  225. }
  226. }
  227. $all_items = wp_get_themes();
  228. // Remove themes that don't exist or have been deleted since the option was last updated.
  229. $auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
  230. update_site_option( 'auto_update_themes', $auto_updates );
  231. wp_safe_redirect( $referer );
  232. exit;
  233. default:
  234. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  235. if ( empty( $themes ) ) {
  236. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  237. exit;
  238. }
  239. check_admin_referer( 'bulk-themes' );
  240. /** This action is documented in wp-admin/network/site-themes.php */
  241. $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  242. wp_safe_redirect( $referer );
  243. exit;
  244. }
  245. }
  246. $wp_list_table->prepare_items();
  247. add_thickbox();
  248. add_screen_option( 'per_page' );
  249. get_current_screen()->add_help_tab(
  250. array(
  251. 'id' => 'overview',
  252. 'title' => __( 'Overview' ),
  253. 'content' =>
  254. '<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>' .
  255. '<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>' .
  256. '<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>',
  257. )
  258. );
  259. $help_sidebar_autoupdates = '';
  260. if ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) {
  261. get_current_screen()->add_help_tab(
  262. array(
  263. 'id' => 'plugins-themes-auto-updates',
  264. 'title' => __( 'Auto-updates' ),
  265. 'content' =>
  266. '<p>' . __( 'Auto-updates can be enabled or disabled for each individual theme. Themes with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>' .
  267. '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>',
  268. )
  269. );
  270. $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
  271. }
  272. get_current_screen()->set_help_sidebar(
  273. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  274. '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
  275. $help_sidebar_autoupdates .
  276. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  277. );
  278. get_current_screen()->set_screen_reader_content(
  279. array(
  280. 'heading_views' => __( 'Filter themes list' ),
  281. 'heading_pagination' => __( 'Themes list navigation' ),
  282. 'heading_list' => __( 'Themes list' ),
  283. )
  284. );
  285. $title = __( 'Themes' );
  286. $parent_file = 'themes.php';
  287. wp_enqueue_script( 'updates' );
  288. wp_enqueue_script( 'theme-preview' );
  289. require_once ABSPATH . 'wp-admin/admin-header.php';
  290. ?>
  291. <div class="wrap">
  292. <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
  293. <?php if ( current_user_can( 'install_themes' ) ) : ?>
  294. <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
  295. <?php endif; ?>
  296. <?php
  297. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  298. echo '<span class="subtitle">';
  299. printf(
  300. /* translators: %s: Search query. */
  301. __( 'Search results for: %s' ),
  302. '<strong>' . esc_html( $s ) . '</strong>'
  303. );
  304. echo '</span>';
  305. }
  306. ?>
  307. <hr class="wp-header-end">
  308. <?php
  309. if ( isset( $_GET['enabled'] ) ) {
  310. $enabled = absint( $_GET['enabled'] );
  311. if ( 1 === $enabled ) {
  312. $message = __( 'Theme enabled.' );
  313. } else {
  314. /* translators: %s: Number of themes. */
  315. $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
  316. }
  317. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  318. } elseif ( isset( $_GET['disabled'] ) ) {
  319. $disabled = absint( $_GET['disabled'] );
  320. if ( 1 === $disabled ) {
  321. $message = __( 'Theme disabled.' );
  322. } else {
  323. /* translators: %s: Number of themes. */
  324. $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
  325. }
  326. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  327. } elseif ( isset( $_GET['deleted'] ) ) {
  328. $deleted = absint( $_GET['deleted'] );
  329. if ( 1 === $deleted ) {
  330. $message = __( 'Theme deleted.' );
  331. } else {
  332. /* translators: %s: Number of themes. */
  333. $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
  334. }
  335. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
  336. } elseif ( isset( $_GET['enabled-auto-update'] ) ) {
  337. $enabled = absint( $_GET['enabled-auto-update'] );
  338. if ( 1 === $enabled ) {
  339. $message = __( 'Theme will be auto-updated.' );
  340. } else {
  341. /* translators: %s: Number of themes. */
  342. $message = _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled );
  343. }
  344. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
  345. } elseif ( isset( $_GET['disabled-auto-update'] ) ) {
  346. $disabled = absint( $_GET['disabled-auto-update'] );
  347. if ( 1 === $disabled ) {
  348. $message = __( 'Theme will no longer be auto-updated.' );
  349. } else {
  350. /* translators: %s: Number of themes. */
  351. $message = _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled );
  352. }
  353. echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
  354. } elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
  355. echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
  356. } elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) {
  357. echo '<div class="error notice is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  358. }
  359. ?>
  360. <form method="get">
  361. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  362. </form>
  363. <?php
  364. $wp_list_table->views();
  365. if ( 'broken' === $status ) {
  366. echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
  367. }
  368. ?>
  369. <form id="bulk-action-form" method="post">
  370. <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
  371. <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
  372. <?php $wp_list_table->display(); ?>
  373. </form>
  374. </div>
  375. <?php
  376. wp_print_request_filesystem_credentials_modal();
  377. wp_print_admin_notice_templates();
  378. wp_print_update_row_templates();
  379. require_once ABSPATH . 'wp-admin/admin-footer.php';