_delete_attachment_theme_mod

The timeline below displays how wordpress function _delete_attachment_theme_mod has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Checks an attachment being deleted to see if it's a header or background image.
 *
 * If true it removes the theme modification which would be pointing at the deleted
 * attachment.
 *
 * @access private
 * @since 3.0.0
 * @since 4.3.0 Also removes `header_image_data`.
 * @since 4.5.0 Also removes custom logo theme mods.
 *
 * @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();
    $custom_logo_id = get_theme_mod('custom_logo');
    if ($custom_logo_id && $custom_logo_id == $id) {
        remove_theme_mod('custom_logo');
        remove_theme_mod('header_text');
    }
    if ($header_image && $header_image == $attachment_image) {
        remove_theme_mod('header_image');
        remove_theme_mod('header_image_data');
    }
    if ($background_image && $background_image == $attachment_image) {
        remove_theme_mod('background_image');
    }
}

WordPress Version: 4.5

/**
 * Checks an attachment being deleted to see if it's a header or background image.
 *
 * If true it removes the theme modification which would be pointing at the deleted
 * attachment.
 *
 * @access private
 * @since 3.0.0
 * @since 4.3.0 Also removes `header_image_data`.
 * @since 4.5.0 Also removes custom logo theme mods.
 *
 * @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();
    $custom_logo_id = get_theme_mod('custom_logo');
    if ($custom_logo_id && $custom_logo_id == $id) {
        remove_theme_mod('custom_logo');
        remove_theme_mod('header_text');
    }
    if ($header_image && $header_image == $attachment_image) {
        remove_theme_mod('header_image');
        remove_theme_mod('header_image_data');
    }
    if ($background_image && $background_image == $attachment_image) {
        remove_theme_mod('background_image');
    }
}

WordPress Version: 4.3

/**
 * Checks an attachment being deleted to see if it's a header or background image.
 *
 * If true it removes the theme modification which would be pointing at the deleted
 * attachment.
 *
 * @access private
 * @since 3.0.0
 * @since 4.3.0 Also removes `header_image_data`.
 *
 * @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');
        remove_theme_mod('header_image_data');
    }
    if ($background_image && $background_image == $attachment_image) {
        remove_theme_mod('background_image');
    }
}

WordPress Version: 3.7

/**
 * Checks an attachment being deleted to see if it's a header or background image.
 *
 * If true it removes the theme modification which would be pointing at the deleted
 * attachment
 *
 * @access private
 * @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');
    }
}