Prevent the deletion of a theme while it has an active child theme.
Fixes #29580 Props karpstrucking, jesin git-svn-id: https://develop.svn.wordpress.org/trunk@30697 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0216b01a69
commit
16ec77cd70
@ -424,14 +424,15 @@ function wp_prepare_themes_for_js( $themes = null ) {
|
|||||||
|
|
||||||
WP_Theme::sort_by_name( $themes );
|
WP_Theme::sort_by_name( $themes );
|
||||||
foreach ( $themes as $theme ) {
|
foreach ( $themes as $theme ) {
|
||||||
|
$slug = $theme->get_stylesheet();
|
||||||
|
$encoded_slug = urlencode( $slug );
|
||||||
|
|
||||||
$parent = false;
|
$parent = false;
|
||||||
if ( $theme->parent() ) {
|
if ( $theme->parent() ) {
|
||||||
$parent = $theme->parent()->display( 'Name' );
|
$parent = $theme->parent()->display( 'Name' );
|
||||||
|
$parents[ $slug ] = $theme->parent()->get_stylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
$slug = $theme->get_stylesheet();
|
|
||||||
$encoded_slug = urlencode( $slug );
|
|
||||||
|
|
||||||
$prepared_themes[ $slug ] = array(
|
$prepared_themes[ $slug ] = array(
|
||||||
'id' => $slug,
|
'id' => $slug,
|
||||||
'name' => $theme->display( 'Name' ),
|
'name' => $theme->display( 'Name' ),
|
||||||
@ -460,6 +461,11 @@ function wp_prepare_themes_for_js( $themes = null ) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove 'delete' action if theme has an active child
|
||||||
|
if ( isset( $parents ) && array_key_exists( $current_theme, $parents ) ) {
|
||||||
|
unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the themes prepared for JavaScript, for themes.php.
|
* Filter the themes prepared for JavaScript, for themes.php.
|
||||||
*
|
*
|
||||||
|
@ -26,8 +26,13 @@ if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
|
|||||||
$theme = wp_get_theme( $_GET['stylesheet'] );
|
$theme = wp_get_theme( $_GET['stylesheet'] );
|
||||||
if ( !current_user_can('delete_themes') || ! $theme->exists() )
|
if ( !current_user_can('delete_themes') || ! $theme->exists() )
|
||||||
wp_die( __( 'Cheatin’ uh?' ), 403 );
|
wp_die( __( 'Cheatin’ uh?' ), 403 );
|
||||||
delete_theme($_GET['stylesheet']);
|
$active = wp_get_theme();
|
||||||
wp_redirect( admin_url('themes.php?deleted=true') );
|
if ( $active->get( 'Template' ) == $_GET['stylesheet'] ) {
|
||||||
|
wp_redirect( admin_url( 'themes.php?delete-active-child=true' ) );
|
||||||
|
} else {
|
||||||
|
delete_theme( $_GET['stylesheet'] );
|
||||||
|
wp_redirect( admin_url( 'themes.php?deleted=true' ) );
|
||||||
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +138,8 @@ if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
|
|||||||
}
|
}
|
||||||
elseif ( isset($_GET['deleted']) ) : ?>
|
elseif ( isset($_GET['deleted']) ) : ?>
|
||||||
<div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
|
<div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
|
||||||
|
<?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
|
||||||
|
<div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
|
||||||
<?php
|
<?php
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user