wp_dependencies_unique_hosts

Retrieves a list of unique hosts of all enqueued scripts and styles.

Description

(array) wp_dependencies_unique_hosts(); 

Returns (array)

A list of unique hosts of enqueued scripts and styles.


Usage

  1. if ( !function_exists( 'wp_dependencies_unique_hosts' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_dependencies_unique_hosts(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function wp_dependencies_unique_hosts() { 
  2. global $wp_scripts, $wp_styles; 
  3.  
  4. $unique_hosts = array(); 
  5.  
  6. foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) { 
  7. if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) { 
  8. foreach ( $dependencies->queue as $handle ) { 
  9. if ( ! isset( $dependencies->registered[ $handle ] ) ) { 
  10. continue; 
  11.  
  12. /** @var _WP_Dependency $dependency */ 
  13. $dependency = $dependencies->registered[ $handle ]; 
  14. $parsed = wp_parse_url( $dependency->src ); 
  15.  
  16. if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) { 
  17. $unique_hosts[] = $parsed['host']; 
  18.  
  19. return $unique_hosts;