From b074c7be022c4258585de133587910c7fb29405a Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 24 May 2010 19:42:43 +0000 Subject: [PATCH] Invalidate header/background images for the current theme when the attachment is deleted. props ocean90, fixes #12467. git-svn-id: https://develop.svn.wordpress.org/trunk@14850 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/theme.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 64aad1d339..89695a79f9 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1714,4 +1714,24 @@ function require_if_theme_supports( $feature, $include) { require ( $include ); } +/** + * Checks an attachment, if it's a header or background image. If true remove the theme modification. + * + * @since 3.0.0 + * @param int $id the attachment id + */ +function _delete_attachment_theme_mod( $id ) { + $attachment_image = wp_get_attachment_url( $id ); + $header_image = get_header_image(); + $background_image = get_background_image(); + + if ( $header_image && $header_image == $attachment_image ) + remove_theme_mod( 'header_image' ); + + if ( $background_image && $background_image == $attachment_image ) + remove_theme_mod( 'background_image' ); +} + +add_action( 'delete_attachment', '_delete_attachment_theme_mod' ); + ?>