Automattic\WooCommerce\Admin
WCAdminHelper::get_normalized_url_path()
Get normalized URL path.
- Only keep the path and query string (if any).
- Remove wp home path from the URL path if WP is installed in a subdirectory.
- Remove leading and trailing slashes.
For example:
- https://example.com/wordpress/shop/uncategorized/test/?add-to-cart=123 => shop/uncategorized/test/?add-to-cart=123
Method of the class: WCAdminHelper{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WCAdminHelper::get_normalized_url_path( $url );
- $url(string) (required)
- URL to normalize.
WCAdminHelper::get_normalized_url_path() WCAdminHelper::get normalized url path code WC 9.7.1
private static function get_normalized_url_path( $url ) { $query = wp_parse_url( $url, PHP_URL_QUERY ); $path = wp_parse_url( $url, PHP_URL_PATH ) . ( $query ? '?' . $query : '' ); $home_path = wp_parse_url( site_url(), PHP_URL_PATH ) ?? ''; $normalized_path = trim( substr( $path, strlen( $home_path ) ), '/' ); return $normalized_path; }