Make WordPress Core


Ignore:
Timestamp:
07/25/2011 12:36:06 AM (13 years ago)
Author:
azaozz
Message:

Use json_encode() for adding script data (formerly l10n). Add the same functionality to WP_Styles for adding inline css after a stylesheet has been outputted. See #11520

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.wp-scripts.php

    r15601 r18464  
    2727    if ( !is_a($wp_scripts, 'WP_Scripts') ) {
    2828        if ( !$handles )
    29             return array(); // No need to instantiate if nothing's there.
     29            return array(); // No need to instantiate if nothing is there.
    3030        else
    3131            $wp_scripts = new WP_Scripts();
     
    3636
    3737/**
    38  * Register new JavaScript file.
     38 * Register new Javascript file.
    3939 *
    4040 * @since r16
     
    5757
    5858/**
    59  * Localizes a script.
     59 * Adds extra Javascript.
    6060 *
    61  * Localizes only if script has already been added.
    62  *
    63  * @since r16
    64  * @see WP_Scripts::localize()
     61 * Works only if the script has already been added.
     62 * Accepts an associative array $data and creates JS object:
     63 * "$name" = {
     64 *   key: value,
     65 *   key: value,
     66 *   ...
     67 * }
     68 * The $name is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/
     69 * The $data array is JSON encoded. If called more than once for the same $handle, with the same $name,
     70 * the object would contain all values. In that case if two or more keys are the same,
     71 * the first value is kept and subsequent values are ignored.
     72 *
     73 * @since 3.3
     74 * @see WP_Scripts::add_script_data()
    6575 */
    66 function wp_localize_script( $handle, $object_name, $l10n ) {
     76function wp_add_script_data( $handle, $name, $data ) {
    6777    global $wp_scripts;
    6878    if ( !is_a($wp_scripts, 'WP_Scripts') )
    6979        return false;
    7080
    71     return $wp_scripts->localize( $handle, $object_name, $l10n );
     81    return $wp_scripts->add_script_data( $handle, $name, $data );
    7282}
    7383
Note: See TracChangeset for help on using the changeset viewer.