diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index 36bfbe7e0c..3c0c51c98e 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -424,14 +424,15 @@ function wp_prepare_themes_for_js( $themes = null ) { WP_Theme::sort_by_name( $themes ); foreach ( $themes as $theme ) { + $slug = $theme->get_stylesheet(); + $encoded_slug = urlencode( $slug ); + $parent = false; if ( $theme->parent() ) { $parent = $theme->parent()->display( 'Name' ); + $parents[ $slug ] = $theme->parent()->get_stylesheet(); } - $slug = $theme->get_stylesheet(); - $encoded_slug = urlencode( $slug ); - $prepared_themes[ $slug ] = array( 'id' => $slug, '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. * diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 0729f18ed4..3fa903124d 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -26,8 +26,13 @@ if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) { $theme = wp_get_theme( $_GET['stylesheet'] ); if ( !current_user_can('delete_themes') || ! $theme->exists() ) wp_die( __( 'Cheatin’ uh?' ), 403 ); - delete_theme($_GET['stylesheet']); - wp_redirect( admin_url('themes.php?deleted=true') ); + $active = wp_get_theme(); + 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; } } @@ -133,6 +138,8 @@ if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?> } elseif ( isset($_GET['deleted']) ) : ?>

+ +