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