From 64601e97ae439d8128ea9f59383f0b5039dcb419 Mon Sep 17 00:00:00 2001 From: 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: http://svn.automattic.com/wordpress/trunk@14850 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 64aad1d33..89695a79f 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' ); + ?>