Automattic\WooCommerce\Internal\Utilities

URL::get_all_parent_urls()publicWC 1.0

Returns all possible parent URLs for the current URL.

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

No Hooks.

Return

String[].

Usage

$URL = new URL();
$URL->get_all_parent_urls(): array;

Code of URL::get_all_parent_urls() WC 7.1.0

public function get_all_parent_urls(): array {
	$max_parent = count( $this->path_parts );
	$parents    = array();

	/*
	 * If we are looking at a relative path that begins with at least one traversal (example: "../../foo")
	 * then we should only return one parent URL (otherwise, we'd potentially have to return an infinite
	 * number of parent URLs since we can't know how far the tree extends).
	 */
	if ( $max_parent > 0 && ! $this->is_absolute && '..' === $this->path_parts[0] ) {
		$max_parent = 1;
	}

	for ( $level = 1; $level <= $max_parent; $level++ ) {
		$parents[] = $this->get_parent_url( $level );
	}

	return $parents;
}