mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: Allow for filtering of block patterns by source #4697
Closed
aaronrobertshaw
wants to merge
6
commits into
WordPress:trunk
from
aaronrobertshaw:update/allow-pattern-filtering-by-source
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49d01ac
Changes from https://github.com/WordPress/wordpress-develop/pull/4655
aaronrobertshaw 9a6553d
Tweak comment
aaronrobertshaw a65767a
Revert change to path
talldan 679ba66
Remove added in 6.3.0 comments
talldan 69af6b2
Try updating tests
talldan 567d5f8
Request source field in get_items test
aaronrobertshaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
* Registers the core block patterns and categories. | ||
* | ||
* @since 5.5.0 | ||
* @since 6.3.0 Added source to core block patterns. | ||
* @access private | ||
*/ | ||
function _register_core_block_patterns_and_categories() { | ||
|
@@ -29,10 +30,9 @@ function _register_core_block_patterns_and_categories() { | |
); | ||
|
||
foreach ( $core_block_patterns as $core_block_pattern ) { | ||
register_block_pattern( | ||
'core/' . $core_block_pattern, | ||
require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php' | ||
); | ||
$pattern = require ABSPATH . WPINC . '/block-patterns/' . $core_block_pattern . '.php'; | ||
$pattern['source'] = 'core'; // Added in 6.3.0. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'Added in 6.3.0' comments are useful in the Gutenberg plugin, but not so useful here, so I think they can be removed. |
||
register_block_pattern( 'core/' . $core_block_pattern, $pattern ); | ||
} | ||
} | ||
|
||
|
@@ -190,6 +190,7 @@ function wp_normalize_remote_block_pattern( $pattern ) { | |
* @since 5.9.0 The $current_screen argument was removed. | ||
* @since 6.2.0 Normalize the pattern from the API (snake_case) to the | ||
* format expected by `register_block_pattern` (camelCase). | ||
* @since 6.3.0 Add 'pattern-directory/core' to the pattern's source. | ||
aaronrobertshaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param WP_Screen $deprecated Unused. Formerly the screen that the current request was triggered from. | ||
*/ | ||
|
@@ -224,6 +225,7 @@ function _load_remote_block_patterns( $deprecated = null ) { | |
$patterns = $response->get_data(); | ||
|
||
foreach ( $patterns as $pattern ) { | ||
$pattern['source'] = 'pattern-directory/core'; // Added in 6.3.0. | ||
$normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); | ||
$pattern_name = 'core/' . sanitize_title( $normalized_pattern['title'] ); | ||
register_block_pattern( $pattern_name, $normalized_pattern ); | ||
|
@@ -237,6 +239,7 @@ function _load_remote_block_patterns( $deprecated = null ) { | |
* @since 5.9.0 | ||
* @since 6.2.0 Normalized the pattern from the API (snake_case) to the | ||
* format expected by `register_block_pattern()` (camelCase). | ||
* @since 6.3.0 Add 'pattern-directory/featured' to the pattern's 'source'. | ||
*/ | ||
function _load_remote_featured_patterns() { | ||
$supports_core_patterns = get_theme_support( 'core-block-patterns' ); | ||
|
@@ -258,6 +261,7 @@ function _load_remote_featured_patterns() { | |
$patterns = $response->get_data(); | ||
$registry = WP_Block_Patterns_Registry::get_instance(); | ||
foreach ( $patterns as $pattern ) { | ||
$pattern['source'] = 'pattern-directory/featured'; // Added in 6.3.0. | ||
$normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); | ||
$pattern_name = sanitize_title( $normalized_pattern['title'] ); | ||
// Some patterns might be already registered as core patterns with the `core` prefix. | ||
|
@@ -275,6 +279,7 @@ function _load_remote_featured_patterns() { | |
* @since 6.0.0 | ||
* @since 6.2.0 Normalized the pattern from the API (snake_case) to the | ||
* format expected by `register_block_pattern()` (camelCase). | ||
* @since 6.3.0 Add 'pattern-directory/theme' to the pattern's 'source'. | ||
* @access private | ||
*/ | ||
function _register_remote_theme_patterns() { | ||
|
@@ -301,6 +306,7 @@ function _register_remote_theme_patterns() { | |
$patterns = $response->get_data(); | ||
$patterns_registry = WP_Block_Patterns_Registry::get_instance(); | ||
foreach ( $patterns as $pattern ) { | ||
$pattern['source'] = 'pattern-directory/theme'; // Added in 6.3.0. | ||
$normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); | ||
$pattern_name = sanitize_title( $normalized_pattern['title'] ); | ||
// Some patterns might be already registered as core patterns with the `core` prefix. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the path was only changed in the gutenberg plugin because the plugin is in a different directory.
No need to bring this change over to core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for explaining that 👍
I did a brief check elsewhere in core and saw similar approaches in defining required paths, so mistakenly brought that over.