Make WordPress Core

Opened 4 months ago

Last modified 9 days ago

#60052 reopened defect (bug)

Error when deleting media if default taxonomies have been removed

Reported by: imatoni's profile imatoni Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.4.2
Component: General Keywords: dev-feedback has-patch
Focuses: Cc:



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: 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/
Stack trace:
#0 /var/www/vhosts/ array_map()
#1 /var/www/vhosts/ wp_delete_object_term_relationships()
#2 /var/www/vhosts/ wp_delete_attachment()
#3 /var/www/vhosts/ wp_delete_post()
#4 /var/www/vhosts/ wp_ajax_delete_post()
#5 /var/www/vhosts/ WP_Hook->apply_filters()
#6 /var/www/vhosts/ WP_Hook->do_action()
#7 /var/www/vhosts/" 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:

Thank you.

Change History (7)

This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.

4 months ago

#2 @Ankit K Gupta
4 months ago

  • Keywords dev-feedback added

#3 @imatoni
4 months ago

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():

PHP message: 63870
PHP message: "category"
PHP message: 63870
PHP message: "post_tag"

#4 @imatoni
4 months ago

  • Resolution set to maybelater
  • Status changed from new to closed

#5 @imatoni
4 months ago

  • Resolution maybelater deleted
  • Status changed from closed to reopened

This ticket was mentioned in PR #6230 on WordPress/wordpress-develop by JPrentice-thecode.

5 weeks ago

  • Keywords has-patch added

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 ) );

Note: See TracTickets for help on using tickets.