Skip to content

Commit

Permalink
Merge pull request #196 from boxuk/fix/editor-tools/post-type-registr…
Browse files Browse the repository at this point in the history
…ation

[FIX] Ensure taxonomies are registered if no custom post-types are.
  • Loading branch information
jdamner authored Oct 30, 2024
2 parents f6c64d4 + e1afc2f commit 6b0c127
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/editor-tools/schema/post-type.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@
"^[a-zA-Z0-9_]+$": {
"type": "object",
"properties": {
"post_types": {
"type": "array",
"description": "An array of post type identifiers that will be registered for the taxonomy. Post types can be registered later with register_post_type() or register_post_type_for_object_type().",
"items": {
"type": "string",
"pattern": "^[a-zA-Z0-9_]+$",
"description": "Post type identifier"
}
},
"labels": {
"type": "object",
"description": "An array of labels for this taxonomy. If not set, taxonomy labels are inherited from post type labels. See [get_taxonomy_labels()](https://developer.wordpress.org/reference/functions/get_taxonomy_labels/) for a full list of supported labels.",
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-tools/src/PostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function register_post_types(): void {
}

foreach ( $data['taxonomies'] ?? array() as $name => $args ) {
register_taxonomy( $name, array(), $args );
register_taxonomy( $name, $args['post_types'] ?? 'post', $args );
}

foreach ( $data['post_types'] ?? array() as $name => $args ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-tools/tests/TestPostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testRegisterPostTypes(): void {
->once()
->with(
'example_category',
array(),
'post',
array(
'labels' => array(
'name' => 'TestName',
Expand Down

0 comments on commit 6b0c127

Please sign in to comment.