wp_dependencies_unique_hosts

The timeline below displays how wordpress function wp_dependencies_unique_hosts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Retrieves a list of unique hosts of all enqueued scripts and styles.
 *
 * @since 4.6.0
 *
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 * @global WP_Styles  $wp_styles  The WP_Styles object for printing styles.
 *
 * @return string[] A list of unique hosts of enqueued scripts and styles.
 */
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, true) && $parsed['host'] !== $_SERVER['SERVER_NAME']) {
                    $unique_hosts[] = $parsed['host'];
                }
            }
        }
    }
    return $unique_hosts;
}

WordPress Version: 5.5

/**
 * Retrieves a list of unique hosts of all enqueued scripts and styles.
 *
 * @since 4.6.0
 *
 * @return string[] A list of unique hosts of enqueued scripts and styles.
 */
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, true) && $parsed['host'] !== $_SERVER['SERVER_NAME']) {
                    $unique_hosts[] = $parsed['host'];
                }
            }
        }
    }
    return $unique_hosts;
}

WordPress Version: 5.4

/**
 * Retrieves a list of unique hosts of all enqueued scripts and styles.
 *
 * @since 4.6.0
 *
 * @return string[] A list of unique hosts of enqueued scripts and styles.
 */
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;
}

WordPress Version: 4.6

/**
 * Retrieves a list of unique hosts of all enqueued scripts and styles.
 *
 * @since 4.6.0
 *
 * @return array A list of unique hosts of enqueued scripts and styles.
 */
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;
}