Opened 3 weeks ago
Last modified 31 hours ago
#62378 new enhancement
Allow patterns files to be divided into sub folders inside the main "patterns" folder
Reported by: | juanfra | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch |
Focuses: | Cc: |
Description
Copy of https://github.com/WordPress/gutenberg/issues/50144 - Opening this ticket as the changes need to happen in core.
What problem does this address?
With a growing number of patterns inside a theme, dealing with a long list of files inside the "patterns" folder is becoming inconvenient.
What is your proposed solution?
Allowing the organization of the patterns in sub-folders. For example, all header patterns are added to the "header" folder, all footer patterns into the "footer" folder, testimonials patterns into the "testimonials" folder, and so on.
Change History (9)
This ticket was mentioned in PR #7764 on WordPress/wordpress-develop by @juanfra.
3 weeks ago
#1
- Keywords has-patch added
3 weeks ago
#2
I followed the testing instructions and the update works well for me.
In addition, I moved some existing patterns to different nested subfolders, without issues.
- [x] Templates or other patterns that includes the patterns that were moved still works
- [x] The patterns are listed in the inserter
- [x] The patterns are listed in the pattern DataViews
- [x] The patterns can be duplicated from the pattern DataViews
#4
@
7 days ago
@flixos90 @mukesh27
I would like to hear if there are any blocking performance concerns with this proposed change or if there are any additional changes needed, for example any changes related to the caching of the patterns.
3 days ago
#5
Any updates here? This seems to be a lightweight feature to be added, once that theme developers would love.
#6
@
2 days ago
@juanfra Is there a reason why the dirpath is only updated in get_block_patterns, not _register_theme_block_patterns?
2 days ago
#7
@bgardner All the reviews and commits etc are public, if you don't see any updates then there are none :)
#8
@
34 hours ago
@poena There were a few reasons for making this change in get_block_patterns():
- Calling
scandir
with a trailing slash causes it to include the slash in the array index (e.g.,$array['/my-pattern.php']
), which could lead to unexpected issues. - It checks whether the dirpath exists, and on certain rare filesystems, this can behave unpredictably.
To address this, I thought it was safer to leave scandir()
as it is and instead adjust the $dirpath in the relevant part of the get_block_patterns() method. This approach avoids additional implications, as the trailing slash is added immediately after the scandir()
call.
Regarding _register_theme_block_patterns()
, it looks like $dirpath
is only used to concatenate and store the pattern filename, not to check if the directory exists. If we also want to modify $dirpath
there, we’d need to add the slash when generating the $file_path
a few lines later in the foreach loop.
#9
@
31 hours ago
@poena I think supporting subdirectories of the patterns
directory sounds reasonable, also from a performance perspective.
Any potential overhead it might add should be very small, and the performance optimizations for this should be made at another point in the system anyway, e.g. at the caching layer.
Trac ticket: https://core.trac.wordpress.org/ticket/62378
Gutenberg issue: https://github.com/WordPress/gutenberg/issues/50144
---
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.
Description
I'm changing the initial
$dirpath
to avoid having the trailing slash, as the file exist can behave differently in different file systems.Then, I'm making use of the static method
scandir
to check for php files in the directory recursively. Finally, adding the trailing slash so that this str_replace leaves only the required slashes in the$pattern_data
array.