From bf9a54557c980ec0c3c73272f36ffb2a28d67852 Mon Sep 17 00:00:00 2001 From: Nirav Sherasiya Date: Wed, 28 Jun 2023 17:11:51 +0530 Subject: [PATCH 1/3] Update file exists condition to avoid multiple check is_dir and is_readable function are used to check the dir exist or not and file_exists also check for the existence to avoid multiple check for same purpose add the non file exists check for continue statement and else for the operation. --- src/wp-includes/block-patterns.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/block-patterns.php b/src/wp-includes/block-patterns.php index a2d90a261e43b..726c9d66843e8 100644 --- a/src/wp-includes/block-patterns.php +++ b/src/wp-includes/block-patterns.php @@ -377,10 +377,10 @@ function _register_theme_block_patterns() { foreach ( $themes as $theme ) { $dirpath = $theme->get_stylesheet_directory() . '/patterns/'; - if ( ! is_dir( $dirpath ) || ! is_readable( $dirpath ) ) { + + if ( ! file_exists( $dirpath ) ) { continue; - } - if ( file_exists( $dirpath ) ) { + } else { $files = glob( $dirpath . '*.php' ); if ( $files ) { foreach ( $files as $file ) { From ba8b3215507054df2822808799c555d885354918 Mon Sep 17 00:00:00 2001 From: Nirav Sherasiya Date: Wed, 28 Jun 2023 18:47:22 +0530 Subject: [PATCH 2/3] Update validation function --- src/wp-includes/block-patterns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-patterns.php b/src/wp-includes/block-patterns.php index 726c9d66843e8..da94fa2146f5b 100644 --- a/src/wp-includes/block-patterns.php +++ b/src/wp-includes/block-patterns.php @@ -378,7 +378,7 @@ function _register_theme_block_patterns() { foreach ( $themes as $theme ) { $dirpath = $theme->get_stylesheet_directory() . '/patterns/'; - if ( ! file_exists( $dirpath ) ) { + if ( ! is_readable( $dirpath ) ) { continue; } else { $files = glob( $dirpath . '*.php' ); From f56293cd6c1a821e133ad41f66357ee1e797d04a Mon Sep 17 00:00:00 2001 From: Nirav sherasiya Date: Tue, 19 Mar 2024 14:18:11 +0530 Subject: [PATCH 3/3] Update src/wp-includes/block-patterns.php Co-authored-by: Jonny Harris --- src/wp-includes/block-patterns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-patterns.php b/src/wp-includes/block-patterns.php index da94fa2146f5b..5e47efb35f0e1 100644 --- a/src/wp-includes/block-patterns.php +++ b/src/wp-includes/block-patterns.php @@ -380,7 +380,7 @@ function _register_theme_block_patterns() { if ( ! is_readable( $dirpath ) ) { continue; - } else { + } $files = glob( $dirpath . '*.php' ); if ( $files ) { foreach ( $files as $file ) {