]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/themes.php
WordPress 3.4.2
[autoinstalls/wordpress.git] / wp-admin / themes.php
1 <?php
2 /**
3  * Themes administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
11
12 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
13         wp_die( __( 'Cheatin&#8217; uh?' ) );
14
15 $wp_list_table = _get_list_table('WP_Themes_List_Table');
16
17 if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
18         if ( 'activate' == $_GET['action'] ) {
19                 check_admin_referer('switch-theme_' . $_GET['stylesheet']);
20                 $theme = wp_get_theme( $_GET['stylesheet'] );
21                 if ( ! $theme->exists() || ! $theme->is_allowed() )
22                         wp_die( __( 'Cheatin&#8217; uh?' ) );
23                 switch_theme( $theme->get_template(), $theme->get_stylesheet() );
24                 wp_redirect( admin_url('themes.php?activated=true') );
25                 exit;
26         } elseif ( 'delete' == $_GET['action'] ) {
27                 check_admin_referer('delete-theme_' . $_GET['stylesheet']);
28                 $theme = wp_get_theme( $_GET['stylesheet'] );
29                 if ( !current_user_can('delete_themes') || ! $theme->exists() )
30                         wp_die( __( 'Cheatin&#8217; uh?' ) );
31                 delete_theme($_GET['stylesheet']);
32                 wp_redirect( admin_url('themes.php?deleted=true') );
33                 exit;
34         }
35 }
36
37 $wp_list_table->prepare_items();
38
39 $title = __('Manage Themes');
40 $parent_file = 'themes.php';
41
42 if ( current_user_can( 'switch_themes' ) ) :
43
44 $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' .
45         '<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>';
46
47 get_current_screen()->add_help_tab( array(
48         'id'      => 'overview',
49         'title'   => __('Overview'),
50         'content' => $help_manage
51 ) );
52
53 if ( current_user_can( 'install_themes' ) ) {
54         if ( is_multisite() ) {
55                 $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
56         } else {
57                 $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>';
58         }
59
60         get_current_screen()->add_help_tab( array(
61                 'id'      => 'adding-themes',
62                 'title'   => __('Adding Themes'),
63                 'content' => $help_install
64         ) );
65 }
66
67 add_thickbox();
68
69 endif; // switch_themes
70
71 if ( current_user_can( 'edit_theme_options' ) ) {
72         $help_customize =
73                 '<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>'.
74                 '<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>' .
75                 '<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>' .
76                 '<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>';
77
78         get_current_screen()->add_help_tab( array(
79                 'id'            => 'customize-preview-themes',
80                 'title'         => __('Previewing and Customizing'),
81                 'content'       => $help_customize
82         ) );
83 }
84
85 get_current_screen()->set_help_sidebar(
86         '<p><strong>' . __('For more information:') . '</strong></p>' .
87         '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
88         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
89 );
90
91 wp_enqueue_script( 'theme' );
92 wp_enqueue_script( 'customize-loader' );
93
94 require_once('./admin-header.php');
95 ?>
96
97 <div class="wrap"><?php
98 screen_icon();
99 if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
100 <h2 class="nav-tab-wrapper">
101 <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>
102 <?php else : ?>
103 <h2><?php echo esc_html( $title ); ?>
104 <?php endif; ?>
105 </h2>
106 <?php
107 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
108 <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
109 <?php elseif ( isset($_GET['activated']) ) :
110                 if ( isset( $_GET['previewed'] ) ) { ?>
111                 <div id="message2" class="updated"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>.' ), home_url( '/' ) ); ?></p></div>
112                 <?php } elseif ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
113 <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
114                 } else { ?>
115 <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
116                 }
117         elseif ( isset($_GET['deleted']) ) : ?>
118 <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
119 <?php
120 endif;
121
122 $ct = wp_get_theme();
123 $screenshot = $ct->get_screenshot();
124 $class = $screenshot ? 'has-screenshot' : '';
125
126 $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;' ), $ct->display('Name') );
127
128 ?>
129 <div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
130         <?php if ( $screenshot ) : ?>
131                 <?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
132                 <a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>">
133                         <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
134                 </a>
135                 <?php endif; ?>
136                 <img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
137         <?php endif; ?>
138
139         <h3><?php _e('Current Theme'); ?></h3>
140         <h4>
141                 <?php echo $ct->display('Name'); ?>
142         </h4>
143
144         <div>
145                 <ul class="theme-info">
146                         <li><?php printf( __('By %s'), $ct->display('Author') ); ?></li>
147                         <li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li>
148                 </ul>
149                 <p class="theme-description"><?php echo $ct->display('Description'); ?></p>
150                 <?php theme_update_available( $ct ); ?>
151         </div>
152
153         <?php
154         // Pretend you didn't see this.
155         $options = array();
156         if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
157                 foreach ( (array) $submenu['themes.php'] as $item) {
158                         $class = '';
159                         if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] )
160                                 continue;
161                         // 0 = name, 1 = capability, 2 = file
162                         if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
163                                 $class = ' class="current"';
164                         if ( !empty($submenu[$item[2]]) ) {
165                                 $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
166                                 $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
167                                 if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
168                                         $options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
169                                 else
170                                         $options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
171                         } else if ( current_user_can($item[1]) ) {
172                                 if ( file_exists(ABSPATH . 'wp-admin/' . $item[2]) ) {
173                                         $options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>";
174                                 } else {
175                                         $options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
176                                 }
177                         }
178                 }
179         }
180
181         if ( $options || current_user_can( 'edit_theme_options' ) ) :
182         ?>
183         <div class="theme-options">
184                 <?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
185                 <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>
186                 <?php
187                 endif; // edit_theme_options
188                 if ( $options ) :
189                 ?>
190                 <span><?php _e( 'Options:' )?></span>
191                 <ul>
192                         <?php foreach ( $options as $option ) : ?>
193                                 <li><?php echo $option; ?></li>
194                         <?php endforeach; ?>
195                 </ul>
196         </div>
197         <?php
198                 endif; // options
199         endif; // options || edit_theme_options
200         ?>
201
202 </div>
203
204 <br class="clear" />
205 <?php
206 if ( ! current_user_can( 'switch_themes' ) ) {
207         echo '</div>';
208         require( './admin-footer.php' );
209         exit;
210 }
211 ?>
212
213 <form class="search-form filter-form" action="" method="get">
214
215 <h3 class="available-themes"><?php _e('Available Themes'); ?></h3>
216
217 <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?>
218
219 <p class="search-box">
220         <label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
221         <input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
222         <?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
223         <a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
224 </p>
225
226 <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
227 <?php $feature_list = get_theme_feature_list(); ?>
228         <div class="feature-filter">
229                 <p class="install-help"><?php _e('Theme filters') ?></p>
230         <?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
231                 <input type="hidden" name="filter" value="1" />
232         <?php endif; ?>
233         <?php foreach ( $feature_list as $feature_name => $features ) :
234                         $feature_name = esc_html( $feature_name ); ?>
235
236                 <div class="feature-container">
237                         <div class="feature-name"><?php echo $feature_name ?></div>
238
239                         <ol class="feature-group">
240                                 <?php foreach ( $features as $key => $feature ) :
241                                                 $feature_name = $feature;
242                                                 $feature_name = esc_html( $feature_name );
243                                                 $feature = esc_attr( $feature );
244                                                 ?>
245                                 <li>
246                                         <input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
247                                         <label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
248                                 </li>
249                                 <?php endforeach; ?>
250                         </ol>
251                 </div>
252         <?php endforeach; ?>
253
254         <div class="feature-container">
255                 <?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?>
256                 &nbsp;
257                 <a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a>
258         </div>
259         <br/>
260         </div>
261         <br class="clear"/>
262 </div>
263
264 <?php endif; ?>
265
266 <br class="clear" />
267
268 <?php $wp_list_table->display(); ?>
269
270 </form>
271 <br class="clear" />
272
273 <?php
274 // List broken themes, if any.
275 if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
276 ?>
277
278 <h3><?php _e('Broken Themes'); ?></h3>
279 <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
280
281 <table id="broken-themes">
282         <tr>
283                 <th><?php _ex('Name', 'theme name'); ?></th>
284                 <th><?php _e('Description'); ?></th>
285         </tr>
286 <?php
287         $alt = '';
288         foreach ( $broken_themes as $broken_theme ) {
289                 $alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"';
290                 echo "
291                 <tr $alt>
292                          <td>" . $broken_theme->get('Name') ."</td>
293                          <td>" . $broken_theme->errors()->get_error_message() . "</td>
294                 </tr>";
295         }
296 ?>
297 </table>
298 <?php
299 }
300 ?>
301 </div>
302
303 <?php require('./admin-footer.php'); ?>