# wp_get_script_polyfill()

URL: https://chugunov.pro/api-wordpress/functions/wp_get_script_polyfill/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.0.0.

## Сигнатура

```php
wp_get_script_polyfill( WP_Scripts $scripts, string[] $tests ): string
```

## Описание

Возвращает содержимое встроенного скрипта, добавляющего скрипты-полифилы для браузеров, не прошедших указанные проверки. Переданный массив сопоставляет условие проверки поддержки возможности с дескриптором её скрипта-полифила.

## Параметры

- `$scripts` `WP_Scripts` — обязательный. Объект WP_Scripts.
- `$tests` `string[]` — обязательный. Возможности для обнаружения.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/script-loader.php:223`

```php
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.

## Связанные

Использует: [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`add_query_arg`](https://chugunov.pro/api-wordpress/functions/add_query_arg/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_get_script_polyfill/
