WC_Frontend_Scripts::localize_script
Localize a WC script once.
Method of the class: WC_Frontend_Scripts{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Frontend_Scripts::localize_script( $handle );
- $handle(string) (required)
- Script handle the data will be attached to.
Changelog
| Since 2.3.0 | Introduced. |
| Since 2.3.0 | this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0. |
WC_Frontend_Scripts::localize_script() WC Frontend Scripts::localize script code WC 10.6.2
private static function localize_script( $handle ) {
if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
$data = self::get_script_data( $handle );
if ( ! $data ) {
return;
}
$name = str_replace( '-', '_', $handle ) . '_params';
self::$wp_localize_scripts[] = $handle;
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
}
}