Make WordPress Core

Changeset 30697


Ignore:
Timestamp:
12/02/2014 02:20:14 AM (10 years ago)
Author:
johnbillion
Message:

Prevent the deletion of a theme while it has an active child theme.

Fixes #29580
Props karpstrucking, jesin

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r30680 r30697  
    425425    WP_Theme::sort_by_name( $themes );
    426426    foreach ( $themes as $theme ) {
     427        $slug = $theme->get_stylesheet();
     428        $encoded_slug = urlencode( $slug );
     429
    427430        $parent = false;
    428431        if ( $theme->parent() ) {
    429432            $parent = $theme->parent()->display( 'Name' );
    430         }
    431 
    432         $slug = $theme->get_stylesheet();
    433         $encoded_slug = urlencode( $slug );
     433            $parents[ $slug ] = $theme->parent()->get_stylesheet();
     434        }
    434435
    435436        $prepared_themes[ $slug ] = array(
     
    461462    }
    462463
     464    // Remove 'delete' action if theme has an active child
     465    if ( isset( $parents ) && array_key_exists( $current_theme, $parents ) ) {
     466        unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
     467    }
     468
    463469    /**
    464470     * Filter the themes prepared for JavaScript, for themes.php.
  • trunk/src/wp-admin/themes.php

    r30356 r30697  
    2727        if ( !current_user_can('delete_themes') || ! $theme->exists() )
    2828            wp_die( __( 'Cheatin’ uh?' ), 403 );
    29         delete_theme($_GET['stylesheet']);
    30         wp_redirect( admin_url('themes.php?deleted=true') );
     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        }
    3136        exit;
    3237    }
     
    134139    elseif ( isset($_GET['deleted']) ) : ?>
    135140<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>
    136143<?php
    137144endif;
Note: See TracChangeset for help on using the changeset viewer.