Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#12467 closed defect (bug) (fixed)

deleting the header and background images from media / library doesn't invalidate these files for the theme

Reported by: denis-de-bernardy's profile Denis-de-Bernardy Owned by: nacin's profile nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Template Keywords: has-patch
Focuses: Cc:

Description

when they're deleted, the theme options should get reset accordingly.

Attachments (1)

12467.patch (890 bytes) - added by ocean90 14 years ago.

Download all attachments as: .zip

Change History (6)

#1 @ocean90
14 years ago

  • Keywords has-patch added

This code would reset the options, if you visit the options page or the frontend you get the default images again. Don't know where we can place this.

function update_theme_mods( $id ) {
	if ( get_header_image() || get_background_image) {
		if ( get_header_image() == wp_get_attachment_url( $id ) )
			remove_theme_mod( 'header_image' );
		elseif ( get_background_image() == wp_get_attachment_url( $id ) )
			remove_theme_mod( 'background_image' );
	}
}

add_action( 'delete_attachment', 'update_theme_mods' );

@ocean90
14 years ago

#2 @ocean90
14 years ago

After talk with nacin I have inserted it into theme.php.

#3 @nacin
14 years ago

  • Owner set to nacin
  • Status changed from new to reviewing

#4 @ryan
14 years ago

Note that this will only work for the current theme. Inactive themes pointing to deleted attachments won't be updated. I think that is acceptable.

#5 @nacin
14 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [14850]) Invalidate header/background images for the current theme when the attachment is deleted. props ocean90, fixes #12467.

Note: See TracTickets for help on using tickets.