Make WordPress Core

Changeset 21672


Ignore:
Timestamp:
08/30/2012 06:57:57 PM (12 years ago)
Author:
nacin
Message:

Have wp_script_is() and wp_style_is() accept 'enqueued', as it reads better than 'queue' and is consistent with 'registered'. fixes #21741.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

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

    r21481 r21672  
    197197    }
    198198
    199     function query( $handle, $list = 'registered' ) { // registered, queue, done, to_do
    200         switch ( $list ) :
    201         case 'registered':
    202         case 'scripts': // back compat
    203             if ( isset($this->registered[$handle]) )
    204                 return $this->registered[$handle];
    205             break;
    206         case 'to_print': // back compat
    207         case 'printed': // back compat
    208             if ( 'to_print' == $list )
    209                 $list = 'to_do';
    210             else
    211                 $list = 'printed';
    212         default:
    213             if ( in_array($handle, $this->$list) )
    214                 return true;
    215             break;
    216         endswitch;
     199
     200    function query( $handle, $list = 'registered' ) {
     201        switch ( $list ) {
     202            case 'registered' :
     203            case 'scripts': // back compat
     204                if ( isset( $this->registered[ $handle ] ) )
     205                    return $this->registered[ $handle ];
     206                return false;
     207
     208            case 'enqueued' :
     209            case 'queue' :
     210                return in_array( $handle, $this->queue );
     211
     212            case 'to_do' :
     213            case 'to_print': // back compat
     214                return in_array( $handle, $this->to_do );
     215
     216            case 'done' :
     217            case 'printed': // back compat
     218                return in_array( $handle, $this->done );
     219        }
    217220        return false;
    218221    }
  • trunk/wp-includes/functions.wp-scripts.php

    r19687 r21672  
    162162 * Check whether script has been added to WordPress Scripts.
    163163 *
    164  * The values for list defaults to 'queue', which is the same as enqueue for
    165  * scripts.
     164 * By default, checks if the script has been enqueued. You can also
     165 * pass 'registered' to $list, to see if the script is registered,
     166 * and you can check processing statuses with 'to_do' and 'done'.
    166167 *
    167168 * @since WP unknown; BP unknown
    168169 *
    169  * @param string $handle Handle used to add script.
    170  * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do'
    171  * @return bool
     170 * @param string $handle Name of the script.
     171 * @param string $list Optional. Defaults to 'enqueued'. Values are
     172 *  'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.
     173 * @return bool Whether script is in the list.
    172174 */
    173 function wp_script_is( $handle, $list = 'queue' ) {
     175function wp_script_is( $handle, $list = 'enqueued' ) {
    174176    global $wp_scripts;
    175177    if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     
    180182    }
    181183
    182     $query = $wp_scripts->query( $handle, $list );
    183 
    184     if ( is_object( $query ) )
    185         return true;
    186 
    187     return $query;
     184    return (bool) $wp_scripts->query( $handle, $list );
    188185}
  • trunk/wp-includes/functions.wp-styles.php

    r19687 r21672  
    168168 * Check whether style has been added to WordPress Styles.
    169169 *
    170  * The values for list defaults to 'queue', which is the same as wp_enqueue_style().
     170 * By default, checks if the style has been enqueued. You can also
     171 * pass 'registered' to $list, to see if the style is registered,
     172 * and you can check processing statuses with 'to_do' and 'done'.
    171173 *
    172174 * @since WP unknown; BP unknown
     
    174176 *
    175177 * @param string $handle Name of the stylesheet.
    176  * @param string $list Values are 'registered', 'done', 'queue' and 'to_do'.
    177  * @return bool True on success, false on failure.
     178 * @param string $list Optional. Defaults to 'enqueued'. Values are
     179 *  'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.
     180 * @return bool Whether style is in the list.
    178181 */
    179 function wp_style_is( $handle, $list = 'queue' ) {
     182function wp_style_is( $handle, $list = 'enqueued' ) {
    180183    global $wp_styles;
    181184    if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     
    186189    }
    187190
    188     $query = $wp_styles->query( $handle, $list );
    189 
    190     if ( is_object( $query ) )
    191         return true;
    192 
    193     return $query;
     191    return (bool) $wp_styles->query( $handle, $list );
    194192}
Note: See TracChangeset for help on using the changeset viewer.