WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#29580 closed defect (bug) (fixed)

When a child-theme is active, the parent-theme should not be deletable.

Reported by: ounziw Owned by: johnbillion
Milestone: 4.1 Priority: normal
Severity: normal Version: 4.0
Component: Themes Keywords: needs-testing has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

In wp-admin/themes.php, we can delete non-active themes.

When a child-theme is active, the parent-theme is deletable.
But if the parent-theme is deleted, the child-theme will not work.

So, the "Delete" link should be removed from the current theme's parent-theme.

Attachments (5)

twentyfourteen.png (368.7 KB) - added by ounziw 5 years ago.
Theme edit screen
29580_gowp.diff (2.2 KB) - added by karpstrucking 5 years ago.
removes link and blocks delete when theme has an active child
29580_gowp1.diff (3.2 KB) - added by karpstrucking 5 years ago.
updates 29580_gowp.diff for code standards
29580_gowp2.diff (2.3 KB) - added by karpstrucking 5 years ago.
reverts unrelated format changes in 29580_gowp1.diff
29580.diff (2.1 KB) - added by jesin 5 years ago.
Fixes undefined variable notice on 29580_gowp2.diff

Download all attachments as: .zip

Change History (17)

@ounziw
5 years ago

Theme edit screen

#1 @karpstrucking
5 years ago

  • Component changed from General to Themes
  • Keywords needs-patch added

Confirmed. Looks like this has been around for awhile, not new to 4.0.

I started working on a patch of the wp_prepare_themes_for_js function in wp-admin/includes/theme.php (to remove the delete link from the UI) but then it occurred to me perhaps this should be built into the delete_theme() function instead. For comparison, it looks like the equivalent function for deleting plugins throws an error if an attempt to delete an active plugin is made, but delete_theme() does not.

@karpstrucking
5 years ago

removes link and blocks delete when theme has an active child

#2 @karpstrucking
5 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

ignore my previous comment. I took a closer look at delete_plugin and the check for active plugins isn't there after all - it's in wp-admin/plugins.php.

in the case of a theme with an active child, the delete link is removed and the plugin deletion is blocked.

#3 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 4.1

#4 @DrewAPicture
5 years ago

  • Keywords needs-patch needs-docs added; has-patch removed

@karpstrucking: Thanks for the patch.

It could do with some inline comments to explain what's going on, as well as conforming to coding standards in regard to spacing in the new string and braces ]on one of the conditionals.

@karpstrucking
5 years ago

updates 29580_gowp.diff for code standards

#5 follow-up: @karpstrucking
5 years ago

  • Keywords has-patch dev-feedback added; needs-patch needs-docs removed

@DrewAPicture thanks for the feedback. updated patch attached. in wp-admin/themes.php I went ahead and updated spacing for the containing if statement, not just my own additions. it's a bit of a slippery slope and I wasn't sure if there's a protocol for that - I'm happy to go further if desired.

#6 in reply to: ↑ 5 ; follow-up: @DrewAPicture
5 years ago

Replying to karpstrucking:

@DrewAPicture thanks for the feedback. updated patch attached. in wp-admin/themes.php I went ahead and updated spacing for the containing if statement, not just my own additions. it's a bit of a slippery slope and I wasn't sure if there's a protocol for that - I'm happy to go further if desired.

Looks pretty good. Yeah, the protocol on spacing out lines is that it should only happen on lines that you're already changing or adding. This is to prevent undue churn in the codebase. So in 29580_gowp1.diff you'd revert the spacing changes on lines 15, 17, 22, 25, and 27 for wp-admin/themes.php.

@karpstrucking
5 years ago

reverts unrelated format changes in 29580_gowp1.diff

#7 in reply to: ↑ 6 @karpstrucking
5 years ago

Replying to DrewAPicture:

Looks pretty good. Yeah, the protocol on spacing out lines is that it should only happen on lines that you're already changing or adding. This is to prevent undue churn in the codebase. So in 29580_gowp1.diff you'd revert the spacing changes on lines 15, 17, 22, 25, and 27 for wp-admin/themes.php.

noted! updated in 29580_gowp2.diff

@jesin
5 years ago

Fixes undefined variable notice on 29580_gowp2.diff

#8 follow-up: @jesin
5 years ago

Patch 29580.diff fixes the PHP notice undefined variable parents... when there are no child themes.

I noticed another problem on Multisite setups. A parent theme is deletable from sites not using its child. To reproduce:

  1. Login as the super admin and navigate to Network Admin > Appearance > Themes.
  2. Network Enable a parent and its child theme.
  3. Login to one of the sites and Apply the child theme.
  4. Login to another site and delete its parent theme.

#9 @nacin
5 years ago

We can't fix the multisite part. We can check if the theme has any children and warn them specifically, the same way we warn them a theme might be used on sites.

#10 in reply to: ↑ 8 @karpstrucking
5 years ago

Replying to jesin:

Patch 29580.diff fixes the PHP notice undefined variable parents... when there are no child themes.

Doh. Thanks!

#11 @seanchayes
5 years ago

I did a test with this patch active and found that the delete option was indeed removed from the parent theme when the child theme was active.

#12 @johnbillion
5 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 30697:

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

Fixes #29580
Props karpstrucking, jesin

Note: See TracTickets for help on using tickets.