X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..e0feb3b2e5b436a06bbb04fbc838d1cd6ec95399:/wp-includes/functions.wp-scripts.php
diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php
index ea719df3..01ad19b1 100644
--- a/wp-includes/functions.wp-scripts.php
+++ b/wp-includes/functions.wp-scripts.php
@@ -8,6 +8,44 @@
* @subpackage BackPress
*/
+/**
+ * Initialize $wp_scripts if it has not been set.
+ *
+ * @global WP_Scripts $wp_scripts
+ *
+ * @since 4.2.0
+ *
+ * @return WP_Scripts WP_Scripts instance.
+ */
+function wp_scripts() {
+ global $wp_scripts;
+ if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
+ $wp_scripts = new WP_Scripts();
+ }
+ return $wp_scripts;
+}
+
+/**
+ * Helper function to output a _doing_it_wrong message when applicable.
+ *
+ * @ignore
+ * @since 4.2.0
+ *
+ * @param string $function Function name.
+ */
+function _wp_scripts_maybe_doing_it_wrong( $function ) {
+ if ( did_action( 'init' ) ) {
+ return;
+ }
+
+ _doing_it_wrong( $function, sprintf(
+ __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
+ 'wp_enqueue_scripts
',
+ 'admin_enqueue_scripts
',
+ 'login_enqueue_scripts
'
+ ), '3.3' );
+}
+
/**
* Print scripts in document head that are in the $handles queue.
*
@@ -21,7 +59,7 @@
*
* @since 2.6.0
*
- * @param array|bool $handles Optional. Scripts to be printed. Default 'false'.
+ * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
* @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
*/
function wp_print_scripts( $handles = false ) {
@@ -31,22 +69,20 @@ function wp_print_scripts( $handles = false ) {
* @since 2.1.0
*/
do_action( 'wp_print_scripts' );
- if ( '' === $handles ) // for wp_head
+ if ( '' === $handles ) { // for wp_head
$handles = false;
+ }
- global $wp_scripts;
- if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
- if ( ! did_action( 'init' ) )
- _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
- 'wp_enqueue_scripts
', 'admin_enqueue_scripts
', 'login_enqueue_scripts
' ), '3.3' );
+ _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
- if ( !$handles )
+ global $wp_scripts;
+ if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
+ if ( ! $handles ) {
return array(); // No need to instantiate if nothing is there.
- else
- $wp_scripts = new WP_Scripts();
+ }
}
- return $wp_scripts->do_items( $handles );
+ return wp_scripts()->do_items( $handles );
}
/**
@@ -55,9 +91,9 @@ function wp_print_scripts( $handles = false ) {
* Registers a script to be linked later using the wp_enqueue_script() function.
*
* @see WP_Dependencies::add(), WP_Dependencies::add_data()
- * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
*
* @since 2.6.0
+ * @since 4.3.0 A return value was added.
*
* @param string $handle Name of the script. Should be unique.
* @param string $src Path to the script from the WordPress root directory. Example: '/js/myscript.js'.
@@ -69,19 +105,18 @@ function wp_print_scripts( $handles = false ) {
* If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'.
* @param bool $in_footer Optional. Whether to enqueue the script before or before