Fix: wp_delete_attachment
to Handle Non-Standard Taxonomies
#7702
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac Ticket: Core-36437
Description:
wp_delete_attachment
function, which assumes that attachments use the category and post_tag taxonomies. This assumption can lead to warnings in wp_delete_object_term_relationships when the attachment's post type does not utilize these taxonomies.Changes Made:
Updated the
wp_delete_attachment
function to check for existing taxonomies associated with the post type. This ensures that only relevant taxonomies are used when deleting term relationships, preventing unnecessary warnings.Removed hardcoded references to
category
andpost_tag
, allowing the function to dynamically handle any taxonomies related to the attachment's post type.Added unit tests to verify the new behavior, ensuring that attachments can be deleted without warnings even when custom taxonomies are used. The tests confirm that the function behaves correctly when no terms are associated with the attachment.
Testing:
Conclusion:
wp_delete_attachment
function, making it more flexible and ensuring it can handle a wider range of use cases without generating warnings. Thank you for considering this pull request!