OSDN Git Service

run regex once, using the PCRE_MULTILINE modifier; see #878
authorscribu <mail@scribu.net>
Sat, 14 Dec 2013 00:44:55 +0000 (02:44 +0200)
committerscribu <mail@scribu.net>
Sat, 14 Dec 2013 00:44:55 +0000 (02:44 +0200)
php/WP_CLI/Runner.php

index e4e7910..dd5e595 100644 (file)
@@ -81,20 +81,15 @@ class Runner {
                                $path = $config['path'];
                        else
                                $path .= '/' . $config['path'];
-               } else {
-                       if ( file_exists( './index.php' ) ) {
-                               $index_code = explode( "\n", file_get_contents( './index.php' ) );
-
-                               foreach ( $index_code as $line ) {
-                                       if ( preg_match( '/^\s*require.+([\'"])(.*wp-blog-header\.php)\1/', $line, $matches ) ) {
-                                               $new_path = dirname( $matches[2] );
-                                               if ( Utils\is_path_absolute( $new_path ) ) {
-                                                       $path = $new_path;
-                                               } else {
-                                                       $path .= '/' . $new_path;
-                                               }
-                                               break;
-                                       }
+               } elseif ( file_exists( './index.php' ) ) {
+                       $index_code = file_get_contents( './index.php' );
+
+                       if ( preg_match( '/^\s*require.+([\'"])(.*wp-blog-header\.php)\1/m', $index_code, $matches ) ) {
+                               $new_path = dirname( $matches[2] );
+                               if ( Utils\is_path_absolute( $new_path ) ) {
+                                       $path = $new_path;
+                               } else {
+                                       $path .= '/' . $new_path;
                                }
                        }
                }