[wp-trac] [WordPress Trac] #63212: WP6.8-RC1: Enhancement: Do not throw PHP notice when file is not a pattern registration file
WordPress Trac
noreply at wordpress.org
Tue Apr 1 12:49:18 UTC 2025
#63212: WP6.8-RC1: Enhancement: Do not throw PHP notice when file is not a pattern
registration file
--------------------------+-----------------------------
Reporter: webmandesign | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi,
Since testing WP6.8 RC1 I get this PHP notice:
{{{
Notice:
Function get_block_patterns was called incorrectly.
Could not register file "./themes/theme-slug/patterns/affected/file.php"
as a block pattern ("Slug" field missing)
Please see Debugging in WordPress for more information.
(This message was added in version 6.0.0.) in ./wp-includes/functions.php
on line 6121
}}}
Could you please modify the code to ''**skip all PHP files without "Slug"
defined**'' in `theme-slug/patterns` folder?
As maybe such files are not meant for a pattern registration purpose. They
may be helper files for patterns, for example.
That way the notice is not triggered and file is skipped during automatic
WordPress pattern registration.
----
**My usecase for explanation:**
In my theme I register most of the patterns with proper file metadata.
However, one of the patterns runs dynamic PHP code that has to be
registered later on front-end (during `wp` action hook) to receive proper
data from WordPress. I need to register this pattern using PHP
[https://developer.wordpress.org/reference/functions/register_block_pattern/
`register_block_pattern()` function] instead of setting the pattern file
metadata.
To fix the new WP6.8 PHP notice I would need to move the affected pattern
from `patterns/` folder to other folder, such as `patterns-other/`, which
creates inconsistency in my theme code organization.
Another alternative solution for me would be to register all patterns with
`register_block_pattern()` function and not use `patterns/` folder at
all...
Pre-WP6.8 solution was to have pattern files with metadata as direct
children of `patterns/` folder and use subfolders for the patterns
registered via `register_block_pattern()` function.
----
**Proposed solution:**
The solution is as simple as removing `_doing_it_wrong()` block from `if (
empty( $pattern['slug'] ) ) {...}` statement in `get_block_patterns()`
function ([https://github.com/WordPress/wordpress-develop/blob/trunk/src
/wp-includes/class-wp-theme.php#L1897 check the code at GitHub]).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63212>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list