检索所有排队脚本和样式的唯一主机列表。

原型

wp_dependencies_unique_hosts()

返回值

(array)  排队脚本和样式的唯一主机列表。

源文件

路径:wp-includes/general-template.php

<?php
...
function wp_dependencies_unique_hosts() {
	global $wp_scripts, $wp_styles;
	$unique_hosts = array();
	foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
		if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
			foreach ( $dependencies->queue as $handle ) {
				if ( ! isset( $dependencies->registered[ $handle ] ) ) {
					continue;
				}
				/* @var _WP_Dependency $dependency */
				$dependency = $dependencies->registered[ $handle ];
				$parsed     = wp_parse_url( $dependency->src );
				if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
					$unique_hosts[] = $parsed['host'];
				}
			}
		}
	}
	return $unique_hosts;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_dependencies_unique_hosts/