-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Removing PHP notice for non pattern definition files #8631
Removing PHP notice for non pattern definition files #8631
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
@webmandesign Thanks for the updates here. I've left a bit of feedback, but this looks pretty good to me.
src/wp-includes/class-wp-theme.php
Outdated
/** | ||
* Filters list of block pattern files for a theme. | ||
* | ||
* @since 6.8 |
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.
* @since 6.8 | |
* @since 6.8.0 |
src/wp-includes/class-wp-theme.php
Outdated
* @param array $files Array of theme files found within `patterns` directory. | ||
* @param string $dirpath Path of theme `patterns` directory being scanned. | ||
*/ | ||
$files = (array) apply_filters( 'get_block_patterns_files', $files, $dirpath ); |
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.
Let's rename this to be a bit more consistent with other filters in this file:
$files = (array) apply_filters( 'get_block_patterns_files', $files, $dirpath ); | |
$files = (array) apply_filters( 'theme_block_pattern_files', $files, $dirpath ); |
src/wp-includes/class-wp-theme.php
Outdated
@@ -1893,6 +1903,10 @@ public function get_block_patterns() { | |||
foreach ( $files as $file ) { | |||
$pattern = get_file_data( $file, $default_headers ); | |||
|
|||
if ( empty( $pattern['slug'] ) && empty( $pattern['title'] ) ) { |
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 this makes sense to add here. The downside may be that folks forget to add the header and have their patterns silently fail to load.
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.
You are right. I'm going to remove this code.
src/wp-includes/class-wp-theme.php
Outdated
* @param array $files Array of theme files found within `patterns` directory. | ||
* @param string $dirpath Path of theme `patterns` directory being scanned. | ||
*/ | ||
$files = (array) apply_filters( 'get_block_patterns_files', $files, $dirpath ); |
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.
Casting as an array could hide if someone returns the wrong type which can make it harder to debug.
$files = (array) apply_filters( 'get_block_patterns_files', $files, $dirpath ); | |
$files = apply_filters( 'get_block_patterns_files', $files, $dirpath ); |
Skipping non-pattern-definition PHP files within
theme-slug/patterns
folder during block pattern registration.This allows using helper PHP files within
theme-slug/patterns
folder, keeping pattern related code in the theme together.Trac ticket: https://core.trac.wordpress.org/ticket/63212
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.