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: https://develop.svn.wordpress.org/trunk@21672 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-08-30 18:57:57 +00:00
parent ceaf979590
commit 9d6e1b33ca
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 ) : function query( $handle, $list = 'registered' ) {
case 'registered': switch ( $list ) {
case 'scripts': // back compat case 'registered' :
if ( isset($this->registered[$handle]) ) case 'scripts': // back compat
return $this->registered[$handle]; if ( isset( $this->registered[ $handle ] ) )
break; return $this->registered[ $handle ];
case 'to_print': // back compat return false;
case 'printed': // back compat
if ( 'to_print' == $list ) case 'enqueued' :
$list = 'to_do'; case 'queue' :
else return in_array( $handle, $this->queue );
$list = 'printed';
default: case 'to_do' :
if ( in_array($handle, $this->$list) ) case 'to_print': // back compat
return true; return in_array( $handle, $this->to_do );
break;
endswitch; case 'done' :
case 'printed': // back compat
return in_array( $handle, $this->done );
}
return false; return false;
} }

View File

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

View File

@ -167,16 +167,19 @@ function wp_dequeue_style( $handle ) {
/** /**
* Check whether style has been added to WordPress Styles. * 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 * @since WP unknown; BP unknown
* @global object $wp_styles The WP_Styles object for printing styles. * @global object $wp_styles The WP_Styles object for printing styles.
* *
* @param string $handle Name of the stylesheet. * @param string $handle Name of the stylesheet.
* @param string $list Values are 'registered', 'done', 'queue' and 'to_do'. * @param string $list Optional. Defaults to 'enqueued'. Values are
* @return bool True on success, false on failure. * '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; global $wp_styles;
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
if ( ! did_action( 'init' ) ) if ( ! did_action( 'init' ) )
@ -185,10 +188,5 @@ function wp_style_is( $handle, $list = 'queue' ) {
$wp_styles = new WP_Styles(); $wp_styles = new WP_Styles();
} }
$query = $wp_styles->query( $handle, $list ); return (bool) $wp_styles->query( $handle, $list );
if ( is_object( $query ) )
return true;
return $query;
} }