Make WordPress Core

Opened 9 years ago

Last modified 5 months ago

#36437 new defect (bug)

wp_delete_attachment causes warning

Reported by: thorbrink's profile thorbrink Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.0
Component: Media Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

wp_delete_attachment assumes that attachments uses category and post_tag taxonomies. This causes a warning in wp_delete_object_term_relationships when post type attachment is not using category or post_tag taxonomies.

Attachments (1)

36437.patch (720 bytes) - added by thorbrink 9 years ago.

Download all attachments as: .zip

Change History (6)

@thorbrink
9 years ago

#1 @swissspidy
9 years ago

  • Component changed from General to Media
  • Keywords has-patch added
  • Version changed from 4.4.2 to 2.0

#2 @desrosj
8 years ago

  • Keywords needs-unit-tests added

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


8 years ago

#4 @desrosj
8 years ago

Hi @thorbrink, would you be able and interested in adding unit tests for this?

This ticket was mentioned in PR #7702 on WordPress/wordpress-develop by @debarghyabanerjee.


5 months ago
#5

  • Keywords has-unit-tests added; needs-unit-tests removed

Trac Ticket: Core-36437

## Description:

  • This pull request addresses an issue with the 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 and post_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:

  • All existing and new unit tests have been executed successfully, confirming that the changes do not introduce any regressions and that the new functionality works as intended.

## Conclusion:

  • These changes enhance the robustness of the 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!
Note: See TracTickets for help on using tickets.