diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 49020d5e969c4..442d18fdd25ed 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1330,12 +1330,18 @@ public function get_post_templates() { $files = (array) $this->get_files( 'php', 1, true ); foreach ( $files as $file => $full_path ) { - if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { + $file_content = @file_get_contents( $full_path ); + + if ( ! $file_content ) { + continue; + } + + if ( ! preg_match( '|Template Name:(.*)$|mi', $file_content, $header ) ) { continue; } $types = array( 'page' ); - if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) { + if ( preg_match( '|Template Post Type:(.*)$|mi', $file_content, $type ) ) { $types = explode( ',', _cleanup_header_comment( $type[1] ) ); }