Skip to content

Commit 0a45004

Browse files
committed
Fix WordPress entity
1 parent 96a555a commit 0a45004

29 files changed

Lines changed: 63 additions & 75 deletions

src/Adapter/Out/WordPress/PostTypeRegistryAdapter.php

100644100755
Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class PostTypeRegistryAdapter implements PostTypeRegistryPort
1919
*
2020
* This is a generic method that delegates to the specific post type 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
{
@@ -33,25 +33,20 @@ public function register(string $slug, array $args, array $names): void
3333
*
3434
* Uses register_extended_post_type if available, or falls back to register_post_type.
3535
*
36-
* @param string $slug The post type slug
37-
* @param array $args Registration arguments
38-
* @param array $names Post type names (singular, plural)
36+
* @param string $slug The post type slug
37+
* @param array $args Registration arguments
38+
* @param array $names Post type names (singular, plural)
3939
*/
4040
public function registerPostType(string $slug, array $args, array $names): void
4141
{
4242
// Check if required WordPress functions exist
43-
if (! function_exists('\\register_post_type') && ! function_exists('\\register_extended_post_type')) {
43+
if (!function_exists('\\register_post_type') && !function_exists('\\register_extended_post_type')) {
4444
return;
4545
}
4646

4747
// Use global namespace for the function
4848
if (function_exists('\\register_extended_post_type')) {
49-
try {
50-
\register_extended_post_type($slug, $args, $names);
51-
} catch (\Exception $e) {
52-
// Fallback to standard WordPress function
53-
$this->fallbackToStandardPostTypeRegistration($slug, $args, $names);
54-
}
49+
\register_extended_post_type($slug, $args, $names);
5550
} else {
5651
$this->fallbackToStandardPostTypeRegistration($slug, $args, $names);
5752
}
@@ -60,35 +55,34 @@ public function registerPostType(string $slug, array $args, array $names): void
6055
/**
6156
* Fallback to standard WordPress post type registration if extended registration fails
6257
*
63-
* @param string $slug Post type slug
64-
* @param array $args Arguments for post type
65-
* @param array $names Names for post type
58+
* @param string $slug Post type slug
59+
* @param array $args Arguments for post type
60+
* @param array $names Names for post type
6661
*/
6762
protected function fallbackToStandardPostTypeRegistration(string $slug, array $args, array $names): void
6863
{
69-
if (function_exists('\\register_post_type')) {
70-
try {
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'];
78-
}
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;
87-
}
64+
if (!function_exists('\\register_post_type')) {
65+
throw new \Exception('register_post_type function not found.');
66+
}
8867

89-
\register_post_type($customSlug, $args);
90-
} catch (\Exception $e) {
68+
// Merge names into args
69+
if (!empty($names)) {
70+
if (isset($names['singular'])) {
71+
$args['labels']['singular_name'] = $names['singular'];
72+
}
73+
if (isset($names['plural'])) {
74+
$args['labels']['name'] = $names['plural'];
9175
}
76+
if (isset($names['slug'])) {
77+
// Use the slug from names if provided
78+
$customSlug = $names['slug'];
79+
} else {
80+
$customSlug = $slug;
81+
}
82+
} else {
83+
$customSlug = $slug;
9284
}
85+
86+
\register_post_type($customSlug, $args);
9387
}
9488
}

src/Adapter/Out/WordPress/TaxonomyRegistryAdapter.php

100644100755
Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Application/Service/EntityRegistrationService.php

100644100755
File mode changed.

src/Application/Service/PostTypeService.php

100644100755
File mode changed.

src/Application/Service/TaxonomyService.php

100644100755
File mode changed.

src/Domain/Exception/PostTypeException.php

100644100755
File mode changed.

src/Domain/Exception/TaxonomyException.php

100644100755
File mode changed.

src/Domain/Model/Entity.php

100644100755
File mode changed.

src/Domain/Model/PostType.php

100644100755
File mode changed.

src/Domain/Model/Taxonomy.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)