WP_CLI
Runner::extract_subdir_path()
Attempts to find the path to the WP installation inside index.php
Method of the class: Runner{}
No Hooks.
Return
String|false
.
Usage
$result = Runner::extract_subdir_path( $index_path );
- $index_path(string) (required)
- -
Runner::extract_subdir_path() Runner::extract subdir path code WP-CLI 2.8.0-alpha
private static function extract_subdir_path( $index_path ) { $index_code = file_get_contents( $index_path ); if ( ! preg_match( '|^\s*require\s*\(?\s*(.+?)/wp-blog-header\.php([\'"])|m', $index_code, $matches ) ) { return false; } $wp_path_src = $matches[1] . $matches[2]; $wp_path_src = Utils\replace_path_consts( $wp_path_src, $index_path ); $wp_path = eval( "return $wp_path_src;" ); // phpcs:ignore Squiz.PHP.Eval.Discouraged if ( ! Utils\is_path_absolute( $wp_path ) ) { $wp_path = dirname( $index_path ) . "/$wp_path"; } return $wp_path; }