WP_CLI

Runner::extract_subdir_path()private staticWP-CLI 1.0

Attempts to find the path to the WP installation inside index.php

Метод класса: Runner{}

Хуков нет.

Возвращает

Строку|false.

Использование

$result = Runner::extract_subdir_path( $index_path );
$index_path(строка) (обязательный)
-

Код Runner::extract_subdir_path() 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;
}