Normally when we sort unattached images, they include logos and header images too. My question is simple. Is there any method to keep header and logos safe from deletion?
Is it possible to attach them to a page (eg logo or header page) automatically when uploaded so that they will not appear unattached in media library.
You could add an ID as
post_parent
to the attachment of the header image viawp_update_post()
(even though this seems to be a very very hacky way to do it!)The tricky part is to get the ID out of the attachment URL; fortunately Rarst solved this issue long time ago, so you can manually add
get_attachment_id()
to your functions.Next you’ll have to assign an ID as
post_parent
; everytime you’ll save the header image the selected header image will be attached to this special ID.Nevertheless this seems to be a tricky way to solve the issue and it would probably superior to write an exception for the delete function…
Debugging Infos:
get_header_image()
should output the link to the current header image URL (only true if a header image is defined)get_attachment_id( $header_image_url )
should output the ID of the attachment page which should be equal to the ID of the attachment page you can see in Media (/wp-admin/post.php?post=123&action=edit); make also sure to copy and pasteget_attachment_id()
function from Rarst to your functions!default-header
should check for thename
of the checked input header field, which will be saved via$_POST