PageRenderTime 110ms CodeModel.GetById 27ms RepoModel.GetById 3ms app.codeStats 0ms

/wp-admin/network/themes.php

https://bitbucket.org/julianelve/vendor-wordpress
PHP | 273 lines | 221 code | 43 blank | 9 comment | 21 complexity | 138344bed8e5d5c45f6b4d7976d68748 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  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. 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. 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. unset( $themes[ get_option( 'stylesheet' ) ], $themes[ get_option( 'template' ) ] );
  96. if ( empty( $themes ) ) {
  97. wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  98. exit;
  99. }
  100. $files_to_delete = $theme_info = array();
  101. foreach ( $themes as $key => $theme ) {
  102. $theme_info[ $theme ] = wp_get_theme( $theme );
  103. $files_to_delete = array_merge( $files_to_delete, list_files( $theme_info[ $theme ]->get_stylesheet_directory() ) );
  104. }
  105. if ( empty( $themes ) ) {
  106. wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
  107. exit;
  108. }
  109. include(ABSPATH . 'wp-admin/update.php');
  110. $parent_file = 'themes.php';
  111. if ( ! isset( $_REQUEST['verify-delete'] ) ) {
  112. wp_enqueue_script( 'jquery' );
  113. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  114. ?>
  115. <div class="wrap">
  116. <?php
  117. $themes_to_delete = count( $themes );
  118. screen_icon();
  119. echo '<h2>' . _n( 'Delete Theme', 'Delete Themes', $themes_to_delete ) . '</h2>';
  120. ?>
  121. <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>
  122. <p><?php echo _n( 'You are about to remove the following theme:', 'You are about to remove the following themes:', $themes_to_delete ); ?></p>
  123. <ul class="ul-disc">
  124. <?php foreach ( $theme_info as $theme )
  125. echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>'; /* translators: 1: theme name, 2: theme author */ ?>
  126. </ul>
  127. <p><?php _e('Are you sure you wish to delete these themes?'); ?></p>
  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. <?php wp_nonce_field('bulk-themes') ?>
  136. <?php submit_button( _n( 'Yes, Delete this theme', 'Yes, Delete these themes', $themes_to_delete ), 'button', 'submit', false ); ?>
  137. </form>
  138. <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
  139. <?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
  140. </form>
  141. <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>
  142. <div id="files-list" style="display:none;">
  143. <ul class="code">
  144. <?php
  145. foreach ( (array) $files_to_delete as $file )
  146. echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . "/themes", '', $file) ) . '</li>';
  147. ?>
  148. </ul>
  149. </div>
  150. </div>
  151. <?php
  152. require_once(ABSPATH . 'wp-admin/admin-footer.php');
  153. exit;
  154. } // Endif verify-delete
  155. foreach ( $themes as $theme ) {
  156. $delete_result = delete_theme( $theme, esc_url( add_query_arg( array(
  157. 'verify-delete' => 1,
  158. 'action' => 'delete-selected',
  159. 'checked' => $_REQUEST['checked'],
  160. '_wpnonce' => $_REQUEST['_wpnonce']
  161. ), network_admin_url( 'themes.php' ) ) ) );
  162. }
  163. $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
  164. wp_redirect( add_query_arg( array(
  165. 'deleted' => count( $themes ),
  166. 'paged' => $paged,
  167. 's' => $s
  168. ), network_admin_url( 'themes.php' ) ) );
  169. exit;
  170. break;
  171. }
  172. }
  173. $wp_list_table->prepare_items();
  174. add_thickbox();
  175. add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
  176. get_current_screen()->add_help_tab( array(
  177. 'id' => 'overview',
  178. 'title' => __('Overview'),
  179. 'content' =>
  180. '<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>' .
  181. '<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>' .
  182. '<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>'
  183. ) );
  184. get_current_screen()->set_help_sidebar(
  185. '<p><strong>' . __('For more information:') . '</strong></p>' .
  186. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
  187. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  188. );
  189. $title = __('Themes');
  190. $parent_file = 'themes.php';
  191. require_once(ABSPATH . 'wp-admin/admin-header.php');
  192. ?>
  193. <div class="wrap">
  194. <?php screen_icon('themes'); ?>
  195. <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 }
  196. if ( $s )
  197. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
  198. </h2>
  199. <?php
  200. if ( isset( $_GET['enabled'] ) ) {
  201. $_GET['enabled'] = absint( $_GET['enabled'] );
  202. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme enabled.', '%s themes enabled.', $_GET['enabled'] ), number_format_i18n( $_GET['enabled'] ) ) . '</p></div>';
  203. } elseif ( isset( $_GET['disabled'] ) ) {
  204. $_GET['disabled'] = absint( $_GET['disabled'] );
  205. echo '<div id="message" class="updated"><p>' . sprintf( _n( 'Theme disabled.', '%s themes disabled.', $_GET['disabled'] ), number_format_i18n( $_GET['disabled'] ) ) . '</p></div>';
  206. } elseif ( isset( $_GET['deleted'] ) ) {
  207. $_GET['deleted'] = absint( $_GET['deleted'] );
  208. echo '<div id="message" class="updated"><p>' . sprintf( _nx( 'Theme deleted.', '%s themes deleted.', $_GET['deleted'], 'network' ), number_format_i18n( $_GET['deleted'] ) ) . '</p></div>';
  209. } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
  210. echo '<div id="message" class="error"><p>' . __( 'No theme selected.' ) . '</p></div>';
  211. } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
  212. echo '<div class="error"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
  213. }
  214. ?>
  215. <form method="get" action="">
  216. <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
  217. </form>
  218. <?php
  219. $wp_list_table->views();
  220. if ( 'broken' == $status )
  221. echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>';
  222. ?>
  223. <form method="post" action="">
  224. <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
  225. <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
  226. <?php $wp_list_table->display(); ?>
  227. </form>
  228. </div>
  229. <?php
  230. include(ABSPATH . 'wp-admin/admin-footer.php');