[wp-trac] [WordPress Trac] #63334: `switch_to_locale()` overwrites custom object types for core taxonomies

WordPress Trac noreply at wordpress.org
Tue Apr 22 15:19:58 UTC 2025


#63334: `switch_to_locale()` overwrites custom object types for core taxonomies
--------------------------+-----------------------------
 Reporter:  Chouby        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  4.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 It's frequent that core taxonomies are registered for custom post types.
 For example in Jetpack:
 https://plugins.trac.wordpress.org/browser/jetpack/tags/14.5/jetpack_vendor/automattic
 /jetpack-classic-theme-helper/src/class-featured-content.php#L157

 However after `switch_to_locale()` is called, the custom post type is
 unregistered for the taxonomy.

 This is demonstrated by the following test:
 {{{#!php
 <?php
 register_post_type( 'cpt' );
 register_taxonomy_for_object_type( 'category', 'cpt' );

 $this->assertEqualsCanonicalizing( array( 'post', 'cpt' ), get_taxonomy(
 'category' )->object_type ); // Passes.

 switch_to_locale( 'de_DE' );
 $this->assertEqualsCanonicalizing( array( 'post', 'cpt' ), get_taxonomy(
 'category' )->object_type ); // Fails.
 }}}

 This is due to `create_initial_taxonomies()` directly hooked to
 `change_locale` without extra logic. This results in the core taxonomy to
 be fully re-initialized without its custom object types. See
 https://core.trac.wordpress.org/browser/tags/6.8/src/wp-includes/default-
 filters.php#L653

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63334>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list