PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/themes.php

https://bitbucket.org/aqge/deptandashboard
PHP | 269 lines | 216 code | 44 blank | 9 comment | 25 complexity | 8d1b41e632baa9c676191f6ee2d212d0 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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( './admin.php' );
  11. if ( ! is_multisite() )
  12. wp_die( __( 'Multisite support is not enabled.' ) );
  13. $menu_perms = get_site_option( 'menu_items', array() );
  14. if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
  15. wp_die( __( 'Cheatin&#8217; uh?' ) );
  16. if ( !current_user_can('manage_network_themes') )
  17. wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
  18. $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
  19. $pagenum = $wp_list_table->get_pagenum();
  20. $action = $wp_list_table->current_action();
  21. $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
  22. // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  23. $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
  24. $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  25. $referer = remove_query_arg( $temp_args, wp_get_referer() );
  26. if ( $action ) {
  27. $allowed_themes = get_site_option( 'allowedthemes' );
  28. switch ( $action ) {
  29. case 'enable':
  30. check_admin_referer('enable-theme_' . $_GET['theme']);
  31. $allowed_themes[ $_GET['theme'] ] = true;
  32. update_site_option( 'allowedthemes', $allowed_themes );
  33. wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  34. exit;
  35. break;
  36. case 'disable':
  37. check_admin_referer('disable-theme_' . $_GET['theme']);
  38. unset( $allowed_themes[ $_GET['theme'] ] );
  39. update_site_option( 'allowedthemes', $allowed_themes );
  40. wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  41. exit;
  42. break;
  43. case 'enable-selected':
  44. check_admin_referer('bulk-themes');
  45. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  46. if ( empty($themes) ) {
  47. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  48. exit;
  49. }
  50. foreach( (array) $themes as $theme )
  51. $allowed_themes[ $theme ] = true;
  52. update_site_option( 'allowedthemes', $allowed_themes );
  53. wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  54. exit;
  55. break;
  56. case 'disable-selected':
  57. check_admin_referer('bulk-themes');
  58. $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  59. if ( empty($themes) ) {
  60. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  61. exit;
  62. }
  63. foreach( (array) $themes as $theme )
  64. unset( $allowed_themes[ $theme ] );
  65. update_site_option( 'allowedthemes', $allowed_themes );
  66. wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  67. exit;
  68. break;
  69. case 'update-selected' :
  70. check_admin_referer( 'bulk-themes' );
  71. if ( isset( $_GET['themes'] ) )
  72. $themes = explode( ',', $_GET['themes'] );
  73. elseif ( isset( $_POST['checked'] ) )
  74. $themes = (array) $_POST['checked'];
  75. else
  76. $themes = array();
  77. $title = __( 'Update Themes' );
  78. $parent_file = 'themes.php';
  79. require_once(ABSPATH . 'wp-admin/admin-header.php');
  80. echo '<div class="wrap">';
  81. screen_icon();
  82. echo '<h2>' . esc_html( $title ) . '</h2>';
  83. $url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
  84. $url = wp_nonce_url($url, 'bulk-update-themes');
  85. echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  86. echo '</div>';
  87. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  88. exit;
  89. break;
  90. case 'delete-selected':
  91. if ( ! current_user_can( 'delete_themes' ) )
  92. wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
  93. check_admin_referer( 'bulk-themes' );
  94. $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  95. if ( isset( $themes[ get_option( 'template' ) ] ) )
  96. unset( $themes[ get_option( 'template' ) ] );
  97. if ( isset( $themes[ get_option( 'stylesheet' ) ] ) )
  98. unset( $themes[ get_option( 'stylesheet' ) ] );
  99. if ( empty( $themes ) ) {
  100. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  101. exit;
  102. }
  103. $main_theme = get_current_theme();
  104. $files_to_delete = $theme_info = array();
  105. foreach ( $themes as $key => $theme ) {
  106. $data = get_theme_data( WP_CONTENT_DIR . '/themes/' . $theme . '/style.css' );
  107. if ( $data['Name'] == $main_theme ) {
  108. unset( $themes[$key] );
  109. } else {
  110. $files_to_delete = array_merge( $files_to_delete, list_files( WP_CONTENT_DIR . "/themes/$theme" ) );
  111. $theme_info[ $theme ] = $data;
  112. }
  113. }
  114. if ( empty( $themes ) ) {
  115. wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
  116. exit;
  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. screen_icon();
  128. echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
  129. ?>
  130. <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>
  131. <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
  132. <ul class="ul-disc">
  133. <?php foreach ( $theme_info as $theme )
  134. echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), esc_html( $theme['Name'] ), esc_html( $theme['AuthorName'] ) ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?>
  135. </ul>
  136. <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
  137. <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
  138. <input type="hidden" name="verify-delete" value="1" />
  139. <input type="hidden" name="action" value="delete-selected" />
  140. <?php
  141. foreach ( (array) $themes as $theme )
  142. echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
  143. ?>
  144. <?php wp_nonce_field('bulk-themes') ?>
  145. <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
  146. </form>
  147. <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
  148. <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
  149. </form>
  150. <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>
  151. <div id="files-list" style="display:none;">
  152. <ul class="code">
  153. <?php
  154. foreach ( (array) $files_to_delete as $file )
  155. echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
  156. ?>
  157. </ul>
  158. </div>
  159. </div>
  160. <?php
  161. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  162. exit;
  163. } // Endif verify-delete
  164. foreach ( $themes as $theme )
  165. $delete_result = delete_theme( $theme, esc_url( add_query_arg( array('verify-delete' => 1), $_SERVER['REQUEST_URI'] ) ) );
  166. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  167. wp_redirect( network_admin_url( "themes.php?deleted=".count( $themes )."&paged=$paged&s=$s" ) );
  168. exit;
  169. break;
  170. }
  171. }
  172. $wp_list_table->prepare_items();
  173. add_thickbox();
  174. add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
  175. get_current_screen()->add_help_tab( array(
  176. 'id' => 'overview',
  177. 'title' => __('Overview'),
  178. 'content' =>
  179. '<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>' .
  180. '<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>' .
  181. '<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>'
  182. ) );
  183. get_current_screen()->set_help_sidebar(
  184. '<p><strong>' . __('For more information:') . '</strong></p>' .
  185. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
  186. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  187. );
  188. $title = __('Themes');
  189. $parent_file = 'themes.php';
  190. require_once(ABSPATH . 'wp-admin/admin-header.php');
  191. ?>
  192. <div class="wrap">
  193. <?php screen_icon('themes'); ?>
  194. <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 }
  195. if ( $s )
  196. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
  197. </h2>
  198. <?php
  199. if ( isset( $_GET['enabled'] ) ) {
  200. $_GET['enabled'] = absint( $_GET['enabled'] );
  201. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
  202. } elseif ( isset( $_GET['disabled'] ) ) {
  203. $_GET['disabled'] = absint( $_GET['disabled'] );
  204. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
  205. } elseif ( isset( $_GET['deleted'] ) ) {
  206. $_GET['deleted'] = absint( $_GET['deleted'] );
  207. echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
  208. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  209. echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
  210. } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
  211. echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  212. }
  213. ?>
  214. <form method="get" action="">
  215. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  216. </form>
  217. <?php $wp_list_table->views(); ?>
  218. <form method="post" action="">
  219. <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
  220. <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
  221. <?php $wp_list_table->display(); ?>
  222. </form>
  223. </div>
  224. <?php
  225. include(ABSPATH . 'wp-admin/admin-footer.php');