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_Dependencies::print_scripts()
|
---|
20 | */
|
---|
21 | function 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_Dependencies::add() For parameter information.
|
---|
42 | */
|
---|
43 | function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = 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 | if ( $in_footer )
|
---|
50 | $wp_scripts->add_data( $handle, 'group', 1 );
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Localizes a script.
|
---|
55 | *
|
---|
56 | * Localizes only if script has already been added.
|
---|
57 | *
|
---|
58 | * @since r16
|
---|
59 | * @see WP_Script::localize()
|
---|
60 | */
|
---|
61 | function wp_localize_script( $handle, $object_name, $l10n ) {
|
---|
62 | global $wp_scripts;
|
---|
63 | if ( !is_a($wp_scripts, 'WP_Scripts') )
|
---|
64 | return false;
|
---|
65 |
|
---|
66 | return $wp_scripts->localize( $handle, $object_name, $l10n );
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Remove a registered script.
|
---|
71 | *
|
---|
72 | * @since r16
|
---|
73 | * @see WP_Scripts::remove() For parameter information.
|
---|
74 | */
|
---|
75 | function wp_deregister_script( $handle ) {
|
---|
76 | global $wp_scripts;
|
---|
77 | if ( !is_a($wp_scripts, 'WP_Scripts') )
|
---|
78 | $wp_scripts = new WP_Scripts();
|
---|
79 |
|
---|
80 | $wp_scripts->remove( $handle );
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Enqueues script.
|
---|
85 | *
|
---|
86 | * Registers the script if src provided (does NOT overwrite) and enqueues.
|
---|
87 | *
|
---|
88 | * @since r16
|
---|
89 | * @see WP_Script::add(), WP_Script::enqueue()
|
---|
90 | */
|
---|
91 | function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
|
---|
92 | global $wp_scripts;
|
---|
93 | if ( !is_a($wp_scripts, 'WP_Scripts') )
|
---|
94 | $wp_scripts = new WP_Scripts();
|
---|
95 |
|
---|
96 | if ( $src ) {
|
---|
97 | $_handle = explode('?', $handle);
|
---|
98 | $wp_scripts->add( $_handle[0], $src, $deps, $ver );
|
---|
99 | if ( $in_footer )
|
---|
100 | $wp_scripts->add_data( $_handle[0], 'group', 1 );
|
---|
101 | }
|
---|
102 | $wp_scripts->enqueue( $handle );
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Check whether script has been added to WordPress Scripts.
|
---|
107 | *
|
---|
108 | * The values for list defaults to 'queue', which is the same as enqueue for
|
---|
109 | * scripts.
|
---|
110 | *
|
---|
111 | * @since WP unknown; BP unknown
|
---|
112 | *
|
---|
113 | * @param string $handle Handle used to add script.
|
---|
114 | * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do'
|
---|
115 | * @return bool
|
---|
116 | */
|
---|
117 | function wp_script_is( $handle, $list = 'queue' ) {
|
---|
118 | global $wp_scripts;
|
---|
119 | if ( !is_a($wp_scripts, 'WP_Scripts') )
|
---|
120 | $wp_scripts = new WP_Scripts();
|
---|
121 |
|
---|
122 | $query = $wp_scripts->query( $handle, $list );
|
---|
123 |
|
---|
124 | if ( is_object( $query ) )
|
---|
125 | return true;
|
---|
126 |
|
---|
127 | return $query;
|
---|
128 | }
|
---|