[wp-trac] [WordPress Trac] #63212: Enhancement: Do not throw PHP notice when file is not a pattern registration file
WordPress Trac
noreply at wordpress.org
Tue Apr 1 18:07:58 UTC 2025
#63212: Enhancement: Do not throw PHP notice when file is not a pattern
registration file
--------------------------+------------------------
Reporter: webmandesign | Owner: joemcgill
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 6.8
Component: Themes | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------------
Comment (by webmandesign):
Hi @joemcgill
Your presumption is correct.
As an example I will use my publicly available theme
[https://wordpress.org/themes/zooey/ Zooey] that has slightly different
usecase than the one I originally described in this ticket:
I have [https://github.com/webmandesign/zooey/tree/main/patterns
subfolders] in `patterns/` directory to organize my block patterns and
[https://github.com/webmandesign/zooey/blob/main/includes/Content/Block_Pattern.php#L566
I register these patterns with `register_block_pattern()` function]
providing user a way to
[https://github.com/webmandesign/zooey/blob/main/includes/Content/Block_Pattern.php#L642
filter the patterns list] before registration (this will become a theme
option in future update so user can disable patterns they don't use).
So, even though I use `patterns/` directory to organize my block patterns,
I don't provide file metadata for their registration - I use the
`register_block_pattern()` function. All of the files in `patterns/`
directory are throwing the PHP notice in WP6.8.
It almost looks like I can not use `register_block_pattern()` function
together with `patterns/` directory to organize my patterns.
Solution for a theme like Zooey would be as simple as renaming `patterns/`
directory to `pattern/`. But it kind of looks wrong as I have plural
directory names in the [https://github.com/webmandesign/zooey/tree/main
theme folder structure], such as `parts`, `templates` and using singular
`pattern` looks weird to me.
But maybe renaming to `block-patterns/` would do the trick, though it
feels really weird to me that I have to do this hack.
You can test this theme example in
[https://playground.wordpress.net/?wp=beta&theme=zooey WP playground] -
check the logs (FYI: there is also `_load_textdomain_just_in_time` PHP
notice for this particular theme I will fix in the theme update).
----
I can come up with additional usage examples, though:
Let's say I have this block pattern files structure in my theme:
{{{
patterns/
helpers/
icon.php
columns/
icons-in-2-columns.php
icons-in-3-columns.php
}}}
The `patterns/helpers/icon.php` is not a pattern file. It is a helper file
I use not to repeat the same code across multiple pattern files. This is
the content of the file:
{{{#!php
<!-- wp:image {"sizeSlug":"full"} -->
<figure class="wp-block-image size-full">
<img src="<?php echo esc_url( get_theme_file_uri( 'assets/images/icon-
demo.webp' ) ); ?>" alt="Demo icon"/>
</figure>
<!-- /wp:image -->
}}}
Then I include the `patterns/helpers/icon.php` in the actual pattern files
within `patterns/columns/` folder.
With this example I'd get PHP notice for the `patterns/helpers/icon.php`
file.
I'd like to keep the `patterns/helpers/icon.php` in the `patterns/` folder
because I use it only for patterns, so I like to keep patterns code
organized together.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63212#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list