функция
since 5.0.0
wp_get_script_polyfill()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_get_script_polyfill( WP_Scripts $scripts, string[] $tests ): string
Описание
Возвращает содержимое встроенного скрипта, добавляющего скрипты-полифилы для браузеров, не прошедших указанные проверки. Переданный массив сопоставляет условие проверки поддержки возможности с дескриптором её скрипта-полифила.
Параметры
$scripts
WP_Scripts
обязательный
Объект WP_Scripts.
$tests
string[]
обязательный
Возможности для обнаружения.
Возвращаемое значение
string
Исходный код
wp-includes/script-loader.php:223
function wp_get_script_polyfill( $scripts, $tests ) {
$polyfill = '';
foreach ( $tests as $test => $handle ) {
if ( ! array_key_exists( $handle, $scripts->registered ) ) {
continue;
}
$src = $scripts->registered[ $handle ]->src;
$ver = $scripts->registered[ $handle ]->ver;
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && str_starts_with( $src, $scripts->content_url ) ) ) {
$src = $scripts->base_url . $src;
}
if ( ! empty( $ver ) ) {
$src = add_query_arg( 'ver', $ver, $src );
}
/** This filter is documented in wp-includes/class-wp-scripts.php */
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
if ( ! $src ) {
continue;
}
$polyfill .= (
// Test presence of feature...
'( ' . $test . ' ) || ' .
/*
* ...appending polyfill on any failures. Cautious viewers may balk
* at the `document.write`. Its caveat of synchronous mid-stream
* blocking write is exactly the behavior we need though.
*/
'document.write( \'<script src="' .
$src .
'"></scr\' + \'ipt>\' );'
);
}
return $polyfill;
}
История изменений
| Версия | Описание |
|---|---|
| 5.0.0 | Introduced. |

