PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/themes.php

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