_delete_attachment_theme_mod()
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.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Return
null
. Nothing (null).
Usage
_delete_attachment_theme_mod( $id );
- $id(int) (required)
- The attachment ID.
Changelog
Since 3.0.0 | Introduced. |
Since 4.3.0 | Also removes header_image_data. |
Since 4.5.0 | Also removes custom logo theme mods. |
_delete_attachment_theme_mod() delete attachment theme mod code WP 6.5.2
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' ); } }