Opened 12 months ago
Last modified 8 months ago
#60052 reopened defect (bug)
Error when deleting media if default taxonomies have been removed
Reported by: | imatoni | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.4.2 |
Component: | General | Keywords: | dev-feedback has-patch |
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 (7)
This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.
12 months ago
This ticket was mentioned in PR #6230 on WordPress/wordpress-develop by JPrentice-thecode.
9 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 ) );
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"