Projects : mp-wp : mp-wp_genesis

mp-wp/wp-includes/functions.wp-scripts.php

Dir - Raw

1<?php
2/**
3 * BackPress script procedural API.
4 *
5 * @package BackPress
6 * @since r16
7 */
8
9/**
10 * Prints script tags in document head.
11 *
12 * Called by admin-header.php and by wp_head hook. Since it is called by wp_head
13 * on every page load, the function does not instantiate the WP_Scripts object
14 * unless script names are explicitly passed. Does make use of already
15 * instantiated $wp_scripts if present. Use provided wp_print_scripts hook to
16 * register/enqueue new scripts.
17 *
18 * @since r16
19 * @see WP_Scripts::print_scripts()
20 */
21function wp_print_scripts( $handles = false ) {
22 do_action( 'wp_print_scripts' );
23 if ( '' === $handles ) // for wp_head
24 $handles = false;
25
26 global $wp_scripts;
27 if ( !is_a($wp_scripts, 'WP_Scripts') ) {
28 if ( !$handles )
29 return array(); // No need to instantiate if nothing's there.
30 else
31 $wp_scripts = new WP_Scripts();
32 }
33
34 return $wp_scripts->do_items( $handles );
35}
36
37/**
38 * Register new JavaScript file.
39 *
40 * @since r16
41 * @see WP_Scripts::add() For parameter information.
42 */
43function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
44 global $wp_scripts;
45 if ( !is_a($wp_scripts, 'WP_Scripts') )
46 $wp_scripts = new WP_Scripts();
47
48 $wp_scripts->add( $handle, $src, $deps, $ver );
49}
50
51/**
52 * Localizes a script.
53 *
54 * Localizes only if script has already been added.
55 *
56 * @since r16
57 * @see WP_Script::localize()
58 */
59function wp_localize_script( $handle, $object_name, $l10n ) {
60 global $wp_scripts;
61 if ( !is_a($wp_scripts, 'WP_Scripts') )
62 return false;
63
64 return $wp_scripts->localize( $handle, $object_name, $l10n );
65}
66
67/**
68 * Remove a registered script.
69 *
70 * @since r16
71 * @see WP_Scripts::remove() For parameter information.
72 */
73function wp_deregister_script( $handle ) {
74 global $wp_scripts;
75 if ( !is_a($wp_scripts, 'WP_Scripts') )
76 $wp_scripts = new WP_Scripts();
77
78 $wp_scripts->remove( $handle );
79}
80
81/**
82 * Enqueues script.
83 *
84 * Registers the script if src provided (does NOT overwrite) and enqueues.
85 *
86 * @since r16
87 * @see WP_Script::add(), WP_Script::enqueue()
88*/
89function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
90 global $wp_scripts;
91 if ( !is_a($wp_scripts, 'WP_Scripts') )
92 $wp_scripts = new WP_Scripts();
93
94 if ( $src ) {
95 $_handle = explode('?', $handle);
96 $wp_scripts->add( $_handle[0], $src, $deps, $ver );
97 }
98 $wp_scripts->enqueue( $handle );
99}