159 } |
159 } |
160 |
160 |
161 /** |
161 /** |
162 * Check whether script has been added to WordPress Scripts. |
162 * Check whether script has been added to WordPress Scripts. |
163 * |
163 * |
164 * The values for list defaults to 'queue', which is the same as enqueue for |
164 * By default, checks if the script has been enqueued. You can also |
165 * scripts. |
165 * pass 'registered' to $list, to see if the script is registered, |
|
166 * and you can check processing statuses with 'to_do' and 'done'. |
166 * |
167 * |
167 * @since WP unknown; BP unknown |
168 * @since WP unknown; BP unknown |
168 * |
169 * |
169 * @param string $handle Handle used to add script. |
170 * @param string $handle Name of the script. |
170 * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do' |
171 * @param string $list Optional. Defaults to 'enqueued'. Values are |
171 * @return bool |
172 * 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'. |
|
173 * @return bool Whether script is in the list. |
172 */ |
174 */ |
173 function wp_script_is( $handle, $list = 'queue' ) { |
175 function wp_script_is( $handle, $list = 'enqueued' ) { |
174 global $wp_scripts; |
176 global $wp_scripts; |
175 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
177 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
176 if ( ! did_action( 'init' ) ) |
178 if ( ! did_action( 'init' ) ) |
177 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
179 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
178 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
180 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
179 $wp_scripts = new WP_Scripts(); |
181 $wp_scripts = new WP_Scripts(); |
180 } |
182 } |
181 |
183 |
182 $query = $wp_scripts->query( $handle, $list ); |
184 return (bool) $wp_scripts->query( $handle, $list ); |
183 |
|
184 if ( is_object( $query ) ) |
|
185 return true; |
|
186 |
|
187 return $query; |
|
188 } |
185 } |