4 * Prints script tags in document head
6 * Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load,
7 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
8 * Does make use of already instantiated $wp_scripts if present.
9 * Use provided wp_print_scripts hook to register/enqueue new scripts.
11 * @see WP_Scripts::print_scripts()
13 function wp_print_scripts( $handles = false ) {
14 do_action( 'wp_print_scripts' );
15 if ( '' === $handles ) // for wp_head
19 if ( !is_a($wp_scripts, 'WP_Scripts') ) {
21 return array(); // No need to instantiate if nothing's there.
23 $wp_scripts = new WP_Scripts();
26 return $wp_scripts->do_items( $handles );
29 function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
31 if ( !is_a($wp_scripts, 'WP_Scripts') )
32 $wp_scripts = new WP_Scripts();
34 $wp_scripts->add( $handle, $src, $deps, $ver );
40 * Localizes only if script has already been added
42 * @see WP_Script::localize()
44 function wp_localize_script( $handle, $object_name, $l10n ) {
46 if ( !is_a($wp_scripts, 'WP_Scripts') )
49 return $wp_scripts->localize( $handle, $object_name, $l10n );
52 function wp_deregister_script( $handle ) {
54 if ( !is_a($wp_scripts, 'WP_Scripts') )
55 $wp_scripts = new WP_Scripts();
57 $wp_scripts->remove( $handle );
63 * Registers the script if src provided (does NOT overwrite) and enqueues.
65 * @see WP_Script::add(), WP_Script::enqueue()
67 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
69 if ( !is_a($wp_scripts, 'WP_Scripts') )
70 $wp_scripts = new WP_Scripts();
73 $_handle = explode('?', $handle);
74 $wp_scripts->add( $_handle[0], $src, $deps, $ver );
76 $wp_scripts->enqueue( $handle );