WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Scripts::localize() WP 2.1.0

Localizes a script, only if the script has already been added.

Это метод класса: WP_Scripts

Хуков нет.

Возвращает

true/false. True on success, false on failure.

Использование

$WP_Scripts = new WP_Scripts();
$var = $WP_Scripts->localize( $handle, $object_name, $l10n );
$handle(строка) (обязательный)
Name of the script to attach data to.
$object_name(строка) (обязательный)
Name of the variable that will contain the data.
$l10n(массив) (обязательный)
Array of data to localize.

Список изменений

С версии 2.1.0 Введена.

Код WP Scripts::localize: wp-includes/class.wp-scripts.php WP 5.2.4

<?php
public function localize( $handle, $object_name, $l10n ) {
	if ( $handle === 'jquery' ) {
		$handle = 'jquery-core';
	}

	if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present.
		$after = $l10n['l10n_print_after'];
		unset( $l10n['l10n_print_after'] );
	}

	foreach ( (array) $l10n as $key => $value ) {
		if ( ! is_scalar( $value ) ) {
			continue;
		}

		$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
	}

	$script = "var $object_name = " . wp_json_encode( $l10n ) . ';';

	if ( ! empty( $after ) ) {
		$script .= "\n$after;";
	}

	$data = $this->get_data( $handle, 'data' );

	if ( ! empty( $data ) ) {
		$script = "$data\n$script";
	}

	return $this->add_data( $handle, 'data', $script );
}