[wp-trac] [WordPress Trac] #62378: Allow patterns files to be divided into sub folders inside the main "patterns" folder

WordPress Trac noreply at wordpress.org
Mon Dec 2 15:47:48 UTC 2024


#62378: Allow patterns files to be divided into sub folders inside the main
"patterns" folder
-------------------------+------------------------------
 Reporter:  juanfra      |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Themes       |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------

Comment (by juanfra):

 @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 [https://github.com/WordPress/wordpress-
 develop/blob/f357f99d34fec4624edaed69fd5f280c608207d7/src/wp-includes
 /class-wp-theme.php#L1854 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
 [https://github.com/WordPress/wordpress-develop/blob/6.7/src/wp-includes
 /block-patterns.php#L377 few lines later] in the foreach loop.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62378#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list