author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Dependencies API: Scripts functions |
0 | 4 |
* |
5 |
* @since 2.6.0 |
|
6 |
* |
|
7 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
* @subpackage Dependencies |
0 | 9 |
*/ |
10 |
||
11 |
/** |
|
5 | 12 |
* Initialize $wp_scripts if it has not been set. |
13 |
* |
|
14 |
* @global WP_Scripts $wp_scripts |
|
15 |
* |
|
16 |
* @since 4.2.0 |
|
17 |
* |
|
18 |
* @return WP_Scripts WP_Scripts instance. |
|
19 |
*/ |
|
20 |
function wp_scripts() { |
|
21 |
global $wp_scripts; |
|
22 |
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
|
23 |
$wp_scripts = new WP_Scripts(); |
|
24 |
} |
|
25 |
return $wp_scripts; |
|
26 |
} |
|
27 |
||
28 |
/** |
|
29 |
* Helper function to output a _doing_it_wrong message when applicable. |
|
30 |
* |
|
31 |
* @ignore |
|
32 |
* @since 4.2.0 |
|
33 |
* |
|
34 |
* @param string $function Function name. |
|
35 |
*/ |
|
36 |
function _wp_scripts_maybe_doing_it_wrong( $function ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
if ( did_action( 'init' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) { |
5 | 38 |
return; |
39 |
} |
|
40 |
||
41 |
_doing_it_wrong( $function, sprintf( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
/* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ |
5 | 43 |
__( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
44 |
'<code>wp_enqueue_scripts</code>', |
|
45 |
'<code>admin_enqueue_scripts</code>', |
|
46 |
'<code>login_enqueue_scripts</code>' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
), '3.3.0' ); |
5 | 48 |
} |
49 |
||
50 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* Prints scripts in document head that are in the $handles queue. |
0 | 52 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load, |
0 | 54 |
* the function does not instantiate the WP_Scripts object unless script names are explicitly passed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
* Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'} |
0 | 56 |
* hook to register/enqueue new scripts. |
57 |
* |
|
58 |
* @see WP_Scripts::do_items() |
|
59 |
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. |
|
60 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @since 2.1.0 |
0 | 62 |
* |
5 | 63 |
* @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'. |
0 | 64 |
* @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. |
65 |
*/ |
|
66 |
function wp_print_scripts( $handles = false ) { |
|
5 | 67 |
/** |
68 |
* Fires before scripts in the $handles queue are printed. |
|
69 |
* |
|
70 |
* @since 2.1.0 |
|
71 |
*/ |
|
0 | 72 |
do_action( 'wp_print_scripts' ); |
5 | 73 |
if ( '' === $handles ) { // for wp_head |
0 | 74 |
$handles = false; |
5 | 75 |
} |
76 |
||
77 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
0 | 78 |
|
79 |
global $wp_scripts; |
|
5 | 80 |
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
81 |
if ( ! $handles ) { |
|
0 | 82 |
return array(); // No need to instantiate if nothing is there. |
5 | 83 |
} |
0 | 84 |
} |
85 |
||
5 | 86 |
return wp_scripts()->do_items( $handles ); |
0 | 87 |
} |
88 |
||
89 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* Adds extra code to a registered script. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* Code will only be added if the script in already in the queue. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* Accepts a string $data containing the Code. If two or more code blocks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* are added to the same script $handle, they will be printed in the order |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
* they were added, i.e. the latter added code can redeclare the previous. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* @see WP_Scripts::add_inline_script() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* @param string $handle Name of the script to add the inline script to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* @param string $data String containing the javascript to be added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* @param string $position Optional. Whether to add the inline script before the handle |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* or after. Default 'after'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
function wp_add_inline_script( $handle, $data, $position = 'after' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
if ( false !== stripos( $data, '</script>' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
_doing_it_wrong( __FUNCTION__, sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
/* translators: 1: <script>, 2: wp_add_inline_script() */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
__( 'Do not pass %1$s tags to %2$s.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
'<code><script></code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
'<code>wp_add_inline_script()</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
), '4.5.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
$data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
return wp_scripts()->add_inline_script( $handle, $data, $position ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
/** |
0 | 124 |
* Register a new script. |
125 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* Registers a script to be enqueued later using the wp_enqueue_script() function. |
0 | 127 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* @see WP_Dependencies::add() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* @see WP_Dependencies::add_data() |
0 | 130 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* @since 4.3.0 A return value was added. |
0 | 133 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @param string $handle Name of the script. Should be unique. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* as a query string for cache busting purposes. If version is set to false, a version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* number is automatically added equal to current installed WordPress version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* If set to null, no version is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* Default 'false'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* @return bool Whether the script has been registered. True on success, false on failure. |
0 | 144 |
*/ |
145 |
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
|
5 | 146 |
$wp_scripts = wp_scripts(); |
147 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
0 | 148 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
$registered = $wp_scripts->add( $handle, $src, $deps, $ver ); |
5 | 150 |
if ( $in_footer ) { |
0 | 151 |
$wp_scripts->add_data( $handle, 'group', 1 ); |
5 | 152 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
return $registered; |
0 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* Localize a script. |
|
159 |
* |
|
160 |
* Works only if the script has already been added. |
|
161 |
* |
|
162 |
* Accepts an associative array $l10n and creates a JavaScript object: |
|
5 | 163 |
* |
164 |
* "$object_name" = { |
|
165 |
* key: value, |
|
166 |
* key: value, |
|
167 |
* ... |
|
168 |
* } |
|
169 |
* |
|
0 | 170 |
* |
171 |
* @see WP_Dependencies::localize() |
|
5 | 172 |
* @link https://core.trac.wordpress.org/ticket/11520 |
0 | 173 |
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. |
174 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* @since 2.2.0 |
0 | 176 |
* |
5 | 177 |
* @todo Documentation cleanup |
178 |
* |
|
0 | 179 |
* @param string $handle Script handle the data will be attached to. |
180 |
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. |
|
181 |
* Example: '/[a-zA-Z0-9_]+/'. |
|
182 |
* @param array $l10n The data itself. The data can be either a single or multi-dimensional array. |
|
183 |
* @return bool True if the script was successfully localized, false otherwise. |
|
184 |
*/ |
|
185 |
function wp_localize_script( $handle, $object_name, $l10n ) { |
|
186 |
global $wp_scripts; |
|
5 | 187 |
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { |
188 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
0 | 189 |
return false; |
190 |
} |
|
191 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
return $wp_scripts->localize( $handle, $object_name, $l10n ); |
0 | 193 |
} |
194 |
||
195 |
/** |
|
196 |
* Remove a registered script. |
|
197 |
* |
|
198 |
* Note: there are intentional safeguards in place to prevent critical admin scripts, |
|
199 |
* such as jQuery core, from being unregistered. |
|
200 |
* |
|
201 |
* @see WP_Dependencies::remove() |
|
202 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* @since 2.1.0 |
0 | 204 |
* |
205 |
* @param string $handle Name of the script to be removed. |
|
206 |
*/ |
|
207 |
function wp_deregister_script( $handle ) { |
|
5 | 208 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
0 | 209 |
|
210 |
/** |
|
211 |
* Do not allow accidental or negligent de-registering of critical scripts in the admin. |
|
212 |
* Show minimal remorse if the correct hook is used. |
|
213 |
*/ |
|
214 |
$current_filter = current_filter(); |
|
215 |
if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || |
|
216 |
( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) |
|
217 |
) { |
|
218 |
$no = array( |
|
219 |
'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', |
|
220 |
'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker', 'jquery-ui-dialog', |
|
221 |
'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', |
|
222 |
'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', |
|
223 |
'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs', |
|
224 |
'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', |
|
225 |
); |
|
226 |
||
227 |
if ( in_array( $handle, $no ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
$message = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
/* translators: 1: script name, 2: wp_enqueue_scripts */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
__( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
"<code>$handle</code>", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
'<code>wp_enqueue_scripts</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
_doing_it_wrong( __FUNCTION__, $message, '3.6.0' ); |
0 | 235 |
return; |
236 |
} |
|
237 |
} |
|
238 |
||
5 | 239 |
wp_scripts()->remove( $handle ); |
0 | 240 |
} |
241 |
||
242 |
/** |
|
243 |
* Enqueue a script. |
|
244 |
* |
|
245 |
* Registers the script if $src provided (does NOT overwrite), and enqueues it. |
|
246 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* @see WP_Dependencies::add() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* @see WP_Dependencies::add_data() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* @see WP_Dependencies::enqueue() |
0 | 250 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @since 2.1.0 |
5 | 252 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @param string $handle Name of the script. Should be unique. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* as a query string for cache busting purposes. If version is set to false, a version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
* number is automatically added equal to current installed WordPress version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
* If set to null, no version is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
* Default 'false'. |
0 | 263 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { |
5 | 265 |
$wp_scripts = wp_scripts(); |
266 |
||
267 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
|
268 |
||
269 |
||
270 |
if ( $src || $in_footer ) { |
|
271 |
$_handle = explode( '?', $handle ); |
|
272 |
||
273 |
if ( $src ) { |
|
274 |
$wp_scripts->add( $_handle[0], $src, $deps, $ver ); |
|
275 |
} |
|
276 |
||
277 |
if ( $in_footer ) { |
|
278 |
$wp_scripts->add_data( $_handle[0], 'group', 1 ); |
|
279 |
} |
|
0 | 280 |
} |
281 |
||
282 |
$wp_scripts->enqueue( $handle ); |
|
283 |
} |
|
284 |
||
285 |
/** |
|
286 |
* Remove a previously enqueued script. |
|
287 |
* |
|
288 |
* @see WP_Dependencies::dequeue() |
|
289 |
* |
|
290 |
* @since 3.1.0 |
|
291 |
* |
|
292 |
* @param string $handle Name of the script to be removed. |
|
293 |
*/ |
|
294 |
function wp_dequeue_script( $handle ) { |
|
5 | 295 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
0 | 296 |
|
5 | 297 |
wp_scripts()->dequeue( $handle ); |
0 | 298 |
} |
299 |
||
300 |
/** |
|
301 |
* Check whether a script has been added to the queue. |
|
302 |
* |
|
303 |
* @since 2.8.0 |
|
304 |
* @since 3.5.0 'enqueued' added as an alias of the 'queue' list. |
|
305 |
* |
|
306 |
* @param string $handle Name of the script. |
|
307 |
* @param string $list Optional. Status of the script to check. Default 'enqueued'. |
|
308 |
* Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
* @return bool Whether the script is queued. |
0 | 310 |
*/ |
311 |
function wp_script_is( $handle, $list = 'enqueued' ) { |
|
5 | 312 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
313 |
||
314 |
return (bool) wp_scripts()->query( $handle, $list ); |
|
315 |
} |
|
316 |
||
317 |
/** |
|
318 |
* Add metadata to a script. |
|
319 |
* |
|
320 |
* Works only if the script has already been added. |
|
321 |
* |
|
322 |
* Possible values for $key and $value: |
|
323 |
* 'conditional' string Comments for IE 6, lte IE 7, etc. |
|
324 |
* |
|
325 |
* @since 4.2.0 |
|
326 |
* |
|
327 |
* @see WP_Dependency::add_data() |
|
328 |
* |
|
329 |
* @param string $handle Name of the script. |
|
330 |
* @param string $key Name of data point for which we're storing a value. |
|
331 |
* @param mixed $value String containing the data to be added. |
|
332 |
* @return bool True on success, false on failure. |
|
333 |
*/ |
|
334 |
function wp_script_add_data( $handle, $key, $value ){ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
return wp_scripts()->add_data( $handle, $key, $value ); |
0 | 336 |
} |