run:R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
23.8 KB
2026-03-11 16:18:51
R W Run
7.8 KB
2026-03-11 16:18:52
R W Run
36.1 KB
2026-03-11 16:18:51
R W Run
11.9 KB
2026-03-11 16:18:52
R W Run
18.94 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:52
R W Run
28.6 KB
2026-03-11 16:18:51
R W Run
316 By
2026-03-11 16:18:51
R W Run
12.9 KB
2026-03-11 16:18:51
R W Run
61.02 KB
2026-03-11 16:18:52
R W Run
15 KB
2026-03-11 16:18:51
R W Run
112.05 KB
2026-03-11 16:18:51
R W Run
12.47 KB
2026-03-11 16:18:51
R W Run
15.07 KB
2026-03-11 16:18:52
R W Run
9.84 KB
2026-03-11 16:18:52
R W Run
13.17 KB
2026-03-11 16:18:52
R W Run
33.83 KB
2026-03-11 16:18:51
R W Run
42.63 KB
2026-03-11 16:18:51
R W Run
55.71 KB
2026-03-11 16:18:52
R W Run
12.53 KB
2026-03-11 16:18:51
R W Run
2.55 KB
2026-03-11 16:18:52
R W Run
28.92 KB
2026-03-11 16:18:52
R W Run
539 By
2026-03-11 16:18:51
R W Run
367 By
2026-03-11 16:18:52
R W Run
42.65 KB
2026-03-11 16:18:51
R W Run
401 By
2026-03-11 16:18:51
R W Run
6.61 KB
2026-03-11 16:18:51
R W Run
664 By
2026-03-11 16:18:52
R W Run
20.63 KB
2026-03-11 16:18:51
R W Run
2.18 KB
2026-03-11 16:18:52
R W Run
453 By
2026-03-11 16:18:52
R W Run
457 By
2026-03-11 16:18:51
R W Run
36.83 KB
2026-03-11 16:18:52
R W Run
2.41 KB
2026-03-11 16:18:52
R W Run
8.28 KB
2026-03-11 16:18:51
R W Run
13.89 KB
2026-03-11 16:18:51
R W Run
11.76 KB
2026-03-11 16:18:51
R W Run
2.65 KB
2026-03-11 16:18:51
R W Run
7.43 KB
2026-03-11 16:18:51
R W Run
17.46 KB
2026-03-11 16:18:51
R W Run
5.14 KB
2026-03-11 16:18:52
R W Run
16.7 KB
2026-03-11 16:18:51
R W Run
8.28 KB
2026-03-11 16:18:52
R W Run
2.92 KB
2026-03-11 16:18:52
R W Run
1.32 KB
2026-03-11 16:18:51
R W Run
4.6 KB
2026-03-11 16:18:52
R W Run
11.62 KB
2026-03-11 16:18:52
R W Run
2.5 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
11.25 KB
2026-03-11 16:18:52
R W Run
5.32 KB
2026-03-11 16:18:51
R W Run
10.99 KB
2026-03-11 16:18:52
R W Run
68.32 KB
2026-03-11 16:18:51
R W Run
6.34 KB
2026-03-11 16:18:51
R W Run
5.49 KB
2026-03-11 16:18:51
R W Run
1.99 KB
2026-03-11 16:18:52
R W Run
7.02 KB
2026-03-11 16:18:51
R W Run
4.91 KB
2026-03-11 16:18:52
R W Run
16.86 KB
2026-03-11 16:18:51
R W Run
24.23 KB
2026-03-11 16:18:51
R W Run
3.97 KB
2026-03-11 16:18:51
R W Run
47.66 KB
2026-03-11 16:18:51
R W Run
9.22 KB
2026-03-11 16:18:51
R W Run
25.51 KB
2026-03-11 16:18:51
R W Run
198.38 KB
2026-03-11 16:18:52
R W Run
56.65 KB
2026-03-11 16:18:51
R W Run
10.46 KB
2026-03-11 16:18:51
R W Run
10.95 KB
2026-03-11 16:18:52
R W Run
29.26 KB
2026-03-11 16:18:51
R W Run
70.91 KB
2026-03-11 16:18:52
R W Run
35.3 KB
2026-03-11 16:18:52
R W Run
16.61 KB
2026-03-11 16:18:52
R W Run
2.57 KB
2026-03-11 16:18:52
R W Run
39.83 KB
2026-03-11 16:18:51
R W Run
70.64 KB
2026-03-11 16:18:51
R W Run
15.56 KB
2026-03-11 16:18:52
R W Run
7.33 KB
2026-03-11 16:18:52
R W Run
253 By
2026-03-11 16:18:51
R W Run
7.96 KB
2026-03-11 16:18:52
R W Run
3.23 KB
2026-03-11 16:18:52
R W Run
969 By
2026-03-11 16:18:52
R W Run
16.28 KB
2026-03-11 16:18:51
R W Run
7.22 KB
2026-03-11 16:18:51
R W Run
12.95 KB
2026-03-11 16:18:51
R W Run
6.53 KB
2026-03-11 16:18:51
R W Run
3.42 KB
2026-03-11 16:18:52
R W Run
5.84 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
4.3 KB
2026-03-11 16:18:52
R W Run
2.91 KB
2026-03-11 16:18:51
R W Run
16.46 KB
2026-03-11 16:18:52
R W Run
40.6 KB
2026-03-11 16:18:51
R W Run
20.22 KB
2026-03-11 16:18:51
R W Run
36.11 KB
2026-03-11 16:18:52
R W Run
17.01 KB
2026-03-11 16:18:51
R W Run
7.27 KB
2026-03-11 16:18:52
R W Run
6.62 KB
2026-03-11 16:18:52
R W Run
16.49 KB
2026-03-11 16:18:52
R W Run
1.79 KB
2026-03-11 16:18:52
R W Run
29.82 KB
2026-03-11 16:18:51
R W Run
6.67 KB
2026-03-11 16:18:52
R W Run
8.98 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:51
R W Run
12.01 KB
2026-03-11 16:18:51
R W Run
17.11 KB
2026-03-11 16:18:51
R W Run
6.74 KB
2026-03-11 16:18:52
R W Run
30.93 KB
2026-03-11 16:18:51
R W Run
4.99 KB
2026-03-11 16:18:51
R W Run
4.25 KB
2026-03-11 16:18:51
R W Run
24.72 KB
2026-03-11 16:18:51
R W Run
29.96 KB
2026-03-11 16:18:52
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
160 KB
2026-03-11 16:18:51
R W Run
6.72 KB
2026-03-11 16:18:52
R W Run
10.92 KB
2026-03-11 16:18:51
R W Run
4.77 KB
2026-03-11 16:18:51
R W Run
3.38 KB
2026-03-11 16:18:51
R W Run
11.18 KB
2026-03-11 16:18:51
R W Run
62.19 KB
2026-03-11 16:18:51
R W Run
2.46 KB
2026-03-11 16:18:51
R W Run
9.17 KB
2026-03-11 16:18:51
R W Run
32.15 KB
2026-03-11 16:18:51
R W Run
34.05 KB
2026-03-11 16:18:52
R W Run
7.15 KB
2026-03-11 16:18:51
R W Run
3.47 KB
2026-03-11 16:18:52
R W Run
1.87 KB
2026-03-11 16:18:52
R W Run
30.91 KB
2026-03-11 16:18:51
R W Run
7.29 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:51
R W Run
12.54 KB
2026-03-11 16:18:51
R W Run
19.12 KB
2026-03-11 16:18:51
R W Run
18.12 KB
2026-03-11 16:18:52
R W Run
39.99 KB
2026-03-11 16:18:52
R W Run
5.17 KB
2026-03-11 16:18:52
R W Run
979 By
2026-03-11 16:18:51
R W Run
18.44 KB
2026-03-11 16:18:52
R W Run
10.24 KB
2026-03-11 16:18:51
R W Run
1.77 KB
2026-03-11 16:18:52
R W Run
34.9 KB
2026-03-11 16:18:51
R W Run
7.19 KB
2026-03-11 16:18:52
R W Run
160.5 KB
2026-03-11 16:18:51
R W Run
64.27 KB
2026-03-11 16:18:51
R W Run
27.95 KB
2026-03-11 16:18:51
R W Run
4.69 KB
2026-03-11 16:18:51
R W Run
2.94 KB
2026-03-11 16:18:51
R W Run
43.13 KB
2026-03-11 16:18:52
R W Run
2.25 KB
2026-03-11 16:18:52
R W Run
22.5 KB
2026-03-11 16:18:51
R W Run
13.01 KB
2026-03-11 16:18:52
R W Run
3.27 KB
2026-03-11 16:18:51
R W Run
18 KB
2026-03-11 16:18:51
R W Run
210.4 KB
2026-03-11 16:18:52
R W Run
25.86 KB
2026-03-11 16:18:52
R W Run
115.85 KB
2026-03-11 16:18:51
R W Run
373 By
2026-03-11 16:18:52
R W Run
343 By
2026-03-11 16:18:52
R W Run
338 By
2026-03-11 16:18:51
R W Run
100.73 KB
2026-03-11 16:18:52
R W Run
130.93 KB
2026-03-11 16:18:51
R W Run
19.1 KB
2026-03-11 16:18:51
R W Run
17.41 KB
2026-03-11 16:18:52
R W Run
41.98 KB
2026-03-11 16:18:52
R W Run
400 By
2026-03-11 16:18:52
R W Run
11.1 KB
2026-03-11 16:18:52
R W Run
37.02 KB
2026-03-11 16:18:51
R W Run
2.24 KB
2026-03-11 16:18:51
R W Run
188.13 KB
2026-03-11 16:18:51
R W Run
338 By
2026-03-11 16:18:51
R W Run
38 KB
2026-03-11 16:18:51
R W Run
4.02 KB
2026-03-11 16:18:52
R W Run
5.38 KB
2026-03-11 16:18:51
R W Run
3.05 KB
2026-03-11 16:18:52
R W Run
2.61 KB
2026-03-11 16:18:51
R W Run
1.16 KB
2026-03-11 16:18:52
R W Run
4.04 KB
2026-03-11 16:18:51
R W Run
3.71 KB
2026-03-11 16:18:51
R W Run
24.6 KB
2026-03-11 16:18:51
R W Run
9.56 KB
2026-03-11 16:18:51
R W Run
346.43 KB
2026-03-11 16:18:52
R W Run
281.84 KB
2026-03-11 16:18:52
R W Run
14.95 KB
2026-03-11 16:18:51
R W Run
8.44 KB
2026-03-11 16:18:52
R W Run
168.95 KB
2026-03-11 16:18:52
R W Run
20.71 KB
2026-03-11 16:18:52
R W Run
25.27 KB
2026-03-11 16:18:51
R W Run
5.72 KB
2026-03-11 16:18:51
R W Run
4.63 KB
2026-03-11 16:18:52
R W Run
81.73 KB
2026-03-11 16:18:51
R W Run
67.18 KB
2026-03-11 16:18:51
R W Run
156.36 KB
2026-03-11 16:18:52
R W Run
55.19 KB
2026-03-11 16:18:51
R W Run
162 By
2026-03-11 16:18:51
R W Run
61.72 KB
2026-03-11 16:18:51
R W Run
216.06 KB
2026-03-11 16:18:52
R W Run
65.09 KB
2026-03-11 16:18:51
R W Run
25.24 KB
2026-03-11 16:18:52
R W Run
4.81 KB
2026-03-11 16:18:51
R W Run
6.48 KB
2026-03-11 16:18:52
R W Run
21.25 KB
2026-03-11 16:18:51
R W Run
2.79 KB
2026-03-11 16:18:52
R W Run
89.69 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:52
R W Run
3.69 KB
2026-03-11 16:18:52
R W Run
4.11 KB
2026-03-11 16:18:51
R W Run
40.74 KB
2026-03-11 16:18:51
R W Run
25.38 KB
2026-03-11 16:18:51
R W Run
43.31 KB
2026-03-11 16:18:52
R W Run
102.57 KB
2026-03-11 16:18:52
R W Run
6.18 KB
2026-03-11 16:18:51
R W Run
124.47 KB
2026-03-11 16:18:52
R W Run
35.65 KB
2026-03-11 16:18:52
R W Run
6.94 KB
2026-03-11 16:18:52
R W Run
67.04 KB
2026-03-11 16:18:52
R W Run
10.62 KB
2026-03-11 16:18:51
R W Run
289.35 KB
2026-03-11 16:18:52
R W Run
36.23 KB
2026-03-11 16:18:51
R W Run
200 By
2026-03-11 16:18:52
R W Run
200 By
2026-03-11 16:18:52
R W Run
98.29 KB
2026-03-11 16:18:52
R W Run
30.02 KB
2026-03-11 16:18:52
R W Run
19.03 KB
2026-03-11 16:18:52
R W Run
5.06 KB
2026-03-11 16:18:52
R W Run
255 By
2026-03-11 16:18:51
R W Run
22.66 KB
2026-03-11 16:18:52
R W Run
154.63 KB
2026-03-11 16:18:51
R W Run
9.68 KB
2026-03-11 16:18:51
R W Run
258 By
2026-03-11 16:18:51
R W Run
23.49 KB
2026-03-11 16:18:51
R W Run
3.16 KB
2026-03-11 16:18:51
R W Run
8.4 KB
2026-03-11 16:18:52
R W Run
441 By
2026-03-11 16:18:51
R W Run
7.39 KB
2026-03-11 16:18:51
R W Run
173 KB
2026-03-11 16:18:52
R W Run
544 By
2026-03-11 16:18:52
R W Run
4.17 KB
2026-03-11 16:18:51
R W Run
35.97 KB
2026-03-11 16:18:52
R W Run
1.69 KB
2026-03-11 16:18:51
R W Run
2.84 KB
2026-03-11 16:18:52
R W Run
6.09 KB
2026-03-11 16:18:51
R W Run
8.71 KB
2026-03-11 16:18:51
R W Run
131.84 KB
2026-03-11 16:18:51
R W Run
37.45 KB
2026-03-11 16:18:51
R W Run
173.89 KB
2026-03-11 16:18:51
R W Run
7.09 KB
2026-03-11 16:18:51
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
1.08 KB
2026-03-11 16:18:51
R W Run
69.46 KB
2026-03-11 16:18:52
R W Run
445 By
2026-03-11 16:18:51
R W Run
799 By
2026-03-11 16:18:52
R W Run
error_log
📄class-wp-scripts.php
1<?php
2/**
3 * Dependencies API: WP_Scripts class
4 *
5 * @since 2.6.0
6 *
7 * @package WordPress
8 * @subpackage Dependencies
9 */
10
11/**
12 * Core class used to register scripts.
13 *
14 * @since 2.1.0
15 *
16 * @see WP_Dependencies
17 */
18class WP_Scripts extends WP_Dependencies {
19 /**
20 * Base URL for scripts.
21 *
22 * Full URL with trailing slash.
23 *
24 * @since 2.6.0
25 * @var string
26 */
27 public $base_url;
28
29 /**
30 * URL of the content directory.
31 *
32 * @since 2.8.0
33 * @var string
34 */
35 public $content_url;
36
37 /**
38 * Default version string for scripts.
39 *
40 * @since 2.6.0
41 * @var string
42 */
43 public $default_version;
44
45 /**
46 * Holds handles of scripts which are enqueued in footer.
47 *
48 * @since 2.8.0
49 * @var array
50 */
51 public $in_footer = array();
52
53 /**
54 * Holds a list of script handles which will be concatenated.
55 *
56 * @since 2.8.0
57 * @var string
58 */
59 public $concat = '';
60
61 /**
62 * Holds a string which contains script handles and their version.
63 *
64 * @since 2.8.0
65 * @deprecated 3.4.0
66 * @var string
67 */
68 public $concat_version = '';
69
70 /**
71 * Whether to perform concatenation.
72 *
73 * @since 2.8.0
74 * @var bool
75 */
76 public $do_concat = false;
77
78 /**
79 * Holds HTML markup of scripts and additional data if concatenation
80 * is enabled.
81 *
82 * @since 2.8.0
83 * @var string
84 */
85 public $print_html = '';
86
87 /**
88 * Holds inline code if concatenation is enabled.
89 *
90 * @since 2.8.0
91 * @var string
92 */
93 public $print_code = '';
94
95 /**
96 * Holds a list of script handles which are not in the default directory
97 * if concatenation is enabled.
98 *
99 * Unused in core.
100 *
101 * @since 2.8.0
102 * @var string
103 */
104 public $ext_handles = '';
105
106 /**
107 * Holds a string which contains handles and versions of scripts which
108 * are not in the default directory if concatenation is enabled.
109 *
110 * Unused in core.
111 *
112 * @since 2.8.0
113 * @var string
114 */
115 public $ext_version = '';
116
117 /**
118 * List of default directories.
119 *
120 * @since 2.8.0
121 * @var array
122 */
123 public $default_dirs;
124
125 /**
126 * Holds a mapping of dependents (as handles) for a given script handle.
127 * Used to optimize recursive dependency tree checks.
128 *
129 * @since 6.3.0
130 * @var array<string, string[]>
131 */
132 private $dependents_map = array();
133
134 /**
135 * Holds a reference to the delayed (non-blocking) script loading strategies.
136 * Used by methods that validate loading strategies.
137 *
138 * @since 6.3.0
139 * @var string[]
140 */
141 private $delayed_strategies = array( 'defer', 'async' );
142
143 /**
144 * Constructor.
145 *
146 * @since 2.6.0
147 */
148 public function __construct() {
149 $this->init();
150 add_action( 'init', array( $this, 'init' ), 0 );
151 }
152
153 /**
154 * Initialize the class.
155 *
156 * @since 3.4.0
157 */
158 public function init() {
159 /**
160 * Fires when the WP_Scripts instance is initialized.
161 *
162 * @since 2.6.0
163 *
164 * @param WP_Scripts $wp_scripts WP_Scripts instance (passed by reference).
165 */
166 do_action_ref_array( 'wp_default_scripts', array( &$this ) );
167 }
168
169 /**
170 * Prints scripts.
171 *
172 * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.
173 *
174 * @since 2.1.0
175 * @since 2.8.0 Added the `$group` parameter.
176 *
177 * @param string|string[]|false $handles Optional. Scripts to be printed: queue (false),
178 * single script (string), or multiple scripts (array of strings).
179 * Default false.
180 * @param int|false $group Optional. Group level: level (int), no groups (false).
181 * Default false.
182 * @return string[] Handles of scripts that have been printed.
183 */
184 public function print_scripts( $handles = false, $group = false ) {
185 return $this->do_items( $handles, $group );
186 }
187
188 /**
189 * Prints extra scripts of a registered script.
190 *
191 * @since 2.1.0
192 * @since 2.8.0 Added the `$display` parameter.
193 * @deprecated 3.3.0
194 *
195 * @see print_extra_script()
196 *
197 * @param string $handle The script's registered handle.
198 * @param bool $display Optional. Whether to print the extra script
199 * instead of just returning it. Default true.
200 * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
201 * true otherwise.
202 */
203 public function print_scripts_l10n( $handle, $display = true ) {
204 _deprecated_function( __FUNCTION__, '3.3.0', 'WP_Scripts::print_extra_script()' );
205 return $this->print_extra_script( $handle, $display );
206 }
207
208 /**
209 * Prints extra scripts of a registered script.
210 *
211 * @since 3.3.0
212 *
213 * @param string $handle The script's registered handle.
214 * @param bool $display Optional. Whether to print the extra script
215 * instead of just returning it. Default true.
216 * @return bool|string|void Void if no data exists, extra scripts if `$display` is true,
217 * true otherwise.
218 */
219 public function print_extra_script( $handle, $display = true ) {
220 $output = $this->get_data( $handle, 'data' );
221 if ( ! $output ) {
222 return;
223 }
224
225 /*
226 * Do not print a sourceURL comment if concatenation is enabled.
227 *
228 * Extra scripts may be concatenated into a single script.
229 * The line-based sourceURL comments may break concatenated scripts
230 * and do not make sense when multiple scripts are joined together.
231 */
232 if ( ! $this->do_concat ) {
233 $output .= sprintf(
234 "\n//# sourceURL=%s",
235 rawurlencode( "{$handle}-js-extra" )
236 );
237 }
238
239 if ( ! $display ) {
240 return $output;
241 }
242
243 wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-extra" ) );
244
245 return true;
246 }
247
248 /**
249 * Checks whether all dependents of a given handle are in the footer.
250 *
251 * If there are no dependents, this is considered the same as if all dependents were in the footer.
252 *
253 * @since 6.4.0
254 *
255 * @param string $handle Script handle.
256 * @return bool Whether all dependents are in the footer.
257 */
258 private function are_all_dependents_in_footer( $handle ) {
259 foreach ( $this->get_dependents( $handle ) as $dep ) {
260 if ( isset( $this->groups[ $dep ] ) && 0 === $this->groups[ $dep ] ) {
261 return false;
262 }
263 }
264 return true;
265 }
266
267 /**
268 * Processes a script dependency.
269 *
270 * @since 2.6.0
271 * @since 2.8.0 Added the `$group` parameter.
272 *
273 * @see WP_Dependencies::do_item()
274 *
275 * @param string $handle The script's registered handle.
276 * @param int|false $group Optional. Group level: level (int), no groups (false).
277 * Default false.
278 * @return bool True on success, false on failure.
279 */
280 public function do_item( $handle, $group = false ) {
281 if ( ! parent::do_item( $handle ) ) {
282 return false;
283 }
284
285 if ( 0 === $group && $this->groups[ $handle ] > 0 ) {
286 $this->in_footer[] = $handle;
287 return false;
288 }
289
290 if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {
291 $this->in_footer = array_diff( $this->in_footer, (array) $handle );
292 }
293
294 $obj = $this->registered[ $handle ];
295 if ( $obj->extra['conditional'] ?? false ) {
296 return false;
297 }
298
299 if ( null === $obj->ver ) {
300 $ver = '';
301 } else {
302 $ver = $obj->ver ? $obj->ver : $this->default_version;
303 }
304
305 if ( isset( $this->args[ $handle ] ) ) {
306 $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
307 }
308
309 $src = $obj->src;
310 $strategy = $this->get_eligible_loading_strategy( $handle );
311 $intended_strategy = (string) $this->get_data( $handle, 'strategy' );
312
313 if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {
314 $intended_strategy = '';
315 }
316
317 /*
318 * Move this script to the footer if:
319 * 1. The script is in the header group.
320 * 2. The current output is the header.
321 * 3. The intended strategy is delayed.
322 * 4. The actual strategy is not delayed.
323 * 5. All dependent scripts are in the footer.
324 */
325 if (
326 0 === $group &&
327 0 === $this->groups[ $handle ] &&
328 $intended_strategy &&
329 ! $this->is_delayed_strategy( $strategy ) &&
330 $this->are_all_dependents_in_footer( $handle )
331 ) {
332 $this->in_footer[] = $handle;
333 return false;
334 }
335
336 $before_script = $this->get_inline_script_tag( $handle, 'before' );
337 $after_script = $this->get_inline_script_tag( $handle, 'after' );
338
339 if ( $before_script || $after_script ) {
340 $inline_script_tag = $before_script . $after_script;
341 } else {
342 $inline_script_tag = '';
343 }
344
345 /*
346 * Prevent concatenation of scripts if the text domain is defined
347 * to ensure the dependency order is respected.
348 */
349 $translations_stop_concat = ! empty( $obj->textdomain );
350
351 $translations = $this->print_translations( $handle, false );
352 if ( $translations ) {
353 /*
354 * The sourceURL comment is not included by WP_Scripts::print_translations()
355 * when `$display` is `false` to prevent issues where the script tag contents are used
356 * by extenders for other purposes, for example concatenated with other script content.
357 *
358 * Include the sourceURL comment here as it would be when printed directly.
359 */
360 $source_url = rawurlencode( "{$handle}-js-translations" );
361 $translations .= "\n//# sourceURL={$source_url}";
362 $translations = wp_get_inline_script_tag( $translations, array( 'id' => "{$handle}-js-translations" ) );
363 }
364
365 if ( $this->do_concat ) {
366 /**
367 * Filters the script loader source.
368 *
369 * @since 2.2.0
370 *
371 * @param string $src Script loader source path.
372 * @param string $handle Script handle.
373 */
374 $filtered_src = apply_filters( 'script_loader_src', $src, $handle );
375
376 if (
377 $this->in_default_dir( $filtered_src )
378 && ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) )
379 ) {
380 $this->do_concat = false;
381
382 // Have to print the so-far concatenated scripts right away to maintain the right order.
383 _print_scripts();
384 $this->reset();
385 } elseif ( $this->in_default_dir( $filtered_src ) ) {
386 $this->print_code .= $this->print_extra_script( $handle, false );
387 $this->concat .= "$handle,";
388 $this->concat_version .= "$handle$ver";
389 return true;
390 } else {
391 $this->ext_handles .= "$handle,";
392 $this->ext_version .= "$handle$ver";
393 }
394 }
395
396 $this->print_extra_script( $handle );
397
398 // A single item may alias a set of items, by having dependencies, but no source.
399 if ( ! $src ) {
400 if ( $inline_script_tag ) {
401 if ( $this->do_concat ) {
402 $this->print_html .= $inline_script_tag;
403 } else {
404 echo $inline_script_tag;
405 }
406 }
407
408 return true;
409 }
410
411 if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) {
412 $src = $this->base_url . $src;
413 }
414
415 if ( ! empty( $ver ) ) {
416 $src = add_query_arg( 'ver', $ver, $src );
417 }
418
419 /** This filter is documented in wp-includes/class-wp-scripts.php */
420 $src = esc_url_raw( apply_filters( 'script_loader_src', $src, $handle ) );
421
422 if ( ! $src ) {
423 return true;
424 }
425
426 $attr = array(
427 'src' => $src,
428 'id' => "{$handle}-js",
429 );
430 if ( $strategy ) {
431 $attr[ $strategy ] = true;
432 }
433 if ( $intended_strategy ) {
434 $attr['data-wp-strategy'] = $intended_strategy;
435 }
436
437 // Determine fetchpriority.
438 $original_fetchpriority = isset( $obj->extra['fetchpriority'] ) ? $obj->extra['fetchpriority'] : null;
439 if ( null === $original_fetchpriority || ! $this->is_valid_fetchpriority( $original_fetchpriority ) ) {
440 $original_fetchpriority = 'auto';
441 }
442 $actual_fetchpriority = $this->get_highest_fetchpriority_with_dependents( $handle );
443 if ( null === $actual_fetchpriority ) {
444 // If null, it's likely this script was not explicitly enqueued, so in this case use the original priority.
445 $actual_fetchpriority = $original_fetchpriority;
446 }
447 if ( is_string( $actual_fetchpriority ) && 'auto' !== $actual_fetchpriority ) {
448 $attr['fetchpriority'] = $actual_fetchpriority;
449 }
450
451 if ( $original_fetchpriority !== $actual_fetchpriority ) {
452 $attr['data-wp-fetchpriority'] = $original_fetchpriority;
453 }
454
455 $tag = $translations . $before_script;
456 $tag .= wp_get_script_tag( $attr );
457 $tag .= $after_script;
458
459 /**
460 * Filters the HTML script tag of an enqueued script.
461 *
462 * @since 4.1.0
463 *
464 * @param string $tag The `<script>` tag for the enqueued script.
465 * @param string $handle The script's registered handle.
466 * @param string $src The script's source URL.
467 */
468 $tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );
469
470 if ( $this->do_concat ) {
471 $this->print_html .= $tag;
472 } else {
473 echo $tag;
474 }
475
476 return true;
477 }
478
479 /**
480 * Adds extra code to a registered script.
481 *
482 * @since 4.5.0
483 *
484 * @param string $handle Name of the script to add the inline script to.
485 * Must be lowercase.
486 * @param string $data String containing the JavaScript to be added.
487 * @param string $position Optional. Whether to add the inline script
488 * before the handle or after. Default 'after'.
489 * @return bool True on success, false on failure.
490 */
491 public function add_inline_script( $handle, $data, $position = 'after' ) {
492 if ( ! $data ) {
493 return false;
494 }
495
496 if ( 'after' !== $position ) {
497 $position = 'before';
498 }
499
500 $script = (array) $this->get_data( $handle, $position );
501 $script[] = $data;
502
503 return $this->add_data( $handle, $position, $script );
504 }
505
506 /**
507 * Prints inline scripts registered for a specific handle.
508 *
509 * @since 4.5.0
510 * @deprecated 6.3.0 Use methods get_inline_script_tag() or get_inline_script_data() instead.
511 *
512 * @param string $handle Name of the script to print inline scripts for.
513 * Must be lowercase.
514 * @param string $position Optional. Whether to add the inline script
515 * before the handle or after. Default 'after'.
516 * @param bool $display Optional. Whether to print the script tag
517 * instead of just returning the script data. Default true.
518 * @return string|false Script data on success, false otherwise.
519 */
520 public function print_inline_script( $handle, $position = 'after', $display = true ) {
521 _deprecated_function( __METHOD__, '6.3.0', 'WP_Scripts::get_inline_script_data() or WP_Scripts::get_inline_script_tag()' );
522
523 $output = $this->get_inline_script_data( $handle, $position );
524 if ( empty( $output ) ) {
525 return false;
526 }
527
528 if ( $display ) {
529 echo $this->get_inline_script_tag( $handle, $position );
530 }
531 return $output;
532 }
533
534 /**
535 * Gets data for inline scripts registered for a specific handle.
536 *
537 * @since 6.3.0
538 *
539 * @param string $handle Name of the script to get data for.
540 * Must be lowercase.
541 * @param string $position Optional. Whether to add the inline script
542 * before the handle or after. Default 'after'.
543 * @return string Inline script, which may be empty string.
544 */
545 public function get_inline_script_data( $handle, $position = 'after' ) {
546 $data = $this->get_data( $handle, $position );
547 if ( empty( $data ) || ! is_array( $data ) ) {
548 return '';
549 }
550
551 /*
552 * Print sourceURL comment regardless of concatenation.
553 *
554 * Inline scripts prevent scripts from being concatenated, so
555 * sourceURL comments are safe to print for inline scripts.
556 */
557 $data[] = sprintf(
558 '//# sourceURL=%s',
559 rawurlencode( "{$handle}-js-{$position}" )
560 );
561
562 return trim( implode( "\n", $data ), "\n" );
563 }
564
565 /**
566 * Gets tags for inline scripts registered for a specific handle.
567 *
568 * @since 6.3.0
569 *
570 * @param string $handle Name of the script to get associated inline script tag for.
571 * Must be lowercase.
572 * @param string $position Optional. Whether to get tag for inline
573 * scripts in the before or after position. Default 'after'.
574 * @return string Inline script, which may be empty string.
575 */
576 public function get_inline_script_tag( $handle, $position = 'after' ) {
577 $js = $this->get_inline_script_data( $handle, $position );
578 if ( empty( $js ) ) {
579 return '';
580 }
581
582 $id = "{$handle}-js-{$position}";
583
584 return wp_get_inline_script_tag( $js, compact( 'id' ) );
585 }
586
587 /**
588 * Localizes a script, only if the script has already been added.
589 *
590 * @since 2.1.0
591 *
592 * @param string $handle Name of the script to attach data to.
593 * @param string $object_name Name of the variable that will contain the data.
594 * @param array $l10n Array of data to localize.
595 * @return bool True on success, false on failure.
596 */
597 public function localize( $handle, $object_name, $l10n ) {
598 if ( 'jquery' === $handle ) {
599 $handle = 'jquery-core';
600 }
601
602 if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present.
603 $after = $l10n['l10n_print_after'];
604 unset( $l10n['l10n_print_after'] );
605 }
606
607 if ( ! is_array( $l10n ) ) {
608 _doing_it_wrong(
609 __METHOD__,
610 sprintf(
611 /* translators: 1: $l10n, 2: wp_add_inline_script() */
612 __( 'The %1$s parameter must be an array. To pass arbitrary data to scripts, use the %2$s function instead.' ),
613 '<code>$l10n</code>',
614 '<code>wp_add_inline_script()</code>'
615 ),
616 '5.7.0'
617 );
618
619 if ( false === $l10n ) {
620 // This should really not be needed, but is necessary for backward compatibility.
621 $l10n = array( $l10n );
622 }
623 }
624
625 if ( is_string( $l10n ) ) {
626 $l10n = html_entity_decode( $l10n, ENT_QUOTES, 'UTF-8' );
627 } elseif ( is_array( $l10n ) ) {
628 foreach ( $l10n as $key => $value ) {
629 if ( ! is_scalar( $value ) ) {
630 continue;
631 }
632
633 $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
634 }
635 }
636
637 $script = "var $object_name = " . wp_json_encode( $l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ';';
638
639 if ( ! empty( $after ) ) {
640 $script .= "\n$after;";
641 }
642
643 $data = $this->get_data( $handle, 'data' );
644
645 if ( ! empty( $data ) ) {
646 $script = "$data\n$script";
647 }
648
649 return $this->add_data( $handle, 'data', $script );
650 }
651
652 /**
653 * Sets handle group.
654 *
655 * @since 2.8.0
656 *
657 * @see WP_Dependencies::set_group()
658 *
659 * @param string $handle Name of the item. Should be unique.
660 * @param bool $recursion Internal flag that calling function was called recursively.
661 * @param int|false $group Optional. Group level: level (int), no groups (false).
662 * Default false.
663 * @return bool Not already in the group or a lower group.
664 */
665 public function set_group( $handle, $recursion, $group = false ) {
666 if ( isset( $this->registered[ $handle ]->args ) && 1 === $this->registered[ $handle ]->args ) {
667 $calculated_group = 1;
668 } else {
669 $calculated_group = (int) $this->get_data( $handle, 'group' );
670 }
671
672 if ( false !== $group && $calculated_group > $group ) {
673 $calculated_group = $group;
674 }
675
676 return parent::set_group( $handle, $recursion, $calculated_group );
677 }
678
679 /**
680 * Sets a translation textdomain.
681 *
682 * @since 5.0.0
683 * @since 5.1.0 The `$domain` parameter was made optional.
684 *
685 * @param string $handle Name of the script to register a translation domain to.
686 * @param string $domain Optional. Text domain. Default 'default'.
687 * @param string $path Optional. The full file path to the directory containing translation files.
688 * @return bool True if the text domain was registered, false if not.
689 */
690 public function set_translations( $handle, $domain = 'default', $path = '' ) {
691 if ( ! isset( $this->registered[ $handle ] ) ) {
692 return false;
693 }
694
695 /** @var \_WP_Dependency $obj */
696 $obj = $this->registered[ $handle ];
697
698 if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) {
699 $obj->deps[] = 'wp-i18n';
700 }
701
702 return $obj->set_translations( $domain, $path );
703 }
704
705 /**
706 * Prints translations set for a specific handle.
707 *
708 * @since 5.0.0
709 *
710 * @param string $handle Name of the script to add the inline script to.
711 * Must be lowercase.
712 * @param bool $display Optional. Whether to print the script
713 * instead of just returning it. Default true.
714 * @return string|false Script on success, false otherwise.
715 */
716 public function print_translations( $handle, $display = true ) {
717 if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) {
718 return false;
719 }
720
721 $domain = $this->registered[ $handle ]->textdomain;
722 $path = '';
723
724 if ( isset( $this->registered[ $handle ]->translations_path ) ) {
725 $path = $this->registered[ $handle ]->translations_path;
726 }
727
728 $json_translations = load_script_textdomain( $handle, $domain, $path );
729
730 if ( ! $json_translations ) {
731 return false;
732 }
733
734 $output = <<<JS
735( function( domain, translations ) {
736 var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
737 localeData[""].domain = domain;
738 wp.i18n.setLocaleData( localeData, domain );
739} )( "{$domain}", {$json_translations} );
740JS;
741
742 if ( $display ) {
743 $source_url = rawurlencode( "{$handle}-js-translations" );
744 $output .= "\n//# sourceURL={$source_url}";
745 wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-translations" ) );
746 }
747
748 return $output;
749 }
750
751 /**
752 * Determines script dependencies.
753 *
754 * @since 2.1.0
755 *
756 * @see WP_Dependencies::all_deps()
757 *
758 * @param string|string[] $handles Item handle (string) or item handles (array of strings).
759 * @param bool $recursion Optional. Internal flag that function is calling itself.
760 * Default false.
761 * @param int|false $group Optional. Group level: level (int), no groups (false).
762 * Default false.
763 * @return bool True on success, false on failure.
764 */
765 public function all_deps( $handles, $recursion = false, $group = false ) {
766 $result = parent::all_deps( $handles, $recursion, $group );
767 if ( ! $recursion ) {
768 /**
769 * Filters the list of script dependencies left to print.
770 *
771 * @since 2.3.0
772 *
773 * @param string[] $to_do An array of script dependency handles.
774 */
775 $this->to_do = apply_filters( 'print_scripts_array', $this->to_do );
776 }
777 return $result;
778 }
779
780 /**
781 * Processes items and dependencies for the head group.
782 *
783 * @since 2.8.0
784 *
785 * @see WP_Dependencies::do_items()
786 *
787 * @return string[] Handles of items that have been processed.
788 */
789 public function do_head_items() {
790 $this->do_items( false, 0 );
791 return $this->done;
792 }
793
794 /**
795 * Processes items and dependencies for the footer group.
796 *
797 * @since 2.8.0
798 *
799 * @see WP_Dependencies::do_items()
800 *
801 * @return string[] Handles of items that have been processed.
802 */
803 public function do_footer_items() {
804 $this->do_items( false, 1 );
805 return $this->done;
806 }
807
808 /**
809 * Whether a handle's source is in a default directory.
810 *
811 * @since 2.8.0
812 *
813 * @param string $src The source of the enqueued script.
814 * @return bool True if found, false if not.
815 */
816 public function in_default_dir( $src ) {
817 if ( ! $this->default_dirs ) {
818 return true;
819 }
820
821 if ( str_starts_with( $src, '/' . WPINC . '/js/l10n' ) ) {
822 return false;
823 }
824
825 foreach ( (array) $this->default_dirs as $test ) {
826 if ( str_starts_with( $src, $test ) ) {
827 return true;
828 }
829 }
830 return false;
831 }
832
833 /**
834 * This overrides the add_data method from WP_Dependencies, to support normalizing of $args.
835 *
836 * @since 6.3.0
837 *
838 * @param string $handle Name of the item. Should be unique.
839 * @param string $key The data key.
840 * @param mixed $value The data value.
841 * @return bool True on success, false on failure.
842 */
843 public function add_data( $handle, $key, $value ) {
844 if ( ! isset( $this->registered[ $handle ] ) ) {
845 return false;
846 }
847
848 if ( 'conditional' === $key ) {
849 // If a dependency is declared by a conditional script, remove it.
850 $this->registered[ $handle ]->deps = array();
851 }
852
853 if ( 'strategy' === $key ) {
854 if ( ! empty( $value ) && ! $this->is_delayed_strategy( $value ) ) {
855 _doing_it_wrong(
856 __METHOD__,
857 sprintf(
858 /* translators: 1: $strategy, 2: $handle */
859 __( 'Invalid strategy `%1$s` defined for `%2$s` during script registration.' ),
860 $value,
861 $handle
862 ),
863 '6.3.0'
864 );
865 return false;
866 } elseif ( ! $this->registered[ $handle ]->src && $this->is_delayed_strategy( $value ) ) {
867 _doing_it_wrong(
868 __METHOD__,
869 sprintf(
870 /* translators: 1: $strategy, 2: $handle */
871 __( 'Cannot supply a strategy `%1$s` for script `%2$s` because it is an alias (it lacks a `src` value).' ),
872 $value,
873 $handle
874 ),
875 '6.3.0'
876 );
877 return false;
878 }
879 } elseif ( 'fetchpriority' === $key ) {
880 if ( empty( $value ) ) {
881 $value = 'auto';
882 }
883 if ( ! $this->is_valid_fetchpriority( $value ) ) {
884 _doing_it_wrong(
885 __METHOD__,
886 sprintf(
887 /* translators: 1: $fetchpriority, 2: $handle */
888 __( 'Invalid fetchpriority `%1$s` defined for `%2$s` during script registration.' ),
889 is_string( $value ) ? $value : gettype( $value ),
890 $handle
891 ),
892 '6.9.0'
893 );
894 return false;
895 } elseif ( ! $this->registered[ $handle ]->src ) {
896 _doing_it_wrong(
897 __METHOD__,
898 sprintf(
899 /* translators: 1: $fetchpriority, 2: $handle */
900 __( 'Cannot supply a fetchpriority `%1$s` for script `%2$s` because it is an alias (it lacks a `src` value).' ),
901 is_string( $value ) ? $value : gettype( $value ),
902 $handle
903 ),
904 '6.9.0'
905 );
906 return false;
907 }
908 }
909 return parent::add_data( $handle, $key, $value );
910 }
911
912 /**
913 * Gets all dependents of a script.
914 *
915 * This is not recursive.
916 *
917 * @since 6.3.0
918 *
919 * @param string $handle The script handle.
920 * @return string[] Script handles.
921 */
922 private function get_dependents( $handle ) {
923 // Check if dependents map for the handle in question is present. If so, use it.
924 if ( isset( $this->dependents_map[ $handle ] ) ) {
925 return $this->dependents_map[ $handle ];
926 }
927
928 $dependents = array();
929
930 // Iterate over all registered scripts, finding dependents of the script passed to this method.
931 foreach ( $this->registered as $registered_handle => $args ) {
932 if ( in_array( $handle, $args->deps, true ) ) {
933 $dependents[] = $registered_handle;
934 }
935 }
936
937 // Add the handles dependents to the map to ease future lookups.
938 $this->dependents_map[ $handle ] = $dependents;
939
940 return $dependents;
941 }
942
943 /**
944 * Checks if the strategy passed is a valid delayed (non-blocking) strategy.
945 *
946 * @since 6.3.0
947 *
948 * @param string|mixed $strategy The strategy to check.
949 * @return bool True if $strategy is one of the delayed strategies, otherwise false.
950 */
951 private function is_delayed_strategy( $strategy ): bool {
952 return in_array(
953 $strategy,
954 $this->delayed_strategies,
955 true
956 );
957 }
958
959 /**
960 * Checks if the provided fetchpriority is valid.
961 *
962 * @since 6.9.0
963 *
964 * @param string|mixed $priority Fetch priority.
965 * @return bool Whether valid fetchpriority.
966 */
967 private function is_valid_fetchpriority( $priority ): bool {
968 return in_array( $priority, array( 'auto', 'low', 'high' ), true );
969 }
970
971 /**
972 * Gets the best eligible loading strategy for a script.
973 *
974 * @since 6.3.0
975 *
976 * @param string $handle The script handle.
977 * @return string The best eligible loading strategy.
978 */
979 private function get_eligible_loading_strategy( $handle ) {
980 $intended_strategy = (string) $this->get_data( $handle, 'strategy' );
981
982 // Bail early if there is no intended strategy.
983 if ( ! $intended_strategy ) {
984 return '';
985 }
986
987 /*
988 * If the intended strategy is 'defer', limit the initial list of eligible
989 * strategies, since 'async' can fallback to 'defer', but not vice-versa.
990 */
991 $initial_strategy = ( 'defer' === $intended_strategy ) ? array( 'defer' ) : null;
992
993 $eligible_strategies = $this->filter_eligible_strategies( $handle, $initial_strategy );
994
995 // Return early once we know the eligible strategy is blocking.
996 if ( empty( $eligible_strategies ) ) {
997 return '';
998 }
999
1000 return in_array( 'async', $eligible_strategies, true ) ? 'async' : 'defer';
1001 }
1002
1003 /**
1004 * Filter the list of eligible loading strategies for a script.
1005 *
1006 * @since 6.3.0
1007 *
1008 * @param string $handle The script handle.
1009 * @param string[]|null $eligible_strategies Optional. The list of strategies to filter. Default null.
1010 * @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1011 * @param array<string, string[]> $stored_results Optional. An array of already computed eligible loading strategies by handle, used to increase performance in large dependency lists.
1012 * @return string[] A list of eligible loading strategies that could be used.
1013 */
1014 private function filter_eligible_strategies( $handle, $eligible_strategies = null, $checked = array(), array &$stored_results = array() ) {
1015 if ( isset( $stored_results[ $handle ] ) ) {
1016 return $stored_results[ $handle ];
1017 }
1018
1019 // If no strategies are being passed, all strategies are eligible.
1020 if ( null === $eligible_strategies ) {
1021 $eligible_strategies = $this->delayed_strategies;
1022 }
1023
1024 // If this handle was already checked, return early.
1025 if ( isset( $checked[ $handle ] ) ) {
1026 return $eligible_strategies;
1027 }
1028
1029 // Mark this handle as checked.
1030 $checked[ $handle ] = true;
1031
1032 // If this handle isn't registered, don't filter anything and return.
1033 if ( ! isset( $this->registered[ $handle ] ) ) {
1034 return $eligible_strategies;
1035 }
1036
1037 // If the handle is not enqueued, don't filter anything and return.
1038 if ( ! $this->query( $handle, 'enqueued' ) ) {
1039 return $eligible_strategies;
1040 }
1041
1042 $is_alias = (bool) ! $this->registered[ $handle ]->src;
1043 $intended_strategy = $this->get_data( $handle, 'strategy' );
1044
1045 // For non-alias handles, an empty intended strategy filters all strategies.
1046 if ( ! $is_alias && empty( $intended_strategy ) ) {
1047 return array();
1048 }
1049
1050 // Handles with inline scripts attached in the 'after' position cannot be delayed.
1051 if ( $this->has_inline_script( $handle, 'after' ) ) {
1052 return array();
1053 }
1054
1055 // If the intended strategy is 'defer', filter out 'async'.
1056 if ( 'defer' === $intended_strategy ) {
1057 $eligible_strategies = array( 'defer' );
1058 }
1059
1060 $dependents = $this->get_dependents( $handle );
1061
1062 // Recursively filter eligible strategies for dependents.
1063 foreach ( $dependents as $dependent ) {
1064 // Bail early once we know the eligible strategy is blocking.
1065 if ( empty( $eligible_strategies ) ) {
1066 return array();
1067 }
1068
1069 $eligible_strategies = $this->filter_eligible_strategies( $dependent, $eligible_strategies, $checked, $stored_results );
1070 }
1071 $stored_results[ $handle ] = $eligible_strategies;
1072 return $eligible_strategies;
1073 }
1074
1075 /**
1076 * Gets the highest fetch priority for a given script and all of its dependent scripts.
1077 *
1078 * @since 6.9.0
1079 * @see self::filter_eligible_strategies()
1080 * @see WP_Script_Modules::get_highest_fetchpriority()
1081 *
1082 * @param string $handle Script module ID.
1083 * @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1084 * @param array<string, string> $stored_results Optional. An array of already computed max priority by handle, used to increase performance in large dependency lists.
1085 * @return string|null Highest fetch priority for the script and its dependents.
1086 */
1087 private function get_highest_fetchpriority_with_dependents( string $handle, array $checked = array(), array &$stored_results = array() ): ?string {
1088 if ( isset( $stored_results[ $handle ] ) ) {
1089 return $stored_results[ $handle ];
1090 }
1091
1092 // If there is a recursive dependency, return early.
1093 if ( isset( $checked[ $handle ] ) ) {
1094 return null;
1095 }
1096
1097 // Mark this handle as checked to guard against infinite recursion.
1098 $checked[ $handle ] = true;
1099
1100 // Abort if the script is not enqueued or a dependency of an enqueued script.
1101 if ( ! $this->query( $handle, 'enqueued' ) ) {
1102 return null;
1103 }
1104
1105 $fetchpriority = $this->get_data( $handle, 'fetchpriority' );
1106 if ( ! $this->is_valid_fetchpriority( $fetchpriority ) ) {
1107 $fetchpriority = 'auto';
1108 }
1109
1110 static $priorities = array(
1111 'low',
1112 'auto',
1113 'high',
1114 );
1115 $high_priority_index = count( $priorities ) - 1;
1116
1117 $highest_priority_index = (int) array_search( $fetchpriority, $priorities, true );
1118 if ( $highest_priority_index !== $high_priority_index ) {
1119 foreach ( $this->get_dependents( $handle ) as $dependent_handle ) {
1120 $dependent_priority = $this->get_highest_fetchpriority_with_dependents( $dependent_handle, $checked, $stored_results );
1121 if ( is_string( $dependent_priority ) ) {
1122 $highest_priority_index = max(
1123 $highest_priority_index,
1124 (int) array_search( $dependent_priority, $priorities, true )
1125 );
1126 if ( $highest_priority_index === $high_priority_index ) {
1127 break;
1128 }
1129 }
1130 }
1131 }
1132 $stored_results[ $handle ] = $priorities[ $highest_priority_index ]; // @phpstan-ignore parameterByRef.type (We know the index is valid and that this will be a string.)
1133 return $priorities[ $highest_priority_index ];
1134 }
1135
1136 /**
1137 * Gets data for inline scripts registered for a specific handle.
1138 *
1139 * @since 6.3.0
1140 *
1141 * @param string $handle Name of the script to get data for. Must be lowercase.
1142 * @param string $position The position of the inline script.
1143 * @return bool Whether the handle has an inline script (either before or after).
1144 */
1145 private function has_inline_script( $handle, $position = null ) {
1146 if ( $position && in_array( $position, array( 'before', 'after' ), true ) ) {
1147 return (bool) $this->get_data( $handle, $position );
1148 }
1149
1150 return (bool) ( $this->get_data( $handle, 'before' ) || $this->get_data( $handle, 'after' ) );
1151 }
1152
1153 /**
1154 * Resets class properties.
1155 *
1156 * @since 2.8.0
1157 */
1158 public function reset() {
1159 $this->do_concat = false;
1160 $this->print_code = '';
1161 $this->concat = '';
1162 $this->concat_version = '';
1163 $this->print_html = '';
1164 $this->ext_version = '';
1165 $this->ext_handles = '';
1166 }
1167
1168 /**
1169 * Gets a script-specific dependency warning message.
1170 *
1171 * @since 6.9.1
1172 *
1173 * @param string $handle Script handle with missing dependencies.
1174 * @param string[] $missing_dependency_handles Missing dependency handles.
1175 * @return string Formatted, localized warning message.
1176 */
1177 protected function get_dependency_warning_message( $handle, $missing_dependency_handles ) {
1178 return sprintf(
1179 /* translators: 1: Script handle, 2: List of missing dependency handles. */
1180 __( 'The script with the handle "%1$s" was enqueued with dependencies that are not registered: %2$s.' ),
1181 $handle,
1182 implode( wp_get_list_item_separator(), $missing_dependency_handles )
1183 );
1184 }
1185}
1186
Ui Ux Design – Teachers Night Out

Get in Touch

© 2024 Teachers Night Out. All Rights Reserved.