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

git-svn-id: http://core.svn.wordpress.org/trunk@21672 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-08-30 18:57:57 +00:00
parent a2580a80d1
commit e03bb0d1ac
3 changed files with 38 additions and 40 deletions

View File

@ -196,24 +196,27 @@ class WP_Dependencies {
}
}
function query( $handle, $list = 'registered' ) { // registered, queue, done, to_do
switch ( $list ) :
case 'registered':
case 'scripts': // back compat
if ( isset($this->registered[$handle]) )
return $this->registered[$handle];
break;
case 'to_print': // back compat
case 'printed': // back compat
if ( 'to_print' == $list )
$list = 'to_do';
else
$list = 'printed';
default:
if ( in_array($handle, $this->$list) )
return true;
break;
endswitch;
function query( $handle, $list = 'registered' ) {
switch ( $list ) {
case 'registered' :
case 'scripts': // back compat
if ( isset( $this->registered[ $handle ] ) )
return $this->registered[ $handle ];
return false;
case 'enqueued' :
case 'queue' :
return in_array( $handle, $this->queue );
case 'to_do' :
case 'to_print': // back compat
return in_array( $handle, $this->to_do );
case 'done' :
case 'printed': // back compat
return in_array( $handle, $this->done );
}
return false;
}

View File

@ -161,16 +161,18 @@ function wp_dequeue_script( $handle ) {
/**
* Check whether script has been added to WordPress Scripts.
*
* The values for list defaults to 'queue', which is the same as enqueue for
* scripts.
* By default, checks if the script has been enqueued. You can also
* pass 'registered' to $list, to see if the script is registered,
* and you can check processing statuses with 'to_do' and 'done'.
*
* @since WP unknown; BP unknown
*
* @param string $handle Handle used to add script.
* @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do'
* @return bool
* @param string $handle Name of the script.
* @param string $list Optional. Defaults to 'enqueued'. Values are
* 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.
* @return bool Whether script is in the list.
*/
function wp_script_is( $handle, $list = 'queue' ) {
function wp_script_is( $handle, $list = 'enqueued' ) {
global $wp_scripts;
if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
if ( ! did_action( 'init' ) )
@ -179,10 +181,5 @@ function wp_script_is( $handle, $list = 'queue' ) {
$wp_scripts = new WP_Scripts();
}
$query = $wp_scripts->query( $handle, $list );
if ( is_object( $query ) )
return true;
return $query;
return (bool) $wp_scripts->query( $handle, $list );
}

View File

@ -167,16 +167,19 @@ function wp_dequeue_style( $handle ) {
/**
* Check whether style has been added to WordPress Styles.
*
* The values for list defaults to 'queue', which is the same as wp_enqueue_style().
* By default, checks if the style has been enqueued. You can also
* pass 'registered' to $list, to see if the style is registered,
* and you can check processing statuses with 'to_do' and 'done'.
*
* @since WP unknown; BP unknown
* @global object $wp_styles The WP_Styles object for printing styles.
*
* @param string $handle Name of the stylesheet.
* @param string $list Values are 'registered', 'done', 'queue' and 'to_do'.
* @return bool True on success, false on failure.
* @param string $list Optional. Defaults to 'enqueued'. Values are
* 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.
* @return bool Whether style is in the list.
*/
function wp_style_is( $handle, $list = 'queue' ) {
function wp_style_is( $handle, $list = 'enqueued' ) {
global $wp_styles;
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
if ( ! did_action( 'init' ) )
@ -185,10 +188,5 @@ function wp_style_is( $handle, $list = 'queue' ) {
$wp_styles = new WP_Styles();
}
$query = $wp_styles->query( $handle, $list );
if ( is_object( $query ) )
return true;
return $query;
return (bool) $wp_styles->query( $handle, $list );
}