Automattic\WooCommerce\Blocks\Utils

Utils::get_absolute_script_urlpublic staticWC 1.0

Resolve a (possibly relative) script src to an absolute URL the same way WordPress core does in WP_Scripts::do_item(): a relative src is resolved against the scripts base URL (the site URL), unless it already points at the content directory. This keeps the resulting URL consistent with what WordPress itself would emit, including on non-default directory layouts (e.g. a custom WP_CONTENT_DIR/WP_CONTENT_URL).

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

Хуков нет.

Возвращает

Строку. The absolute script URL.

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

$result = Utils::get_absolute_script_url( $src );
$src(строка) (обязательный)
The script src, which may be relative or absolute.

Код Utils::get_absolute_script_url() WC 11.0.1

public static function get_absolute_script_url( $src ) {
	$wp_scripts = wc_get_container()->get( LegacyProxy::class )->call_function( 'wp_scripts' );
	if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
		$src = $wp_scripts->base_url . $src;
	}
	return $src;
}