author | ymh <ymh.work@gmail.com> |
Tue, 22 Oct 2019 16:11:46 +0200 | |
changeset 15 | 3d4e9c994f10 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
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: WP_Scripts class |
0 | 4 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @since 2.6.0 |
0 | 6 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
* @subpackage Dependencies |
0 | 9 |
*/ |
10 |
||
11 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* Core class used to register scripts. |
0 | 13 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @see WP_Dependencies |
0 | 17 |
*/ |
18 |
class WP_Scripts extends WP_Dependencies { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* Base URL for scripts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* Full URL with trailing slash. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
public $base_url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* URL of the content directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
*/ |
5 | 35 |
public $content_url; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
/** |
9 | 38 |
* Default version string for scripts. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
*/ |
5 | 43 |
public $default_version; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* Holds handles of scripts which are enqueued in footer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
*/ |
5 | 51 |
public $in_footer = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* Holds a list of script handles which will be concatenated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
*/ |
5 | 59 |
public $concat = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* Holds a string which contains script handles and their version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* @deprecated 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
*/ |
5 | 68 |
public $concat_version = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* Whether to perform concatenation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
*/ |
5 | 76 |
public $do_concat = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* Holds HTML markup of scripts and additional data if concatenation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* is enabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
*/ |
5 | 85 |
public $print_html = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* Holds inline code if concatenation is enabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
*/ |
5 | 93 |
public $print_code = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* Holds a list of script handles which are not in the default directory |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* if concatenation is enabled. |
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 |
* Unused in core. |
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 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
*/ |
5 | 104 |
public $ext_handles = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
|
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 |
* Holds a string which contains handles and versions of scripts which |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* are not in the default directory if concatenation is enabled. |
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 |
* Unused in core. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
*/ |
5 | 115 |
public $ext_version = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* List of default directories. |
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 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
*/ |
5 | 123 |
public $default_dirs; |
0 | 124 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* Constructor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
*/ |
5 | 130 |
public function __construct() { |
0 | 131 |
$this->init(); |
132 |
add_action( 'init', array( $this, 'init' ), 0 ); |
|
133 |
} |
|
134 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* Initialize the class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
*/ |
5 | 140 |
public function init() { |
141 |
/** |
|
142 |
* Fires when the WP_Scripts instance is initialized. |
|
143 |
* |
|
144 |
* @since 2.6.0 |
|
145 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @param WP_Scripts $this WP_Scripts instance (passed by reference). |
5 | 147 |
*/ |
9 | 148 |
do_action_ref_array( 'wp_default_scripts', array( &$this ) ); |
0 | 149 |
} |
150 |
||
151 |
/** |
|
5 | 152 |
* Prints scripts. |
0 | 153 |
* |
154 |
* Prints the scripts passed to it or the print queue. Also prints all necessary dependencies. |
|
155 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* @since 2.8.0 Added the `$group` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* |
5 | 159 |
* @param mixed $handles Optional. Scripts to be printed. (void) prints queue, (string) prints |
160 |
* that script, (array of strings) prints those scripts. Default false. |
|
161 |
* @param int $group Optional. If scripts were queued in groups prints this group number. |
|
162 |
* Default false. |
|
163 |
* @return array Scripts that have been printed. |
|
0 | 164 |
*/ |
5 | 165 |
public function print_scripts( $handles = false, $group = false ) { |
0 | 166 |
return $this->do_items( $handles, $group ); |
167 |
} |
|
168 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* Prints extra scripts of a registered script. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
* @since 2.8.0 Added the `$echo` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @deprecated 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* @see print_extra_script() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @param string $handle The script's registered handle. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* @param bool $echo Optional. Whether to echo the extra script instead of just returning it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
*/ |
5 | 183 |
public function print_scripts_l10n( $handle, $echo = true ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
_deprecated_function( __FUNCTION__, '3.3.0', 'WP_Scripts::print_extra_script()' ); |
0 | 185 |
return $this->print_extra_script( $handle, $echo ); |
186 |
} |
|
187 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* Prints extra scripts of a registered script. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* @since 3.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* @param string $handle The script's registered handle. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* @param bool $echo Optional. Whether to echo the extra script instead of just returning it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
*/ |
5 | 198 |
public function print_extra_script( $handle, $echo = true ) { |
9 | 199 |
if ( ! $output = $this->get_data( $handle, 'data' ) ) { |
0 | 200 |
return; |
9 | 201 |
} |
0 | 202 |
|
9 | 203 |
if ( ! $echo ) { |
0 | 204 |
return $output; |
9 | 205 |
} |
0 | 206 |
|
9 | 207 |
echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5. |
0 | 208 |
echo "/* <![CDATA[ */\n"; |
209 |
echo "$output\n"; |
|
210 |
echo "/* ]]> */\n"; |
|
211 |
echo "</script>\n"; |
|
212 |
||
213 |
return true; |
|
214 |
} |
|
215 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
* Processes a script dependency. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
* @since 2.8.0 Added the `$group` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* @see WP_Dependencies::do_item() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
* |
9 | 224 |
* @param string $handle The script's registered handle. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
*/ |
5 | 228 |
public function do_item( $handle, $group = false ) { |
9 | 229 |
if ( ! parent::do_item( $handle ) ) { |
0 | 230 |
return false; |
9 | 231 |
} |
0 | 232 |
|
9 | 233 |
if ( 0 === $group && $this->groups[ $handle ] > 0 ) { |
0 | 234 |
$this->in_footer[] = $handle; |
235 |
return false; |
|
236 |
} |
|
237 |
||
9 | 238 |
if ( false === $group && in_array( $handle, $this->in_footer, true ) ) { |
0 | 239 |
$this->in_footer = array_diff( $this->in_footer, (array) $handle ); |
9 | 240 |
} |
0 | 241 |
|
9 | 242 |
$obj = $this->registered[ $handle ]; |
5 | 243 |
|
244 |
if ( null === $obj->ver ) { |
|
0 | 245 |
$ver = ''; |
5 | 246 |
} else { |
247 |
$ver = $obj->ver ? $obj->ver : $this->default_version; |
|
248 |
} |
|
0 | 249 |
|
9 | 250 |
if ( isset( $this->args[ $handle ] ) ) { |
251 |
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; |
|
252 |
} |
|
0 | 253 |
|
9 | 254 |
$src = $obj->src; |
5 | 255 |
$cond_before = $cond_after = ''; |
256 |
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
|
257 |
||
258 |
if ( $conditional ) { |
|
259 |
$cond_before = "<!--[if {$conditional}]>\n"; |
|
9 | 260 |
$cond_after = "<![endif]-->\n"; |
5 | 261 |
} |
0 | 262 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
$before_handle = $this->print_inline_script( $handle, 'before', false ); |
9 | 264 |
$after_handle = $this->print_inline_script( $handle, 'after', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
if ( $before_handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
$before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
if ( $after_handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
$after_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $after_handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
|
9 | 274 |
if ( $before_handle || $after_handle ) { |
275 |
$inline_script_tag = "{$cond_before}{$before_handle}{$after_handle}{$cond_after}"; |
|
276 |
} else { |
|
277 |
$inline_script_tag = ''; |
|
278 |
} |
|
279 |
||
0 | 280 |
if ( $this->do_concat ) { |
5 | 281 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
* Filters the script loader source. |
5 | 283 |
* |
284 |
* @since 2.2.0 |
|
285 |
* |
|
286 |
* @param string $src Script loader source path. |
|
287 |
* @param string $handle Script handle. |
|
288 |
*/ |
|
0 | 289 |
$srce = apply_filters( 'script_loader_src', $src, $handle ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
if ( $this->in_default_dir( $srce ) && ( $before_handle || $after_handle ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
$this->do_concat = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
// Have to print the so-far concatenated scripts right away to maintain the right order. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
_print_scripts(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
$this->reset(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
} elseif ( $this->in_default_dir( $srce ) && ! $conditional ) { |
9 | 298 |
$this->print_code .= $this->print_extra_script( $handle, false ); |
299 |
$this->concat .= "$handle,"; |
|
0 | 300 |
$this->concat_version .= "$handle$ver"; |
301 |
return true; |
|
302 |
} else { |
|
303 |
$this->ext_handles .= "$handle,"; |
|
304 |
$this->ext_version .= "$handle$ver"; |
|
305 |
} |
|
306 |
} |
|
307 |
||
5 | 308 |
$has_conditional_data = $conditional && $this->get_data( $handle, 'data' ); |
309 |
||
310 |
if ( $has_conditional_data ) { |
|
311 |
echo $cond_before; |
|
312 |
} |
|
313 |
||
0 | 314 |
$this->print_extra_script( $handle ); |
5 | 315 |
|
316 |
if ( $has_conditional_data ) { |
|
317 |
echo $cond_after; |
|
318 |
} |
|
319 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
// A single item may alias a set of items, by having dependencies, but no source. |
9 | 321 |
if ( ! $src ) { |
322 |
if ( $inline_script_tag ) { |
|
323 |
if ( $this->do_concat ) { |
|
324 |
$this->print_html .= $inline_script_tag; |
|
325 |
} else { |
|
326 |
echo $inline_script_tag; |
|
327 |
} |
|
328 |
} |
|
329 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
|
9 | 333 |
$translations = $this->print_translations( $handle, false ); |
334 |
if ( $translations ) { |
|
335 |
$translations = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $translations ); |
|
336 |
} |
|
337 |
||
5 | 338 |
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { |
0 | 339 |
$src = $this->base_url . $src; |
340 |
} |
|
341 |
||
9 | 342 |
if ( ! empty( $ver ) ) { |
5 | 343 |
$src = add_query_arg( 'ver', $ver, $src ); |
9 | 344 |
} |
0 | 345 |
|
5 | 346 |
/** This filter is documented in wp-includes/class.wp-scripts.php */ |
0 | 347 |
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); |
348 |
||
9 | 349 |
if ( ! $src ) { |
0 | 350 |
return true; |
9 | 351 |
} |
0 | 352 |
|
9 | 353 |
$tag = "{$translations}{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; |
5 | 354 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
* Filters the HTML script tag of an enqueued script. |
5 | 357 |
* |
358 |
* @since 4.1.0 |
|
359 |
* |
|
360 |
* @param string $tag The `<script>` tag for the enqueued script. |
|
361 |
* @param string $handle The script's registered handle. |
|
362 |
* @param string $src The script's source URL. |
|
363 |
*/ |
|
364 |
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src ); |
|
365 |
||
366 |
if ( $this->do_concat ) { |
|
367 |
$this->print_html .= $tag; |
|
368 |
} else { |
|
369 |
echo $tag; |
|
370 |
} |
|
0 | 371 |
|
372 |
return true; |
|
373 |
} |
|
374 |
||
375 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* Adds extra code to a registered script. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* @param string $handle Name of the script to add the inline script to. Must be lowercase. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @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
|
382 |
* @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
|
383 |
* or after. Default 'after'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
public function add_inline_script( $handle, $data, $position = 'after' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
if ( ! $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
if ( 'after' !== $position ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
$position = 'before'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
$script = (array) $this->get_data( $handle, $position ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
$script[] = $data; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
return $this->add_data( $handle, $position, $script ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* Prints inline scripts registered for a specific handle. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* @since 4.5.0 |
0 | 405 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* @param string $handle Name of the script to add the inline script to. Must be lowercase. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* @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
|
408 |
* or after. Default 'after'. |
9 | 409 |
* @param bool $echo Optional. Whether to echo the script instead of just returning it. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
* Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* @return string|false Script on success, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
public function print_inline_script( $handle, $position = 'after', $echo = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
$output = $this->get_data( $handle, $position ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
if ( empty( $output ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
$output = trim( implode( "\n", $output ), "\n" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
if ( $echo ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
return $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* Localizes a script, only if the script has already been added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* |
9 | 434 |
* @param string $handle Name of the script to attach data to. |
435 |
* @param string $object_name Name of the variable that will contain the data. |
|
436 |
* @param array $l10n Array of data to localize. |
|
437 |
* @return bool True on success, false on failure. |
|
0 | 438 |
*/ |
5 | 439 |
public function localize( $handle, $object_name, $l10n ) { |
9 | 440 |
if ( $handle === 'jquery' ) { |
0 | 441 |
$handle = 'jquery-core'; |
9 | 442 |
} |
0 | 443 |
|
9 | 444 |
if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present. |
0 | 445 |
$after = $l10n['l10n_print_after']; |
9 | 446 |
unset( $l10n['l10n_print_after'] ); |
0 | 447 |
} |
448 |
||
449 |
foreach ( (array) $l10n as $key => $value ) { |
|
9 | 450 |
if ( ! is_scalar( $value ) ) { |
0 | 451 |
continue; |
9 | 452 |
} |
0 | 453 |
|
9 | 454 |
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
0 | 455 |
} |
456 |
||
5 | 457 |
$script = "var $object_name = " . wp_json_encode( $l10n ) . ';'; |
0 | 458 |
|
9 | 459 |
if ( ! empty( $after ) ) { |
0 | 460 |
$script .= "\n$after;"; |
9 | 461 |
} |
0 | 462 |
|
463 |
$data = $this->get_data( $handle, 'data' ); |
|
464 |
||
9 | 465 |
if ( ! empty( $data ) ) { |
0 | 466 |
$script = "$data\n$script"; |
9 | 467 |
} |
0 | 468 |
|
469 |
return $this->add_data( $handle, 'data', $script ); |
|
470 |
} |
|
471 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
* Sets handle group. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* @see WP_Dependencies::set_group() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* @param string $handle Name of the item. Should be unique. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @param bool $recursion Internal flag that calling function was called recursively. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* @return bool Not already in the group or a lower group |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
*/ |
5 | 484 |
public function set_group( $handle, $recursion, $group = false ) { |
9 | 485 |
if ( isset( $this->registered[ $handle ]->args ) && $this->registered[ $handle ]->args === 1 ) { |
0 | 486 |
$grp = 1; |
9 | 487 |
} else { |
0 | 488 |
$grp = (int) $this->get_data( $handle, 'group' ); |
9 | 489 |
} |
0 | 490 |
|
9 | 491 |
if ( false !== $group && $grp > $group ) { |
0 | 492 |
$grp = $group; |
9 | 493 |
} |
0 | 494 |
|
495 |
return parent::set_group( $handle, $recursion, $grp ); |
|
496 |
} |
|
497 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
/** |
9 | 499 |
* Sets a translation textdomain. |
500 |
* |
|
501 |
* @since 5.0.0 |
|
502 |
* @since 5.1.0 The `$domain` parameter was made optional. |
|
503 |
* |
|
504 |
* @param string $handle Name of the script to register a translation domain to. |
|
505 |
* @param string $domain Optional. Text domain. Default 'default'. |
|
506 |
* @param string $path Optional. The full file path to the directory containing translation files. |
|
507 |
* @return bool True if the text domain was registered, false if not. |
|
508 |
*/ |
|
509 |
public function set_translations( $handle, $domain = 'default', $path = null ) { |
|
510 |
if ( ! isset( $this->registered[ $handle ] ) ) { |
|
511 |
return false; |
|
512 |
} |
|
513 |
||
514 |
/** @var \_WP_Dependency $obj */ |
|
515 |
$obj = $this->registered[ $handle ]; |
|
516 |
||
517 |
if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) { |
|
518 |
$obj->deps[] = 'wp-i18n'; |
|
519 |
} |
|
520 |
||
521 |
return $obj->set_translations( $domain, $path ); |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Prints translations set for a specific handle. |
|
526 |
* |
|
527 |
* @since 5.0.0 |
|
528 |
* |
|
529 |
* @param string $handle Name of the script to add the inline script to. Must be lowercase. |
|
530 |
* @param bool $echo Optional. Whether to echo the script instead of just returning it. |
|
531 |
* Default true. |
|
532 |
* @return string|false Script on success, false otherwise. |
|
533 |
*/ |
|
534 |
public function print_translations( $handle, $echo = true ) { |
|
535 |
if ( ! isset( $this->registered[ $handle ] ) || empty( $this->registered[ $handle ]->textdomain ) ) { |
|
536 |
return false; |
|
537 |
} |
|
538 |
||
539 |
$domain = $this->registered[ $handle ]->textdomain; |
|
540 |
$path = $this->registered[ $handle ]->translations_path; |
|
541 |
||
542 |
$json_translations = load_script_textdomain( $handle, $domain, $path ); |
|
543 |
||
544 |
if ( ! $json_translations ) { |
|
545 |
// Register empty locale data object to ensure the domain still exists. |
|
546 |
$json_translations = '{ "locale_data": { "messages": { "": {} } } }'; |
|
547 |
} |
|
548 |
||
549 |
$output = <<<JS |
|
550 |
( function( domain, translations ) { |
|
551 |
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages; |
|
552 |
localeData[""].domain = domain; |
|
553 |
wp.i18n.setLocaleData( localeData, domain ); |
|
554 |
} )( "{$domain}", {$json_translations} ); |
|
555 |
JS; |
|
556 |
||
557 |
if ( $echo ) { |
|
558 |
printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); |
|
559 |
} |
|
560 |
||
561 |
return $output; |
|
562 |
} |
|
563 |
||
564 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* Determines script dependencies. |
9 | 566 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* @see WP_Dependencies::all_deps() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* @param bool $recursion Internal flag that function is calling itself. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* @return bool True on success, false on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
*/ |
5 | 576 |
public function all_deps( $handles, $recursion = false, $group = false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
$r = parent::all_deps( $handles, $recursion, $group ); |
5 | 578 |
if ( ! $recursion ) { |
579 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* Filters the list of script dependencies left to print. |
5 | 581 |
* |
582 |
* @since 2.3.0 |
|
583 |
* |
|
9 | 584 |
* @param string[] $to_do An array of script dependency handles. |
5 | 585 |
*/ |
0 | 586 |
$this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); |
5 | 587 |
} |
0 | 588 |
return $r; |
589 |
} |
|
590 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* Processes items and dependencies for the head group. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
* @see WP_Dependencies::do_items() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
* @return array Handles of items that have been processed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
*/ |
5 | 600 |
public function do_head_items() { |
9 | 601 |
$this->do_items( false, 0 ); |
0 | 602 |
return $this->done; |
603 |
} |
|
604 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* Processes items and dependencies for the footer group. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
* @see WP_Dependencies::do_items() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
* @return array Handles of items that have been processed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
*/ |
5 | 614 |
public function do_footer_items() { |
9 | 615 |
$this->do_items( false, 1 ); |
0 | 616 |
return $this->done; |
617 |
} |
|
618 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* Whether a handle's source is in a default directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* @param string $src The source of the enqueued script. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* @return bool True if found, false if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
*/ |
5 | 627 |
public function in_default_dir( $src ) { |
628 |
if ( ! $this->default_dirs ) { |
|
0 | 629 |
return true; |
5 | 630 |
} |
0 | 631 |
|
5 | 632 |
if ( 0 === strpos( $src, '/' . WPINC . '/js/l10n' ) ) { |
0 | 633 |
return false; |
5 | 634 |
} |
0 | 635 |
|
636 |
foreach ( (array) $this->default_dirs as $test ) { |
|
5 | 637 |
if ( 0 === strpos( $src, $test ) ) { |
0 | 638 |
return true; |
5 | 639 |
} |
0 | 640 |
} |
641 |
return false; |
|
642 |
} |
|
643 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* Resets class properties. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
*/ |
5 | 649 |
public function reset() { |
9 | 650 |
$this->do_concat = false; |
651 |
$this->print_code = ''; |
|
652 |
$this->concat = ''; |
|
0 | 653 |
$this->concat_version = ''; |
9 | 654 |
$this->print_html = ''; |
655 |
$this->ext_version = ''; |
|
656 |
$this->ext_handles = ''; |
|
0 | 657 |
} |
658 |
} |