10
10
require_once( dirname( __FILE__ ) . '/admin.php' );
12
12
if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
13
wp_die( __( 'Cheatin’ uh?' ) );
13
wp_die( __( 'Cheatin’ uh?' ), 403 );
15
15
if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
16
16
if ( 'activate' == $_GET['action'] ) {
17
17
check_admin_referer('switch-theme_' . $_GET['stylesheet']);
18
18
$theme = wp_get_theme( $_GET['stylesheet'] );
19
19
if ( ! $theme->exists() || ! $theme->is_allowed() )
20
wp_die( __( 'Cheatin’ uh?' ) );
20
wp_die( __( 'Cheatin’ uh?' ), 403 );
21
21
switch_theme( $theme->get_stylesheet() );
22
22
wp_redirect( admin_url('themes.php?activated=true') );
25
25
check_admin_referer('delete-theme_' . $_GET['stylesheet']);
26
26
$theme = wp_get_theme( $_GET['stylesheet'] );
27
27
if ( !current_user_can('delete_themes') || ! $theme->exists() )
28
wp_die( __( 'Cheatin’ uh?' ) );
29
delete_theme($_GET['stylesheet']);
30
wp_redirect( admin_url('themes.php?deleted=true') );
28
wp_die( __( 'Cheatin’ 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' ) );
33
delete_theme( $_GET['stylesheet'] );
34
wp_redirect( admin_url( 'themes.php?deleted=true' ) );
119
124
<h2><?php esc_html_e( 'Themes' ); ?>
120
125
<span class="title-count theme-count"><?php echo count( $themes ); ?></span>
121
126
<?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>
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>
134
139
elseif ( isset($_GET['deleted']) ) : ?>
135
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>
158
165
// 0 = name, 1 = capability, 2 = file
159
166
if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
160
$class = ' class="current"';
161
168
if ( !empty($submenu[$item[2]]) ) {
162
169
$submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
163
170
$menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
164
171
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>";
172
$current_theme_actions[] = "<a class='button button-secondary$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
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]) ) {
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] ) ) {
169
176
$menu_file = $item[2];
170
if ( false !== ( $pos = strpos( $menu_file, '?' ) ) )
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>";
186
if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
171
187
$menu_file = substr( $menu_file, 0, $pos );
172
190
if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
173
$current_theme_actions[] = "<a class='button button-secondary' href='{$item[2]}'$class>{$item[0]}</a>";
191
$current_theme_actions[] = "<a class='button button-secondary$class' href='{$item[2]}'>{$item[0]}</a>";
175
$current_theme_actions[] = "<a class='button button-secondary' href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
193
$current_theme_actions[] = "<a class='button button-secondary$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
216
234
<a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
218
236
<?php } else { ?>
219
<a class="button button-primary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
237
<a class="button button-secondary activate" href="<?php echo $theme['actions']['activate']; ?>"><?php _e( 'Activate' ); ?></a>
220
238
<?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>
239
<a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
222
240
<a class="button button-secondary hide-if-customize" href="<?php echo $theme['actions']['preview']; ?>"><?php _e( 'Preview' ); ?></a>
246
264
<h3><?php _e('Broken Themes'); ?></h3>
247
265
<p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
268
$can_delete = current_user_can( 'delete_themes' );
251
272
<th><?php _ex('Name', 'theme name'); ?></th>
252
273
<th><?php _e('Description'); ?></th>
274
<?php if ( $can_delete ) { ?>
255
foreach ( $broken_themes as $broken_theme ) {
279
<?php foreach ( $broken_themes as $broken_theme ) : ?>
258
<td>" . ( $broken_theme->get( 'Name' ) ? $broken_theme->get( 'Name' ) : $broken_theme->get_stylesheet() ) . "</td>
259
<td>" . $broken_theme->errors()->get_error_message() . "</td>
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>
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 );
292
<td><a href="<?php echo esc_url( $delete_url ); ?>" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a></td>
297
332
<a class="button button-primary customize load-customize hide-if-no-customize" href="{{ data.actions.customize }}"><?php _e( 'Customize' ); ?></a>
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>
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>
302
337
<a class="button button-secondary hide-if-customize" href="{{{ data.actions.preview }}}"><?php _e( 'Preview' ); ?></a>
359
394
<div class="inactive-theme">
360
395
<# if ( data.actions.activate ) { #>
361
<a href="{{{ data.actions.activate }}}" class="button button-primary activate"><?php _e( 'Activate' ); ?></a>
396
<a href="{{{ data.actions.activate }}}" class="button button-secondary activate"><?php _e( 'Activate' ); ?></a>
363
<a href="{{{ data.actions.customize }}}" class="button button-secondary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
398
<a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
364
399
<a href="{{{ data.actions.preview }}}" class="button button-secondary hide-if-customize"><?php _e( 'Preview' ); ?></a>