X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/72836ec95a52eacbda4dc5aa296b7dd6de08bd3b..138998bbd8f7a1ac38b2f1eacbdf7cd522be4b13:/wp-includes/functions.wp-scripts.php
diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php
index e89553b1..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,27 +59,30 @@
*
* @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 ) {
+ /**
+ * Fires before scripts in the $handles queue are printed.
+ *
+ * @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 );
}
/**
@@ -50,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'.
@@ -64,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