WordPress 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( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
13         wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
14
15 if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
16         if ( 'activate' == $_GET['action'] ) {
17                 check_admin_referer('switch-theme_' . $_GET['stylesheet']);
18                 $theme = wp_get_theme( $_GET['stylesheet'] );
19                 if ( ! $theme->exists() || ! $theme->is_allowed() )
20                         wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
21                 switch_theme( $theme->get_stylesheet() );
22                 wp_redirect( admin_url('themes.php?activated=true') );
23                 exit;
24         } elseif ( 'delete' == $_GET['action'] ) {
25                 check_admin_referer('delete-theme_' . $_GET['stylesheet']);
26                 $theme = wp_get_theme( $_GET['stylesheet'] );
27                 if ( !current_user_can('delete_themes') || ! $theme->exists() )
28                         wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
29                 $active = wp_get_theme();
30                 if ( $active->get( 'Template' ) == $_GET['stylesheet'] ) {
31                         wp_redirect( admin_url( 'themes.php?delete-active-child=true' ) );
32                 } else {
33                         delete_theme( $_GET['stylesheet'] );
34                         wp_redirect( admin_url( 'themes.php?deleted=true' ) );
35                 }
36                 exit;
37         }
38 }
39
40 $title = __('Manage Themes');
41 $parent_file = 'themes.php';
42
43 // Help tab: Overview
44 if ( current_user_can( 'switch_themes' ) ) {
45         $help_overview  = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
46                 '<p>' . __( 'From this screen you can:' ) . '</p>' .
47                 '<ul><li>' . __( 'Hover or tap to see Activate and Live Preview buttons' ) . '</li>' .
48                 '<li>' . __( 'Click on the theme to see the theme name, version, author, description, tags, and the Delete link' ) . '</li>' .
49                 '<li>' . __( 'Click Customize for the current theme or Live Preview for any other theme to see a live preview' ) . '</li></ul>' .
50                 '<p>' . __( 'The current theme is displayed highlighted as the first theme.' ) . '</p>' .
51                 '<p>' . __( 'The search for installed themes will search for terms in their name, description, author, or tag.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>';
52
53         get_current_screen()->add_help_tab( array(
54                 'id'      => 'overview',
55                 'title'   => __( 'Overview' ),
56                 'content' => $help_overview
57         ) );
58 } // switch_themes
59
60 // Help tab: Adding Themes
61 if ( current_user_can( 'install_themes' ) ) {
62         if ( is_multisite() ) {
63                 $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
64         } else {
65                 $help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button 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!'), 'https://wordpress.org/themes/' ) . '</p>';
66         }
67
68         get_current_screen()->add_help_tab( array(
69                 'id'      => 'adding-themes',
70                 'title'   => __('Adding Themes'),
71                 'content' => $help_install
72         ) );
73 } // install_themes
74
75 // Help tab: Previewing and Customizing
76 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
77         $help_customize =
78                 '<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>'.
79                 '<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. The settings may 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 above the menu.' ) . '</p>' .
80                 '<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>';
81
82         get_current_screen()->add_help_tab( array(
83                 'id'            => 'customize-preview-themes',
84                 'title'         => __( 'Previewing and Customizing' ),
85                 'content'       => $help_customize
86         ) );
87 } // edit_theme_options && customize
88
89 get_current_screen()->set_help_sidebar(
90         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
91         '<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>' ) . '</p>' .
92         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
93 );
94
95 if ( current_user_can( 'switch_themes' ) ) {
96         $themes = wp_prepare_themes_for_js();
97 } else {
98         $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
99 }
100 wp_reset_vars( array( 'theme', 'search' ) );
101
102 wp_localize_script( 'theme', '_wpThemeSettings', array(
103         'themes'   => $themes,
104         'settings' => array(
105                 'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
106                 'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
107                 'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
108                 'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
109         ),
110         'l10n' => array(
111                 'addNew'            => __( 'Add New Theme' ),
112                 'search'            => __( 'Search Installed Themes' ),
113                 'searchPlaceholder' => __( 'Search installed themes...' ), // placeholder (no ellipsis)
114                 'themesFound'       => __( 'Number of Themes found: %d' ),
115                 'noThemesFound'     => __( 'No themes found. Try a different search.' ),
116         ),
117 ) );
118
119 add_thickbox();
120 wp_enqueue_script( 'theme' );
121 wp_enqueue_script( 'customize-loader' );
122
123 require_once( ABSPATH . 'wp-admin/admin-header.php' );
124 ?>
125
126 <div class="wrap">
127         <h2><?php esc_html_e( 'Themes' ); ?>
128                 <span class="title-count theme-count"><?php echo count( $themes ); ?></span>
129         <?php if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
130                 <a href="<?php echo admin_url( 'theme-install.php' ); ?>" class="hide-if-no-js add-new-h2"><?php echo esc_html_x( 'Add New', 'Add new theme' ); ?></a>
131         <?php endif; ?>
132         </h2>
133 <?php
134 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
135 <div id="message1" class="updated notice is-dismissible"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
136 <?php elseif ( isset($_GET['activated']) ) :
137                 if ( isset( $_GET['previewed'] ) ) { ?>
138                 <div id="message2" class="updated notice is-dismissible"><p><?php printf( __( 'Settings saved and theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div>
139                 <?php } else { ?>
140 <div id="message2" class="updated notice is-dismissible"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
141                 }
142         elseif ( isset($_GET['deleted']) ) : ?>
143 <div id="message3" class="updated notice is-dismissible"><p><?php _e('Theme deleted.') ?></p></div>
144 <?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
145         <div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
146 <?php
147 endif;
148
149 $ct = wp_get_theme();
150
151 if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
152         echo '<div class="error"><p>' . sprintf( __( 'ERROR: %s' ), $ct->errors()->get_error_message() ) . '</p></div>';
153 }
154
155 /*
156 // Certain error codes are less fatal than others. We can still display theme information in most cases.
157 if ( ! $ct->errors() || ( 1 == count( $ct->errors()->get_error_codes() )
158         && in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
159 */
160
161         // Pretend you didn't see this.
162         $current_theme_actions = array();
163         if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
164                 foreach ( (array) $submenu['themes.php'] as $item) {
165                         $class = '';
166                         if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] || 0 === strpos( $item[2], 'customize.php' ) )
167                                 continue;
168                         // 0 = name, 1 = capability, 2 = file
169                         if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
170                                 $class = ' current';
171                         if ( !empty($submenu[$item[2]]) ) {
172                                 $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
173                                 $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
174                                 if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
175                                         $current_theme_actions[] = "<a class='button button-secondary$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
176                                 else
177                                         $current_theme_actions[] = "<a class='button button-secondary$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
178                         } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
179                                 $menu_file = $item[2];
180
181                                 if ( current_user_can( 'customize' ) ) {
182                                         if ( 'custom-header' === $menu_file ) {
183                                                 $current_theme_actions[] = "<a class='button button-secondary hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
184                                         } elseif ( 'custom-background' === $menu_file ) {
185                                                 $current_theme_actions[] = "<a class='button button-secondary hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
186                                         }
187                                 }
188
189                                 if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
190                                         $menu_file = substr( $menu_file, 0, $pos );
191                                 }
192
193                                 if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
194                                         $current_theme_actions[] = "<a class='button button-secondary$class' href='{$item[2]}'>{$item[0]}</a>";
195                                 } else {
196                                         $current_theme_actions[] = "<a class='button button-secondary$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
197                                 }
198                         }
199                 }
200         }
201
202 ?>
203
204 <div class="theme-browser">
205         <div class="themes">
206
207 <?php
208 /*
209  * This PHP is synchronized with the tmpl-theme template below!
210  */
211
212 foreach ( $themes as $theme ) :
213         $aria_action = esc_attr( $theme['id'] . '-action' );
214         $aria_name   = esc_attr( $theme['id'] . '-name' );
215         ?>
216 <div class="theme<?php if ( $theme['active'] ) echo ' active'; ?>" tabindex="0" aria-describedby="<?php echo $aria_action . ' ' . $aria_name; ?>">
217         <?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
218                 <div class="theme-screenshot">
219                         <img src="<?php echo $theme['screenshot'][0]; ?>" alt="" />
220                 </div>
221         <?php } else { ?>
222                 <div class="theme-screenshot blank"></div>
223         <?php } ?>
224         <span class="more-details" id="<?php echo $aria_action; ?>"><?php _e( 'Theme Details' ); ?></span>
225         <div class="theme-author"><?php printf( __( 'By %s' ), $theme['author'] ); ?></div>
226
227         <?php if ( $theme['active'] ) { ?>
228                 <h3 class="theme-name" id="<?php echo $aria_name; ?>">
229                         <?php
230                         /* translators: %s: theme name */
231                         printf( __( '<span>Active:</span> %s' ), $theme['name'] );
232                         ?>
233                 </h3>
234         <?php } else { ?>
235                 <h3 class="theme-name" id="<?php echo $aria_name; ?>"><?php echo $theme['name']; ?></h3>
236         <?php } ?>
237
238         <div class="theme-actions">
239
240         <?php if ( $theme['active'] ) { ?>
241                 <?php if ( $theme['actions']['customize'] && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
242                         <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
243                 <?php } ?>
244         <?php } else { ?>
245                 <a class="button button-secondary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
246                 <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
247                         <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
248                         <a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
249                 <?php } ?>
250         <?php } ?>
251
252         </div>
253
254         <?php if ( $theme['hasUpdate'] ) { ?>
255                 <div class="theme-update"><?php _e( 'Update Available' ); ?></div>
256         <?php } ?>
257 </div>
258 <?php endforeach; ?>
259         <br class="clear" />
260         </div>
261 </div>
262 <div class="theme-overlay"></div>
263
264 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
265
266 <?php
267 // List broken themes, if any.
268 if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
269 ?>
270
271 <div class="broken-themes">
272 <h3><?php _e('Broken Themes'); ?></h3>
273 <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
274
275 <?php
276 $can_delete = current_user_can( 'delete_themes' );
277 ?>
278 <table>
279         <tr>
280                 <th><?php _ex('Name', 'theme name'); ?></th>
281                 <th><?php _e('Description'); ?></th>
282                 <?php if ( $can_delete ) { ?>
283                         <th></th>
284                 <?php } ?>
285                 </tr>
286         </tr>
287         <?php foreach ( $broken_themes as $broken_theme ) : ?>
288                 <tr>
289                         <td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : $broken_theme->get_stylesheet(); ?></td>
290                         <td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
291                         <?php
292                         if ( $can_delete ) {
293                                 $stylesheet = $broken_theme->get_stylesheet();
294                                 $delete_url = add_query_arg( array(
295                                         'action'     => 'delete',
296                                         'stylesheet' => urlencode( $stylesheet ),
297                                 ), admin_url( 'themes.php' ) );
298                                 $delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
299                                 ?>
300                                 <td><a href="<?php echo esc_url( $delete_url ); ?>" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a></td>
301                                 <?php
302                         }
303                         ?>
304                 </tr>
305         <?php endforeach; ?>
306 </table>
307 </div>
308
309 <?php
310 }
311 ?>
312 </div><!-- .wrap -->
313
314 <?php
315 /*
316  * The tmpl-theme template is synchronized with PHP above!
317  */
318 ?>
319 <script id="tmpl-theme" type="text/template">
320         <# if ( data.screenshot[0] ) { #>
321                 <div class="theme-screenshot">
322                         <img src="{{ data.screenshot[0] }}" alt="" />
323                 </div>
324         <# } else { #>
325                 <div class="theme-screenshot blank"></div>
326         <# } #>
327         <span class="more-details" id="{{ data.id }}-action"><?php _e( 'Theme Details' ); ?></span>
328         <div class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.author }}}' ); ?></div>
329
330         <# if ( data.active ) { #>
331                 <h3 class="theme-name" id="{{ data.id }}-name">
332                         <?php
333                         /* translators: %s: theme name */
334                         printf( __( '<span>Active:</span> %s' ), '{{ data.name }}' );
335                         ?>
336                 </h3>
337         <# } else { #>
338                 <h3 class="theme-name" id="{{ data.id }}-name">{{{ data.name }}}</h3>
339         <# } #>
340
341         <div class="theme-actions">
342
343         <# if ( data.active ) { #>
344                 <# if ( data.actions.customize ) { #>
345                         <a class="button button-primary customize load-customize hide-if-no-customize" href="{{ data.actions.customize }}"><?php _e( 'Customize' ); ?></a>
346                 <# } #>
347         <# } else { #>
348                 <a class="button button-secondary activate" href="{{{ data.actions.activate }}}"><?php _e( 'Activate' ); ?></a>
349                 <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
350                 <a class="button button-secondary hide-if-customize" href="{{{ data.actions.preview }}}"><?php _e( 'Preview' ); ?></a>
351         <# } #>
352
353         </div>
354
355         <# if ( data.hasUpdate ) { #>
356                 <div class="theme-update"><?php _e( 'Update Available' ); ?></div>
357         <# } #>
358 </script>
359
360 <script id="tmpl-theme-single" type="text/template">
361         <div class="theme-backdrop"></div>
362         <div class="theme-wrap">
363                 <div class="theme-header">
364                         <button class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button>
365                         <button class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button>
366                         <button class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close overlay' ); ?></span></button>
367                 </div>
368                 <div class="theme-about">
369                         <div class="theme-screenshots">
370                         <# if ( data.screenshot[0] ) { #>
371                                 <div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
372                         <# } else { #>
373                                 <div class="screenshot blank"></div>
374                         <# } #>
375                         </div>
376
377                         <div class="theme-info">
378                                 <# if ( data.active ) { #>
379                                         <span class="current-label"><?php _e( 'Current Theme' ); ?></span>
380                                 <# } #>
381                                 <h3 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h3>
382                                 <h4 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h4>
383
384                                 <# if ( data.hasUpdate ) { #>
385                                 <div class="theme-update-message">
386                                         <h4 class="theme-update"><?php _e( 'Update Available' ); ?></h4>
387                                         {{{ data.update }}}
388                                 </div>
389                                 <# } #>
390                                 <p class="theme-description">{{{ data.description }}}</p>
391
392                                 <# if ( data.parent ) { #>
393                                         <p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p>
394                                 <# } #>
395
396                                 <# if ( data.tags ) { #>
397                                         <p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p>
398                                 <# } #>
399                         </div>
400                 </div>
401
402                 <div class="theme-actions">
403                         <div class="active-theme">
404                                 <a href="{{{ data.actions.customize }}}" class="button button-primary customize load-customize hide-if-no-customize"><?php _e( 'Customize' ); ?></a>
405                                 <?php echo implode( ' ', $current_theme_actions ); ?>
406                         </div>
407                         <div class="inactive-theme">
408                                 <# if ( data.actions.activate ) { #>
409                                         <a href="{{{ data.actions.activate }}}" class="button button-secondary activate"><?php _e( 'Activate' ); ?></a>
410                                 <# } #>
411                                 <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
412                                 <a href="{{{ data.actions.preview }}}" class="button button-secondary hide-if-customize"><?php _e( 'Preview' ); ?></a>
413                         </div>
414
415                         <# if ( ! data.active && data.actions['delete'] ) { #>
416                                 <a href="{{{ data.actions['delete'] }}}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a>
417                         <# } #>
418                 </div>
419         </div>
420 </script>
421
422 <?php require( ABSPATH . 'wp-admin/admin-footer.php' );