Opened 16 months ago
Last modified 6 days ago
#60052 assigned defect (bug)
Error when deleting media if default taxonomies have been removed
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.4.2 |
Component: | General | Keywords: | dev-feedback has-patch has-unit-tests |
Focuses: | Cc: |
Description
Hello,
I recently had a problem with deleting media from the media library.
I received the following error message:
2151#0: *203114 FastCGI sent in stderr: "PHP message: UM_TEST_ERROR_LOG
PHP message: 63870
PHP message: "category"
PHP message: UM_TEST_ERROR_LOG
PHP message: 63870
PHP message: "post_tag"
PHP message: PHP Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, WP_Error given in /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/taxonomy.php:1964
Stack trace:
#0 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/taxonomy.php(1964): array_map()
#1 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/post.php(6304): wp_delete_object_term_relationships()
#2 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/post.php(3416): wp_delete_attachment()
#3 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-admin/includes/ajax-actions.php(886): wp_delete_post()
#4 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/class-wp-hook.php(324): wp_ajax_delete_post()
#5 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#6 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-includes/plugin.php(517): WP_Hook->do_action()
#7 /var/www/vhosts/fis-gmbh.de/stage.fis-gmbh.de/wp-admin/admin-ajax.php(1" while reading response header from upstream
This happened because we had used the following code elsewhere:
add_action( 'init', 'deregister_tag' );
function deregister_tag() {
global $wp_taxonomies;
$tax = 'post_tag';
if ( taxonomy_exists( $tax ) ) {
unset( $wp_taxonomies[ $tax ] );
}
}
This code ensures that the standard WordPress taxonomy 'post_tag' is no longer present (this was not necessary for this project).
In wp-includes/post.php there is the following call:
wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
This call causes an error to occur if the taxonomy 'post_tag' is not present.
I am of the opinion that this error should be caught in the WordPress core.
This issue is also being discussed here at WPML:
https://wpml.org/forums/topic/fatal-error-when-deleting-a-media/
Thank you.
Change History (12)
This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.
16 months ago
This ticket was mentioned in PR #6230 on WordPress/wordpress-develop by JPrentice-thecode.
13 months ago
#6
- Keywords has-patch added
https://core.trac.wordpress.org/ticket/60052#no0
that causes crit errors if default taxonomies catergory / post_tag have been removed or disabled.
The following line is a more generic check that would check category and post tag if they existed.
Deleted: wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
This following line does the same thing but doesn't fail if empty, and covers any custom taxonomies.
Following line:
wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
#8
@
5 weeks ago
- Keywords needs-unit-tests added
https://github.com/WordPress/wordpress-develop/pull/6230
Instead of removing the line, checks added.
Needs unit tests
#9
@
5 weeks ago
- Keywords has-testing-info added
Testing Criteria & Summary of Unit Test
Testing Criteria:
Ensure that an attachment can be deleted even when the post_tag taxonomy has been unregistered.
Verify that wp_delete_attachment() correctly handles the absence of post_tag without errors.
Simulate real-world conditions by unregistering both category and post_tag taxonomies before deleting the attachment.
Confirm that the function returns a valid WP_Post object upon successful deletion.
Unit Test Summary:
This unit test creates a test attachment, unregisters the category and post_tag taxonomies, and then attempts to delete the attachment using wp_delete_attachment(). In previous versions, deleting an attachment after unregistering post_tag could cause a failure (#60052). The test ensures that after the core patch, the function correctly handles missing taxonomies and successfully deletes the attachment. The test also explicitly removes taxonomy entries from $wp_taxonomies to fully replicate the missing taxonomy scenario.
Let me know if you'd like any refinements!
#10
@
5 weeks ago
- Keywords has-unit-tests added; needs-unit-tests has-testing-info removed
https://github.com/WordPress/wordpress-develop/pull/6230
@anthonythorne credit for completing the PHPUnit testing.
@jamespayne credit for removing the duplicate calls
oops, the first lines in the error message came from my error log. Of course, they do not come from the core.
This comes from my error_log():
UM_TEST_ERROR_LOG
PHP message: 63870
PHP message: "category"
PHP message: UM_TEST_ERROR_LOG
PHP message: 63870
PHP message: "post_tag"