Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#58656 closed defect (bug) (duplicate)

The function _register_theme_block_patterns check to see if directory exist multiple times

Reported by: spacedmonkey Owned by:
Priority: normal Milestone:
Component: Editor Version: 6.2
Severity: normal Keywords: good-first-bug has-patch
Cc: Focuses:

Description

In the function _register_theme_block_patterns check to see if a directory exists three files.

        $dirpath = $theme->get_stylesheet_directory() . '/patterns/';
        if ( ! is_dir( $dirpath ) || ! is_readable( $dirpath ) ) {
                continue;
        }
        if ( file_exists( $dirpath ) ) {
                $files = glob( $dirpath . '*.php' );

This calls is_dir, is_readable and file_exists basically the same thing. This should be avoided.

Change History (5)

#1 @spacedmonkey
3 years ago

  • Keywords good-first-bug needs-patch added

This ticket was mentioned in ​PR #4752 on ​WordPress/wordpress-develop by ​nirav7707.


3 years ago
#2

  • Keywords has-patch added; needs-patch removed

Trac Ticket -> https://core.trac.wordpress.org/ticket/58656

  • ----

In the pull request (PR), the changes were made to remove the is_dir and is_readable checks. These checks were originally used to verify the availability of a directory. To streamline the code and avoid multiple checks, the is_readable function was used to validate the directory's existence and readability.

To implement this, an if condition was added with the negation of the is_readable check. If the condition is met, the continue statement is executed, skipping the rest of the code. However, if the directory is valid and readable, the remaining code is executed as usual.

#3 @spacedmonkey
3 years ago

#58655 was marked as a duplicate.

#4 @spacedmonkey
3 years ago

  • Milestone Future Release → 6.4

#5 @spacedmonkey
3 years ago

  • Milestone 6.4
  • Resolution → duplicate
  • Status new → closed

Duplicate of #57905.

Fixed in [55702].

Note: See TracTickets for help on using tickets.