PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/themes.php

https://gitlab.com/woxiprogrammers/infinia-wordpress
PHP | 291 lines | 231 code | 48 blank | 12 comment | 23 complexity | 26b094140c6e6d5a6f3d7f4fdf7bc36f 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 '<h2>' . esc_html( $title ) . '</h2>';
  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. ?>
  124. <div class="wrap">
  125. <?php
  126. $themes_to_delete = count( $themes );
  127. echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
  128. ?>
  129. <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This theme may be active on other sites in the network.', 'These themes may be active on other sites in the network.', $themes_to_delete ); ?></p></div>
  130. <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
  131. <ul class="ul-disc">
  132. <?php
  133. foreach ( $theme_info as $theme ) {
  134. /* translators: 1: theme name, 2: theme author */
  135. echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>';
  136. }
  137. ?>
  138. </ul>
  139. <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
  140. <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
  141. <input type="hidden" name="verify-delete" value="1" />
  142. <input type="hidden" name="action" value="delete-selected" />
  143. <?php
  144. foreach ( (array) $themes as $theme ) {
  145. echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
  146. }
  147. ?>
  148. <?php wp_nonce_field('bulk-themes') ?>
  149. <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
  150. </form>
  151. <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
  152. <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
  153. </form>
  154. <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>
  155. <div id="files-list" style="display:none;">
  156. <ul class="code">
  157. <?php
  158. foreach ( (array) $files_to_delete as $file ) {
  159. echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . '/themes', '', $file ) ) . '</li>';
  160. }
  161. ?>
  162. </ul>
  163. </div>
  164. </div>
  165. <?php
  166. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  167. exit;
  168. } // Endif verify-delete
  169. foreach ( $themes as $theme ) {
  170. $delete_result = delete_theme( $theme, esc_url( add_query_arg( array(
  171. 'verify-delete' => 1,
  172. 'action' => 'delete-selected',
  173. 'checked' => $_REQUEST['checked'],
  174. '_wpnonce' => $_REQUEST['_wpnonce']
  175. ), network_admin_url( 'themes.php' ) ) ) );
  176. }
  177. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  178. wp_redirect( add_query_arg( array(
  179. 'deleted' => count( $themes ),
  180. 'paged' => $paged,
  181. 's' => $s
  182. ), network_admin_url( 'themes.php' ) ) );
  183. exit;
  184. }
  185. }
  186. $wp_list_table->prepare_items();
  187. add_thickbox();
  188. add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
  189. get_current_screen()->add_help_tab( array(
  190. 'id' => 'overview',
  191. 'title' => __('Overview'),
  192. 'content' =>
  193. '<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>' .
  194. '<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>' .
  195. '<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>'
  196. ) );
  197. get_current_screen()->set_help_sidebar(
  198. '<p><strong>' . __('For more information:') . '</strong></p>' .
  199. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
  200. '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  201. );
  202. $title = __('Themes');
  203. $parent_file = 'themes.php';
  204. wp_enqueue_script( 'theme-preview' );
  205. require_once(ABSPATH . 'wp-admin/admin-header.php');
  206. ?>
  207. <div class="wrap">
  208. <h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
  209. if ( $s )
  210. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
  211. </h2>
  212. <?php
  213. if ( isset( $_GET['enabled'] ) ) {
  214. $_GET['enabled'] = absint( $_GET['enabled'] );
  215. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
  216. } elseif ( isset( $_GET['disabled'] ) ) {
  217. $_GET['disabled'] = absint( $_GET['disabled'] );
  218. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
  219. } elseif ( isset( $_GET['deleted'] ) ) {
  220. $_GET['deleted'] = absint( $_GET['deleted'] );
  221. echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
  222. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  223. echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
  224. } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
  225. echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  226. }
  227. ?>
  228. <form method="get" action="">
  229. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  230. </form>
  231. <?php
  232. $wp_list_table->views();
  233. if ( 'broken' == $status )
  234. echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>';
  235. ?>
  236. <form method="post" action="">
  237. <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
  238. <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
  239. <?php $wp_list_table->display(); ?>
  240. </form>
  241. </div>
  242. <?php
  243. include(ABSPATH . 'wp-admin/admin-footer.php');