99 * @var array |
99 * @var array |
100 */ |
100 */ |
101 public $default_dirs; |
101 public $default_dirs; |
102 |
102 |
103 /** |
103 /** |
|
104 * Holds a string which contains the type attribute for style tag. |
|
105 * |
|
106 * If the current theme does not declare HTML5 support for 'style', |
|
107 * then it initializes as `type='text/css'`. |
|
108 * |
|
109 * @since 5.3.0 |
|
110 * @var string |
|
111 */ |
|
112 private $type_attr = ''; |
|
113 |
|
114 /** |
104 * Constructor. |
115 * Constructor. |
105 * |
116 * |
106 * @since 2.6.0 |
117 * @since 2.6.0 |
107 */ |
118 */ |
108 public function __construct() { |
119 public function __construct() { |
|
120 if ( |
|
121 function_exists( 'is_admin' ) && ! is_admin() |
|
122 && |
|
123 function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' ) |
|
124 ) { |
|
125 $this->type_attr = " type='text/css'"; |
|
126 } |
|
127 |
109 /** |
128 /** |
110 * Fires when the WP_Styles instance is initialized. |
129 * Fires when the WP_Styles instance is initialized. |
111 * |
130 * |
112 * @since 2.6.0 |
131 * @since 2.6.0 |
113 * |
132 * |
118 |
137 |
119 /** |
138 /** |
120 * Processes a style dependency. |
139 * Processes a style dependency. |
121 * |
140 * |
122 * @since 2.6.0 |
141 * @since 2.6.0 |
|
142 * @since 5.5.0 Added the `$group` parameter. |
123 * |
143 * |
124 * @see WP_Dependencies::do_item() |
144 * @see WP_Dependencies::do_item() |
125 * |
145 * |
126 * @param string $handle The style's registered handle. |
146 * @param string $handle The style's registered handle. |
|
147 * @param int|false $group Optional. Group level: level (int), no groups (false). |
|
148 * Default false. |
127 * @return bool True on success, false on failure. |
149 * @return bool True on success, false on failure. |
128 */ |
150 */ |
129 public function do_item( $handle ) { |
151 public function do_item( $handle, $group = false ) { |
130 if ( ! parent::do_item( $handle ) ) { |
152 if ( ! parent::do_item( $handle ) ) { |
131 return false; |
153 return false; |
132 } |
154 } |
133 |
155 |
134 $obj = $this->registered[ $handle ]; |
156 $obj = $this->registered[ $handle ]; |
142 if ( isset( $this->args[ $handle ] ) ) { |
164 if ( isset( $this->args[ $handle ] ) ) { |
143 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; |
165 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; |
144 } |
166 } |
145 |
167 |
146 $src = $obj->src; |
168 $src = $obj->src; |
147 $cond_before = $cond_after = ''; |
169 $cond_before = ''; |
|
170 $cond_after = ''; |
148 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
171 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
149 |
172 |
150 if ( $conditional ) { |
173 if ( $conditional ) { |
151 $cond_before = "<!--[if {$conditional}]>\n"; |
174 $cond_before = "<!--[if {$conditional}]>\n"; |
152 $cond_after = "<![endif]-->\n"; |
175 $cond_after = "<![endif]-->\n"; |
153 } |
176 } |
154 |
177 |
155 $inline_style = $this->print_inline_style( $handle, false ); |
178 $inline_style = $this->print_inline_style( $handle, false ); |
156 |
179 |
157 if ( $inline_style ) { |
180 if ( $inline_style ) { |
158 $inline_style_tag = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
181 $inline_style_tag = sprintf( |
|
182 "<style id='%s-inline-css'%s>\n%s\n</style>\n", |
|
183 esc_attr( $handle ), |
|
184 $this->type_attr, |
|
185 $inline_style |
|
186 ); |
159 } else { |
187 } else { |
160 $inline_style_tag = ''; |
188 $inline_style_tag = ''; |
161 } |
189 } |
162 |
190 |
163 if ( $this->do_concat ) { |
191 if ( $this->do_concat ) { |
208 * @param string $html The link tag for the enqueued style. |
246 * @param string $html The link tag for the enqueued style. |
209 * @param string $handle The style's registered handle. |
247 * @param string $handle The style's registered handle. |
210 * @param string $href The stylesheet's source URL. |
248 * @param string $href The stylesheet's source URL. |
211 * @param string $media The stylesheet's media attribute. |
249 * @param string $media The stylesheet's media attribute. |
212 */ |
250 */ |
213 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media ); |
251 $tag = apply_filters( 'style_loader_tag', $tag, $handle, $href, $media ); |
214 |
252 |
215 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) { |
253 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) { |
216 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
254 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
217 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
255 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
218 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) ); |
256 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) ); |
219 } else { |
257 } else { |
220 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
258 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
221 } |
259 } |
222 |
260 |
|
261 $rtl_tag = sprintf( |
|
262 "<link rel='%s' id='%s-rtl-css' %s href='%s'%s media='%s' />\n", |
|
263 $rel, |
|
264 $handle, |
|
265 $title, |
|
266 $rtl_href, |
|
267 $this->type_attr, |
|
268 $media |
|
269 ); |
|
270 |
223 /** This filter is documented in wp-includes/class.wp-styles.php */ |
271 /** This filter is documented in wp-includes/class.wp-styles.php */ |
224 $rtl_tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media ); |
272 $rtl_tag = apply_filters( 'style_loader_tag', $rtl_tag, $handle, $rtl_href, $media ); |
225 |
273 |
226 if ( $obj->extra['rtl'] === 'replace' ) { |
274 if ( 'replace' === $obj->extra['rtl'] ) { |
227 $tag = $rtl_tag; |
275 $tag = $rtl_tag; |
228 } else { |
276 } else { |
229 $tag .= $rtl_tag; |
277 $tag .= $rtl_tag; |
230 } |
278 } |
231 } |
279 } |
275 * Prints extra CSS styles of a registered stylesheet. |
323 * Prints extra CSS styles of a registered stylesheet. |
276 * |
324 * |
277 * @since 3.3.0 |
325 * @since 3.3.0 |
278 * |
326 * |
279 * @param string $handle The style's registered handle. |
327 * @param string $handle The style's registered handle. |
280 * @param bool $echo Optional. Whether to echo the inline style instead of just returning it. |
328 * @param bool $echo Optional. Whether to echo the inline style |
281 * Default true. |
329 * instead of just returning it. Default true. |
282 * @return string|bool False if no data exists, inline styles if `$echo` is true, true otherwise. |
330 * @return string|bool False if no data exists, inline styles if `$echo` is true, |
|
331 * true otherwise. |
283 */ |
332 */ |
284 public function print_inline_style( $handle, $echo = true ) { |
333 public function print_inline_style( $handle, $echo = true ) { |
285 $output = $this->get_data( $handle, 'after' ); |
334 $output = $this->get_data( $handle, 'after' ); |
286 |
335 |
287 if ( empty( $output ) ) { |
336 if ( empty( $output ) ) { |
304 * |
358 * |
305 * @since 2.6.0 |
359 * @since 2.6.0 |
306 * |
360 * |
307 * @see WP_Dependencies::all_deps() |
361 * @see WP_Dependencies::all_deps() |
308 * |
362 * |
309 * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings). |
363 * @param string|string[] $handles Item handle (string) or item handles (array of strings). |
310 * @param bool $recursion Internal flag that function is calling itself. |
364 * @param bool $recursion Optional. Internal flag that function is calling itself. |
311 * @param int|false $group Group level: (int) level, (false) no groups. |
365 * Default false. |
|
366 * @param int|false $group Optional. Group level: level (int), no groups (false). |
|
367 * Default false. |
312 * @return bool True on success, false on failure. |
368 * @return bool True on success, false on failure. |
313 */ |
369 */ |
314 public function all_deps( $handles, $recursion = false, $group = false ) { |
370 public function all_deps( $handles, $recursion = false, $group = false ) { |
315 $r = parent::all_deps( $handles, $recursion, $group ); |
371 $r = parent::all_deps( $handles, $recursion, $group ); |
316 if ( ! $recursion ) { |
372 if ( ! $recursion ) { |
329 /** |
385 /** |
330 * Generates an enqueued style's fully-qualified URL. |
386 * Generates an enqueued style's fully-qualified URL. |
331 * |
387 * |
332 * @since 2.6.0 |
388 * @since 2.6.0 |
333 * |
389 * |
334 * @param string $src The source of the enqueued style. |
390 * @param string $src The source of the enqueued style. |
335 * @param string $ver The version of the enqueued style. |
391 * @param string $ver The version of the enqueued style. |
336 * @param string $handle The style's registered handle. |
392 * @param string $handle The style's registered handle. |
337 * @return string Style's fully-qualified URL. |
393 * @return string Style's fully-qualified URL. |
338 */ |
394 */ |
339 public function _css_href( $src, $ver, $handle ) { |
395 public function _css_href( $src, $ver, $handle ) { |
340 if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { |
396 if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { |