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

/blog/wp-admin/network/themes.php

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