wp_dependencies_unique_hosts()
Retrieves a list of unique hosts of all enqueued scripts and styles.
Хуков нет.
Возвращает
Строку[]
. A list of unique hosts of enqueued scripts and styles.
Использование
wp_dependencies_unique_hosts();
Заметки
- Global. WP_Scripts. $wp_scripts The WP_Scripts object for printing scripts.
- Global. WP_Styles. $wp_styles The WP_Styles object for printing styles.
Список изменений
С версии 4.6.0 | Введена. |
Код wp_dependencies_unique_hosts() wp dependencies unique hosts WP 6.7.1
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; }