@@ -19,9 +19,9 @@ class TaxonomyRegistryAdapter implements TaxonomyRegistryPort
1919 *
2020 * This is a generic method that delegates to the specific taxonomy registration method.
2121 *
22- * @param string $slug The entity slug
23- * @param array $args Registration arguments
24- * @param array $names Entity names (singular, plural)
22+ * @param string $slug The entity slug
23+ * @param array $args Registration arguments
24+ * @param array $names Entity names (singular, plural)
2525 */
2626 public function register (string $ slug , array $ args , array $ names ): void
2727 {
@@ -39,21 +39,16 @@ public function register(string $slug, array $args, array $names): void
3939 *
4040 * Uses register_extended_taxonomy if available, or falls back to register_taxonomy.
4141 *
42- * @param string $slug The taxonomy slug
43- * @param string|array $objectType The post type(s) the taxonomy is associated with
44- * @param array $args Registration arguments
45- * @param array $names Taxonomy names (singular, plural)
42+ * @param string $slug The taxonomy slug
43+ * @param string|array $objectType The post type(s) the taxonomy is associated with
44+ * @param array $args Registration arguments
45+ * @param array $names Taxonomy names (singular, plural)
4646 */
4747 public function registerTaxonomy (string $ slug , string |array $ objectType , array $ args , array $ names ): void
4848 {
4949 // Use global namespace for the function
5050 if (function_exists ('\\register_extended_taxonomy ' )) {
51- try {
52- \register_extended_taxonomy ($ slug , $ objectType , $ args , $ names );
53- } catch (\Exception $ e ) {
54- // Fallback to standard WordPress function
55- $ this ->fallbackToStandardTaxonomyRegistration ($ slug , $ objectType , $ args , $ names );
56- }
51+ \register_extended_taxonomy ($ slug , $ objectType , $ args , $ names );
5752 } else {
5853 $ this ->fallbackToStandardTaxonomyRegistration ($ slug , $ objectType , $ args , $ names );
5954 }
@@ -62,36 +57,35 @@ public function registerTaxonomy(string $slug, string|array $objectType, array $
6257 /**
6358 * Fallback to standard WordPress taxonomy registration if extended registration fails
6459 *
65- * @param string $slug Taxonomy slug
66- * @param string|array $objectType Post type(s) to register the taxonomy for
67- * @param array $args Arguments for taxonomy
68- * @param array $names Names for taxonomy
60+ * @param string $slug Taxonomy slug
61+ * @param string|array $objectType Post type(s) to register the taxonomy for
62+ * @param array $args Arguments for taxonomy
63+ * @param array $names Names for taxonomy
6964 */
7065 protected function fallbackToStandardTaxonomyRegistration (string $ slug , string |array $ objectType , array $ args , array $ names ): void
7166 {
72- if (function_exists ('\\register_taxonomy ' )) {
73- try {
74- // Merge names into args
75- if (! empty ($ names )) {
76- if (isset ($ names ['singular ' ])) {
77- $ args ['labels ' ]['singular_name ' ] = $ names ['singular ' ];
78- }
79- if (isset ($ names ['plural ' ])) {
80- $ args ['labels ' ]['name ' ] = $ names ['plural ' ];
81- }
82- if (isset ($ names ['slug ' ])) {
83- // Use the slug from names if provided
84- $ customSlug = $ names ['slug ' ];
85- } else {
86- $ customSlug = $ slug ;
87- }
88- } else {
89- $ customSlug = $ slug ;
90- }
67+ if (!function_exists ('\\register_taxonomy ' )) {
68+ throw new \Exception ('The register_taxonomy function is not available. ' );
69+ }
9170
92- \register_taxonomy ($ customSlug , $ objectType , $ args );
93- } catch (\Exception $ e ) {
71+ // Merge names into args
72+ if (!empty ($ names )) {
73+ if (isset ($ names ['singular ' ])) {
74+ $ args ['labels ' ]['singular_name ' ] = $ names ['singular ' ];
75+ }
76+ if (isset ($ names ['plural ' ])) {
77+ $ args ['labels ' ]['name ' ] = $ names ['plural ' ];
9478 }
79+ if (isset ($ names ['slug ' ])) {
80+ // Use the slug from names if provided
81+ $ customSlug = $ names ['slug ' ];
82+ } else {
83+ $ customSlug = $ slug ;
84+ }
85+ } else {
86+ $ customSlug = $ slug ;
9587 }
88+
89+ \register_taxonomy ($ customSlug , $ objectType , $ args );
9690 }
9791}
0 commit comments