Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_delete_attachment_theme_mod() WordPress Function

The delete_attachment_theme_mod() function is used to delete an attachment from a WordPress theme. This function can be used when you need to delete an attachment that is no longer needed or when you want to change the attachment.

_delete_attachment_theme_mod( int $id ) #

Checks an attachment being deleted to see if it’s a header or background image.


Description

If true it removes the theme modification which would be pointing at the deleted attachment.


Top ↑

Parameters

$id

(int)(Required)The attachment ID.


Top ↑

Source

File: wp-includes/theme.php

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' );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
4.5.0Also removes custom logo theme mods.
4.3.0Also removes header_image_data.
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.