WP_CLI

Runner::find_wp_root()privateWP-CLI 1.0

Find the directory that contains the WordPress files. Defaults to the current working dir.

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

Хуков нет.

Возвращает

Строку. An absolute path

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

// private - только в коде основоного (родительского) класса
$result = $this->find_wp_root();

Код Runner::find_wp_root() WP-CLI 2.8.0-alpha

private function find_wp_root() {
	if ( isset( $this->config['path'] ) &&
		( is_bool( $this->config['path'] ) || empty( $this->config['path'] ) )
	) {
		WP_CLI::error( 'The --path parameter cannot be empty when provided.' );
	}

	if ( ! empty( $this->config['path'] ) ) {
		$path = $this->config['path'];
		if ( ! Utils\is_path_absolute( $path ) ) {
			$path = getcwd() . '/' . $path;
		}

		return $path;
	}

	if ( $this->cmd_starts_with( [ 'core', 'download' ] ) ) {
		return getcwd();
	}

	$dir = getcwd();

	while ( is_readable( $dir ) ) {
		if ( file_exists( "$dir/wp-load.php" ) ) {
			return $dir;
		}

		if ( file_exists( "$dir/index.php" ) ) {
			$path = self::extract_subdir_path( "$dir/index.php" );
			if ( ! empty( $path ) ) {
				return $path;
			}
		}

		$parent_dir = dirname( $dir );
		if ( empty( $parent_dir ) || $parent_dir === $dir ) {
			break;
		}
		$dir = $parent_dir;
	}

	return getcwd();
}