Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Returning the "doing it wrong" and allowing filtering theme pattern f…
…iles
  • Loading branch information
webmandesign authored Apr 2, 2025
commit 93364ad6a9904a31f20567a1879f96c686383eee
19 changes: 18 additions & 1 deletion src/wp-includes/class-wp-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,15 @@ public function get_block_patterns() {

$files = (array) self::scandir( $dirpath, 'php', -1 );

/**
* Filters list of block pattern files for a theme.
*
* @since 6.8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 6.8
* @since 6.8.0

*
* @param array $files Array of theme files found within `patterns` directory.
*/
$files = (array) apply_filters( 'get_block_patterns_files', $files );

$dirpath = trailingslashit( $dirpath );

if ( ! $files ) {
Expand Down Expand Up @@ -1894,7 +1903,15 @@ public function get_block_patterns() {
$pattern = get_file_data( $file, $default_headers );

if ( empty( $pattern['slug'] ) ) {
// Skip any file without pattern slug definition.
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: file name. */
__( 'Could not register file "%s" as a block pattern ("Slug" field missing)' ),
$file
),
'6.0.0'
);
continue;
}

Expand Down
Loading