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

/wp-admin/themes.php

https://bitbucket.org/abnopanda/wordpress
PHP | 311 lines | 257 code | 44 blank | 10 comment | 60 complexity | 1bbceb4162a5bf38a2a8ffe056ef382b MD5 | raw file
  1. <?php
  2. /**
  3. * Themes administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
  11. wp_die( __( 'Cheatin&#8217; uh?' ) );
  12. $wp_list_table = _get_list_table('WP_Themes_List_Table');
  13. if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
  14. if ( 'activate' == $_GET['action'] ) {
  15. check_admin_referer('switch-theme_' . $_GET['stylesheet']);
  16. $theme = wp_get_theme( $_GET['stylesheet'] );
  17. if ( ! $theme->exists() || ! $theme->is_allowed() )
  18. wp_die( __( 'Cheatin&#8217; uh?' ) );
  19. switch_theme( $theme->get_stylesheet() );
  20. wp_redirect( admin_url('themes.php?activated=true') );
  21. exit;
  22. } elseif ( 'delete' == $_GET['action'] ) {
  23. check_admin_referer('delete-theme_' . $_GET['stylesheet']);
  24. $theme = wp_get_theme( $_GET['stylesheet'] );
  25. if ( !current_user_can('delete_themes') || ! $theme->exists() )
  26. wp_die( __( 'Cheatin&#8217; uh?' ) );
  27. delete_theme($_GET['stylesheet']);
  28. wp_redirect( admin_url('themes.php?deleted=true') );
  29. exit;
  30. }
  31. }
  32. $wp_list_table->prepare_items();
  33. $title = __('Manage Themes');
  34. $parent_file = 'themes.php';
  35. if ( current_user_can( 'switch_themes' ) ) :
  36. $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' .
  37. '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Live Preview link (see "Previewing and Customizing" help tab). To change themes, click the Activate link.') . '</p>';
  38. get_current_screen()->add_help_tab( array(
  39. 'id' => 'overview',
  40. 'title' => __('Overview'),
  41. 'content' => $help_manage
  42. ) );
  43. if ( current_user_can( 'install_themes' ) ) {
  44. if ( is_multisite() ) {
  45. $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
  46. } else {
  47. $help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/' ) . '</p>';
  48. }
  49. get_current_screen()->add_help_tab( array(
  50. 'id' => 'adding-themes',
  51. 'title' => __('Adding Themes'),
  52. 'content' => $help_install
  53. ) );
  54. }
  55. add_thickbox();
  56. endif; // switch_themes
  57. if ( current_user_can( 'edit_theme_options' ) ) {
  58. $help_customize =
  59. '<p>' . __('Click on the "Live Preview" link under any theme to preview that theme and change theme options in a separate, full-screen view. Any installed theme can be previewed and customized in this way.') . '</p>'.
  60. '<p>' . __('The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates.') . '</p>' .
  61. '<p>' . __('In the left-hand pane you can edit the theme settings. The settings will differ, depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the "Save &amp; Activate" button at the top of the left-hand pane.') . '</p>' .
  62. '<p>' . __('When previewing on smaller monitors, you can use the "Collapse" icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the Collapse icon again.') . '</p>';
  63. get_current_screen()->add_help_tab( array(
  64. 'id' => 'customize-preview-themes',
  65. 'title' => __('Previewing and Customizing'),
  66. 'content' => $help_customize
  67. ) );
  68. }
  69. get_current_screen()->set_help_sidebar(
  70. '<p><strong>' . __('For more information:') . '</strong></p>' .
  71. '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
  72. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  73. );
  74. wp_enqueue_script( 'theme' );
  75. wp_enqueue_script( 'customize-loader' );
  76. require_once('./admin-header.php');
  77. ?>
  78. <div class="wrap"><?php
  79. screen_icon();
  80. if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
  81. <h2 class="nav-tab-wrapper">
  82. <a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><a href="<?php echo admin_url( 'theme-install.php'); ?>" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a>
  83. <?php else : ?>
  84. <h2><?php echo esc_html( $title ); ?>
  85. <?php endif; ?>
  86. </h2>
  87. <?php
  88. if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
  89. <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  90. <?php elseif ( isset($_GET['activated']) ) :
  91. if ( isset( $_GET['previewed'] ) ) { ?>
  92. <div id="message2" class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div>
  93. <?php } else { ?>
  94. <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
  95. }
  96. elseif ( isset($_GET['deleted']) ) : ?>
  97. <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
  98. <?php
  99. endif;
  100. $ct = wp_get_theme();
  101. $screenshot = $ct->get_screenshot();
  102. $class = $screenshot ? 'has-screenshot' : '';
  103. $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;' ), $ct->display('Name') );
  104. ?>
  105. <div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
  106. <?php if ( $screenshot ) : ?>
  107. <?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
  108. <a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>">
  109. <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
  110. </a>
  111. <?php endif; ?>
  112. <img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
  113. <?php endif; ?>
  114. <h3><?php _e('Current Theme'); ?></h3>
  115. <h4>
  116. <?php echo $ct->display('Name'); ?>
  117. </h4>
  118. <div>
  119. <ul class="theme-info">
  120. <li><?php printf( __('By %s'), $ct->display('Author') ); ?></li>
  121. <li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li>
  122. </ul>
  123. <p class="theme-description"><?php echo $ct->display('Description'); ?></p>
  124. <?php if ( $ct->parent() ) {
  125. printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
  126. __( 'http://codex.wordpress.org/Child_Themes' ),
  127. $ct->parent()->display( 'Name' ) );
  128. } ?>
  129. <?php theme_update_available( $ct ); ?>
  130. </div>
  131. <?php
  132. // Pretend you didn't see this.
  133. $options = array();
  134. if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
  135. foreach ( (array) $submenu['themes.php'] as $item) {
  136. $class = '';
  137. if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] )
  138. continue;
  139. // 0 = name, 1 = capability, 2 = file
  140. if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
  141. $class = ' class="current"';
  142. if ( !empty($submenu[$item[2]]) ) {
  143. $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
  144. $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
  145. if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
  146. $options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
  147. else
  148. $options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
  149. } else if ( current_user_can($item[1]) ) {
  150. $menu_file = $item[2];
  151. if ( false !== ( $pos = strpos( $menu_file, '?' ) ) )
  152. $menu_file = substr( $menu_file, 0, $pos );
  153. if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
  154. $options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>";
  155. } else {
  156. $options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
  157. }
  158. }
  159. }
  160. }
  161. if ( $options || current_user_can( 'edit_theme_options' ) ) :
  162. ?>
  163. <div class="theme-options">
  164. <?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
  165. <a id="customize-current-theme-link" href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"><?php _e( 'Customize' ); ?></a>
  166. <?php
  167. endif; // edit_theme_options
  168. if ( $options ) :
  169. ?>
  170. <span><?php _e( 'Options:' )?></span>
  171. <ul>
  172. <?php foreach ( $options as $option ) : ?>
  173. <li><?php echo $option; ?></li>
  174. <?php endforeach; ?>
  175. </ul>
  176. <?php
  177. endif; // options
  178. ?>
  179. </div>
  180. <?php
  181. endif; // options || edit_theme_options
  182. ?>
  183. </div>
  184. <br class="clear" />
  185. <?php
  186. if ( ! current_user_can( 'switch_themes' ) ) {
  187. echo '</div>';
  188. require( './admin-footer.php' );
  189. exit;
  190. }
  191. ?>
  192. <form class="search-form filter-form" action="" method="get">
  193. <h3 class="available-themes"><?php _e('Available Themes'); ?></h3>
  194. <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?>
  195. <p class="search-box">
  196. <label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
  197. <input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  198. <?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
  199. <a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
  200. </p>
  201. <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
  202. <?php $feature_list = get_theme_feature_list(); ?>
  203. <div class="feature-filter">
  204. <p class="install-help"><?php _e('Theme filters') ?></p>
  205. <?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
  206. <input type="hidden" name="filter" value="1" />
  207. <?php endif; ?>
  208. <?php foreach ( $feature_list as $feature_name => $features ) :
  209. $feature_name = esc_html( $feature_name ); ?>
  210. <div class="feature-container">
  211. <div class="feature-name"><?php echo $feature_name ?></div>
  212. <ol class="feature-group">
  213. <?php foreach ( $features as $key => $feature ) :
  214. $feature_name = $feature;
  215. $feature_name = esc_html( $feature_name );
  216. $feature = esc_attr( $feature );
  217. ?>
  218. <li>
  219. <input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
  220. <label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
  221. </li>
  222. <?php endforeach; ?>
  223. </ol>
  224. </div>
  225. <?php endforeach; ?>
  226. <div class="feature-container">
  227. <?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?>
  228. &nbsp;
  229. <a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a>
  230. </div>
  231. <br/>
  232. </div>
  233. <br class="clear"/>
  234. </div>
  235. <?php endif; ?>
  236. <br class="clear" />
  237. <?php $wp_list_table->display(); ?>
  238. </form>
  239. <br class="clear" />
  240. <?php
  241. // List broken themes, if any.
  242. if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
  243. ?>
  244. <h3><?php _e('Broken Themes'); ?></h3>
  245. <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
  246. <table id="broken-themes">
  247. <tr>
  248. <th><?php _ex('Name', 'theme name'); ?></th>
  249. <th><?php _e('Description'); ?></th>
  250. </tr>
  251. <?php
  252. $alt = '';
  253. foreach ( $broken_themes as $broken_theme ) {
  254. $alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"';
  255. echo "
  256. <tr $alt>
  257. <td>" . $broken_theme->get('Name') ."</td>
  258. <td>" . $broken_theme->errors()->get_error_message() . "</td>
  259. </tr>";
  260. }
  261. ?>
  262. </table>
  263. <?php
  264. }
  265. ?>
  266. </div>
  267. <?php require('./admin-footer.php'); ?>