PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/themes.php

https://bitbucket.org/aqge/deptandashboard
PHP | 257 lines | 204 code | 42 blank | 11 comment | 50 complexity | 07ee29fae122016936c4e1091366fd6a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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['template']);
  16. switch_theme($_GET['template'], $_GET['stylesheet']);
  17. wp_redirect( admin_url('themes.php?activated=true') );
  18. exit;
  19. } elseif ( 'delete' == $_GET['action'] ) {
  20. check_admin_referer('delete-theme_' . $_GET['template']);
  21. if ( !current_user_can('delete_themes') )
  22. wp_die( __( 'Cheatin&#8217; uh?' ) );
  23. delete_theme($_GET['template']);
  24. wp_redirect( admin_url('themes.php?deleted=true') );
  25. exit;
  26. }
  27. }
  28. $wp_list_table->prepare_items();
  29. $title = __('Manage Themes');
  30. $parent_file = 'themes.php';
  31. if ( current_user_can( 'switch_themes' ) ) :
  32. $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' .
  33. '<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 Preview link. To change themes, click the Activate link.') . '</p>';
  34. get_current_screen()->add_help_tab( array(
  35. 'id' => 'overview',
  36. 'title' => __('Overview'),
  37. 'content' => $help_manage,
  38. ) );
  39. if ( current_user_can( 'install_themes' ) ) {
  40. if ( is_multisite() ) {
  41. $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
  42. } else {
  43. $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>';
  44. }
  45. get_current_screen()->add_help_tab( array(
  46. 'id' => 'adding-themes',
  47. 'title' => __('Adding Themes'),
  48. 'content' => $help_install,
  49. ) );
  50. }
  51. get_current_screen()->set_help_sidebar(
  52. '<p><strong>' . __('For more information:') . '</strong></p>' .
  53. '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
  54. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  55. );
  56. add_thickbox();
  57. wp_enqueue_script( 'theme-preview' );
  58. wp_enqueue_script( 'theme' );
  59. endif;
  60. require_once('./admin-header.php');
  61. ?>
  62. <?php if ( ! validate_current_theme() ) : ?>
  63. <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  64. <?php elseif ( isset($_GET['activated']) ) :
  65. if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
  66. <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
  67. } else { ?>
  68. <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
  69. }
  70. elseif ( isset($_GET['deleted']) ) : ?>
  71. <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
  72. <?php endif; ?>
  73. <div class="wrap"><?php
  74. screen_icon();
  75. if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
  76. <h2 class="nav-tab-wrapper">
  77. <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>
  78. <?php else : ?>
  79. <h2><?php echo esc_html( $title ); ?>
  80. <?php endif; ?>
  81. </h2>
  82. <h3><?php _e('Current Theme'); ?></h3>
  83. <div id="current-theme">
  84. <?php if ( $ct->screenshot ) : ?>
  85. <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php esc_attr_e('Current theme preview'); ?>" />
  86. <?php endif; ?>
  87. <h4><?php
  88. /* translators: 1: theme title, 2: theme version, 3: theme author */
  89. printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
  90. <p class="theme-description"><?php echo $ct->description; ?></p>
  91. <div class="theme-options">
  92. <span><?php _e( 'Options:' )?></span>
  93. <?php
  94. // Pretend you didn't see this.
  95. $options = array();
  96. if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
  97. foreach ( (array) $submenu['themes.php'] as $item) {
  98. $class = '';
  99. if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] )
  100. continue;
  101. // 0 = name, 1 = capability, 2 = file
  102. if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) ) $class = ' class="current"';
  103. if ( !empty($submenu[$item[2]]) ) {
  104. $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
  105. $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
  106. if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
  107. $options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
  108. else
  109. $options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
  110. } else if ( current_user_can($item[1]) ) {
  111. if ( file_exists(ABSPATH . 'wp-admin/' . $item[2]) ) {
  112. $options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>";
  113. } else {
  114. $options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
  115. }
  116. }
  117. }
  118. }
  119. echo implode ( ' | ', $options );
  120. if ( $ct->tags ) : ?>
  121. <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
  122. <?php endif; ?>
  123. </div>
  124. <?php theme_update_available($ct); ?>
  125. </div>
  126. <br class="clear" />
  127. <?php
  128. if ( ! current_user_can( 'switch_themes' ) ) {
  129. echo '</div>';
  130. require( './admin-footer.php' );
  131. exit;
  132. }
  133. ?>
  134. <h3><?php _e('Available Themes'); ?></h3>
  135. <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['filter'] ) || $wp_list_table->has_items() ) : ?>
  136. <form class="search-form filter-form" action="" method="get">
  137. <p class="search-box">
  138. <label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
  139. <input type="text" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  140. <?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
  141. <a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
  142. </p>
  143. <br class="clear"/>
  144. <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
  145. <?php $feature_list = get_theme_feature_list(); ?>
  146. <div class="feature-filter">
  147. <p class="install-help"><?php _e('Theme filters') ?></p>
  148. <?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
  149. <input type="hidden" name="filter" value="1" />
  150. <?php endif; ?>
  151. <?php foreach ( $feature_list as $feature_name => $features ) :
  152. $feature_name = esc_html( $feature_name ); ?>
  153. <div class="feature-container">
  154. <div class="feature-name"><?php echo $feature_name ?></div>
  155. <ol class="feature-group">
  156. <?php foreach ( $features as $key => $feature ) :
  157. $feature_name = $feature;
  158. $feature_name = esc_html( $feature_name );
  159. $feature = esc_attr( $feature );
  160. ?>
  161. <li>
  162. <input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
  163. <label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
  164. </li>
  165. <?php endforeach; ?>
  166. </ol>
  167. </div>
  168. <?php endforeach; ?>
  169. <div class="feature-container">
  170. <?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'style' => 'margin-left: 120px', 'id' => 'filter-submit' ) ); ?>
  171. &nbsp;
  172. <small><a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a></small>
  173. </div>
  174. <br/>
  175. </div>
  176. <br class="clear"/>
  177. </div>
  178. <br class="clear" />
  179. <?php endif; ?>
  180. <?php $wp_list_table->display(); ?>
  181. </form>
  182. <br class="clear" />
  183. <?php
  184. // List broken themes, if any.
  185. $broken_themes = get_broken_themes();
  186. if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
  187. ?>
  188. <h3><?php _e('Broken Themes'); ?></h3>
  189. <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
  190. <table id="broken-themes">
  191. <tr>
  192. <th><?php _ex('Name', 'theme name'); ?></th>
  193. <th><?php _e('Description'); ?></th>
  194. </tr>
  195. <?php
  196. $theme = '';
  197. $theme_names = array_keys($broken_themes);
  198. natcasesort($theme_names);
  199. foreach ($theme_names as $theme_name) {
  200. $title = $broken_themes[$theme_name]['Title'];
  201. $description = $broken_themes[$theme_name]['Description'];
  202. $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
  203. echo "
  204. <tr $theme>
  205. <td>$title</td>
  206. <td>$description</td>
  207. </tr>";
  208. }
  209. ?>
  210. </table>
  211. <?php
  212. }
  213. ?>
  214. </div>
  215. <?php require('./admin-footer.php'); ?>