WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/28/2011 06:24:00 PM (10 years ago)
Author:
azaozz
Message:

Introduce WP_Dependencies::get_data() method, change scripts and styles priority to follow the "natural" order in HTML, i.e. the last one wins, props scribu, see #11520

File:
1 edited

Legend:

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

    r18464 r18480  
    5555
    5656    function print_script_data( $handle, $echo = true, $_l10n = false ) {
    57         if ( empty($this->registered[$handle]->extra['data']) )
    58             return false;
    59 
    6057        if ( $_l10n ) {
    61             $name = $this->registered[$handle]->extra['l10n'][0];
    62             $data = $this->registered[$handle]->extra['l10n'][1];
     58            list( $name, $data ) = $this->get_data( $handle, 'l10n' );
    6359            $after = '';
    6460
     
    6965            $output = "var $name = " . json_encode($data) . "; $after\n";
    7066        } else {
    71             foreach ( (array) $this->registered[$handle]->extra['data'] as $name => $data ) {
     67            $data = $this->get_data( $handle, 'data' );
     68
     69            if ( empty( $data ) )
     70                return false;
     71
     72            foreach ( (array) $data as $name => $data ) {
    7273                $output = "var $name = " . json_encode($data) . ";\n";
    7374            }
     
    143144     * Localizes only if script has already been added
    144145     *
    145      * @since
    146146     * @deprecated WP 3.3
    147147     */
     
    158158     * @param string $handle Script name
    159159     * @param string $name Name of JS object to hold the data
    160      * @param array $data Associative array of JS name => value
     160     * @param array $args Associative array of JS object attributes
    161161     * @return bool Successful or not
    162162     */
    163     function add_script_data( $handle, $name, $data ) {
    164         if ( !$name || !is_array($data) )
    165             return false;
    166 
    167         if ( !empty( $this->registered[$handle]->extra['data'][$name] ) )
    168             $data = array_merge( $data, (array) $this->registered[$handle]->extra['data'][$name] );
    169 
    170         return $this->add_data( $handle, 'data', array( $name => $data ) );
     163    function add_script_data( $handle, $name, $args ) {
     164        if ( !$name || !is_array( $args ) )
     165            return false;
     166
     167        $data = $this->get_data( $handle, 'data' );
     168
     169        if ( !empty( $data[$name] ) )
     170            $args = array_merge( $data[$name], $args );
     171
     172        return $this->add_data( $handle, 'data', array( $name => $args ) );
    171173    }
    172174
    173175    function set_group( $handle, $recursion, $group = false ) {
    174         $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0;
     176        $grp = (int) $this->get_data( $handle, 'group' );
     177
    175178        if ( false !== $group && $grp > $group )
    176179            $grp = $group;
Note: See TracChangeset for help on using the changeset viewer.