~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-admin/themes.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

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