[wp-trac] [WordPress Trac] #60052: Error when deleting media if default taxonomies have been removed

WordPress Trac noreply at wordpress.org
Thu Feb 15 05:04:13 UTC 2024


#60052: Error when deleting media if default taxonomies have been removed
--------------------------+------------------------------
 Reporter:  imatoni       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  6.4.2
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |     Focuses:
--------------------------+------------------------------

Comment (by htyzfpip23):

 The error you encountered when deleting media from the media library,
 specifically the `TypeError` in `taxonomy.php`, is indeed related to the
 removal of the default taxonomy 'post_tag' using the provided code
 snippet.

 To address this issue, it's essential to consider the potential
 consequences of deregistering default taxonomies. While your specific use
 case necessitates the removal of 'post_tag,' doing so might impact other
 functionalities and processes within WordPress, as evidenced by the error
 during media deletion.

 To handle this gracefully in the WordPress core, a more robust solution
 can be implemented. Rather than directly unsetting the taxonomy, consider
 using the `unregister_taxonomy` function, which properly removes the
 taxonomy without causing unexpected errors during operations like media
 deletion.

 Here's an adjusted code snippet:

 ```php
 add_action('init', 'deregister_tag');

 function deregister_tag() {
     $tax = 'post_tag';

     if (taxonomy_exists($tax)) {
         unregister_taxonomy($tax);
     }
 }
 ```

 This modification ensures that the 'post_tag' taxonomy is deregistered
 using the appropriate WordPress function, minimizing potential conflicts
 and errors in core processes.

 By using `unregister_taxonomy`, the system should handle the removal more
 gracefully, reducing the likelihood of fatal errors during media deletion
 or other related operations.

 Remember to thoroughly test this adjustment in a staging environment
 before applying it to a live site to ensure compatibility with your
 specific use case. Additionally, consider the broader implications of
 removing default taxonomies to avoid unintended consequences in other
 parts of your WordPress installation.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60052#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list