Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: add a custom taxonomy for user created patterns #53163

Merged
merged 6 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/compat/wordpress-6.4/block-patterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Overrides Core's wp-includes/block-patterns.php to add new wp_patterns taxonomy for WP 6.4.
*
* @package gutenberg
*/

/**
* Adds a new taxonomy for organizing user created patterns.
*
* Note: This should be removed when the minimum required WP version is >= 6.4.
*
* @see https://github.com/WordPress/gutenberg/pull/53163
*
* @return void
*/
function gutenberg_register_taxonomy_patterns() {
$labels = array(
'name' => _x( 'Pattern Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Pattern Category', 'taxonomy singular name' ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
'_builtin' => true,
'rewrite' => array( 'slug' => 'wp_pattern_category' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We can set show_ui to false; the post type has no admin menu, which will do nothing.
  • REST API will mainly consume the taxonomy, so it's not publicly queriable. Related arguments (query_var, rewrite, public) will need to be adjusted.

That would give us pretty much the same argument shape as wp_template_part_area - https://github.com/WordPress/wordpress-develop/blob/8cd99074624a8c4b589f31c7b2a8092f4fe5c79e/src/wp-includes/taxonomy.php#L207-L224

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference with patterns is if we set show_ui false and make it not public users won't be able to see/update the terms in the /wp-admin/edit.php?post_type=wp_block interface, eg.

Screenshot 2023-08-17 at 4 48 05 PM

Not sure how critical that is 🤔 What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PostTaxonomies component only checks for show_ui, not the other arguments.

Considering that the new taxonomy does very little without remaining work from #53164. I think it's okay to hide UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, have removed the UI for now at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Glen!

);
register_taxonomy( 'wp_pattern_category', array( 'wp_block' ), $args );
}
add_action( 'init', 'gutenberg_register_taxonomy_patterns' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function gutenberg_is_experiment_enabled( $name ) {

// WordPress 6.4 compat.
require __DIR__ . '/compat/wordpress-6.4/blocks.php';
require __DIR__ . '/compat/wordpress-6.4/block-patterns.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
Expand Down