From e03bb0d1acc9de5ed181ad67d7934f8701e67383 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 30 Aug 2012 18:57:57 +0000 Subject: [PATCH] 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 --- wp-includes/class.wp-dependencies.php | 39 ++++++++++++++------------- wp-includes/functions.wp-scripts.php | 21 +++++++-------- wp-includes/functions.wp-styles.php | 18 ++++++------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/wp-includes/class.wp-dependencies.php b/wp-includes/class.wp-dependencies.php index b59b6bc2db..7aa5e5cb34 100644 --- a/wp-includes/class.wp-dependencies.php +++ b/wp-includes/class.wp-dependencies.php @@ -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; } diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index a8dac35c25..49b760f04a 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -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 ); } diff --git a/wp-includes/functions.wp-styles.php b/wp-includes/functions.wp-styles.php index 8896615438..49095f3b7a 100644 --- a/wp-includes/functions.wp-styles.php +++ b/wp-includes/functions.wp-styles.php @@ -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 ); }