Skip to content

Commit

Permalink
Merge pull request #59 from boxuk/taxonomy-registration
Browse files Browse the repository at this point in the history
[FEATURE] Add Taxonomy Registration to `post-types.json`.
  • Loading branch information
jdamner authored Jul 16, 2024
2 parents fd790f9 + ae2f74b commit 4bd79f2
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 9 deletions.

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/editor-tools/src/PostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function register_post_types(): void {
return;
}

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

foreach ( $data['post_types'] ?? array() as $name => $args ) {
$args = wp_parse_args(
$args,
Expand All @@ -54,7 +58,7 @@ public function register_post_types(): void {
);

register_post_type( $name, $args ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral
}
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/editor-tools/tests/TestPostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public function testRegisterPostTypes(): void {
->once()
->with( 'bar', $expected_parsed_json_with_defaults );

\WP_Mock::userFunction( 'register_taxonomy' )
->once()
->with(
'example_category',
array(),
array(
'labels' => array(
'name' => 'TestName',
'singular_name' => 'TestName',
),
'public' => true,
'rewrite' => array( 'slug' => 'example-category' ),
)
);

// Short-circuit the test here as we'll test the blocks-to-template methods separately.
\WP_Mock::userFunction( 'is_admin' )
->twice()
Expand Down
12 changes: 12 additions & 0 deletions packages/editor-tools/tests/fixtures/PostTypes/post-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
"menu_icon": "dashicons-admin-post",
"taxonomies": [ "category", "post_tag" ]
}
},
"taxonomies": {
"example_category": {
"labels": {
"name": "TestName",
"singular_name": "TestName"
},
"public": true,
"rewrite": {
"slug": "example-category"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Outlined (Filled)",
"name": "boxuk/material-symbols-outlined-filled",
"tagName": "span",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Outlined",
"name": "boxuk/material-symbols-outlined",
"tagName": "span",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Rounded (Filled)",
"name": "boxuk/material-symbols-rounded-filled",
"tagName": "span",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Rounded",
"name": "boxuk/material-symbols-rounded",
"tagName": "span",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Sharp (Filled)",
"name": "boxuk/material-symbols-sharp-filled",
"tagName": "span",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "../schema/icon-config.json",
"title": "Sharp",
"name": "boxuk/material-symbols-sharp",
"tagName": "span",
Expand Down
2 changes: 1 addition & 1 deletion packages/iconography/includes/ConfigurationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function parse_config( string $file ) {
* @return SchemaContract
*/
private function get_schema(): SchemaContract {
return Schema::import( plugin_dir_path( __DIR__ ) . '/schema.json' );
return Schema::import( plugin_dir_path( __DIR__ ) . '/schema/icon-config.json' );
}

/**
Expand Down
File renamed without changes.

0 comments on commit 4bd79f2

Please sign in to comment.