diff --git wp-includes/functions.wp-scripts.php wp-includes/functions.wp-scripts.php
index a8dac35..cd2943e 100644
|
|
function wp_print_scripts( $handles = false ) { |
23 | 23 | if ( '' === $handles ) // for wp_head |
24 | 24 | $handles = false; |
25 | 25 | |
26 | | global $wp_scripts; |
27 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
28 | | if ( ! did_action( 'init' ) ) |
29 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
30 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
31 | | |
32 | | if ( !$handles ) |
33 | | return array(); // No need to instantiate if nothing is there. |
34 | | else |
35 | | $wp_scripts = new WP_Scripts(); |
36 | | } |
| 26 | if ( !$handles ) |
| 27 | return array(); // No need to instantiate if nothing is there. |
37 | 28 | |
38 | | return $wp_scripts->do_items( $handles ); |
| 29 | return wp_scripts()->do_items( $handles ); |
39 | 30 | } |
40 | 31 | |
41 | 32 | /** |
… |
… |
function wp_print_scripts( $handles = false ) { |
50 | 41 | * @return null |
51 | 42 | */ |
52 | 43 | function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
53 | | global $wp_scripts; |
54 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
55 | | if ( ! did_action( 'init' ) ) |
56 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
57 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
58 | | $wp_scripts = new WP_Scripts(); |
59 | | } |
| 44 | $wp_scripts = wp_scripts(); |
60 | 45 | |
61 | 46 | $wp_scripts->add( $handle, $src, $deps, $ver ); |
62 | 47 | if ( $in_footer ) |
… |
… |
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f |
84 | 69 | * @return bool Whether the localization was added successfully. |
85 | 70 | */ |
86 | 71 | function wp_localize_script( $handle, $object_name, $l10n ) { |
87 | | global $wp_scripts; |
88 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
89 | | if ( ! did_action( 'init' ) ) |
90 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
91 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
92 | | |
93 | | return false; |
94 | | } |
95 | | |
96 | | return $wp_scripts->localize( $handle, $object_name, $l10n ); |
| 72 | return wp_scripts()->localize( $handle, $object_name, $l10n ); |
97 | 73 | } |
98 | 74 | |
99 | 75 | /** |
… |
… |
function wp_localize_script( $handle, $object_name, $l10n ) { |
103 | 79 | * @see WP_Scripts::remove() For parameter information. |
104 | 80 | */ |
105 | 81 | function wp_deregister_script( $handle ) { |
106 | | global $wp_scripts; |
107 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
108 | | if ( ! did_action( 'init' ) ) |
109 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
110 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
111 | | $wp_scripts = new WP_Scripts(); |
112 | | } |
113 | | |
114 | | $wp_scripts->remove( $handle ); |
| 82 | wp_scripts()->remove( $handle ); |
115 | 83 | } |
116 | 84 | |
117 | 85 | /** |
… |
… |
function wp_deregister_script( $handle ) { |
123 | 91 | * @see wp_register_script() For parameter information. |
124 | 92 | */ |
125 | 93 | function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { |
126 | | global $wp_scripts; |
127 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
128 | | if ( ! did_action( 'init' ) ) |
129 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
130 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
131 | | $wp_scripts = new WP_Scripts(); |
132 | | } |
| 94 | $wp_scripts = wp_scripts(); |
133 | 95 | |
134 | 96 | if ( $src ) { |
135 | 97 | $_handle = explode('?', $handle); |
… |
… |
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false |
147 | 109 | * @see WP_Scripts::dequeue() For parameter information. |
148 | 110 | */ |
149 | 111 | function wp_dequeue_script( $handle ) { |
150 | | global $wp_scripts; |
151 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
152 | | if ( ! did_action( 'init' ) ) |
153 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
154 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
155 | | $wp_scripts = new WP_Scripts(); |
156 | | } |
157 | | |
158 | | $wp_scripts->dequeue( $handle ); |
| 112 | wp_scripts()->dequeue( $handle ); |
159 | 113 | } |
160 | 114 | |
161 | 115 | /** |
… |
… |
function wp_dequeue_script( $handle ) { |
171 | 125 | * @return bool |
172 | 126 | */ |
173 | 127 | function wp_script_is( $handle, $list = 'queue' ) { |
174 | | global $wp_scripts; |
175 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
176 | | if ( ! did_action( 'init' ) ) |
177 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
178 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
179 | | $wp_scripts = new WP_Scripts(); |
180 | | } |
181 | | |
182 | | $query = $wp_scripts->query( $handle, $list ); |
| 128 | $query = wp_scripts()->query( $handle, $list ); |
183 | 129 | |
184 | 130 | if ( is_object( $query ) ) |
185 | 131 | return true; |
186 | 132 | |
187 | 133 | return $query; |
188 | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Return the global instance of WP_Scripts |
| 138 | * |
| 139 | * @since 3.5.0 |
| 140 | * |
| 141 | * @return object WP_Scripts instance |
| 142 | */ |
| 143 | function wp_scripts() { |
| 144 | global $wp_scripts; |
| 145 | |
| 146 | if ( is_a( $wp_scripts, 'WP_Scripts' ) ) |
| 147 | return $wp_scripts; |
| 148 | |
| 149 | if ( ! did_action( 'init' ) ) |
| 150 | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 151 | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 152 | |
| 153 | $wp_scripts = new WP_Scripts; |
| 154 | |
| 155 | return $wp_scripts; |
| 156 | } |
| 157 | |