125 * |
125 * |
126 * @param string $handle The style's registered handle. |
126 * @param string $handle The style's registered handle. |
127 * @return bool True on success, false on failure. |
127 * @return bool True on success, false on failure. |
128 */ |
128 */ |
129 public function do_item( $handle ) { |
129 public function do_item( $handle ) { |
130 if ( !parent::do_item($handle) ) |
130 if ( ! parent::do_item( $handle ) ) { |
131 return false; |
131 return false; |
132 |
132 } |
133 $obj = $this->registered[$handle]; |
133 |
134 if ( null === $obj->ver ) |
134 $obj = $this->registered[ $handle ]; |
|
135 |
|
136 if ( null === $obj->ver ) { |
135 $ver = ''; |
137 $ver = ''; |
136 else |
138 } else { |
137 $ver = $obj->ver ? $obj->ver : $this->default_version; |
139 $ver = $obj->ver ? $obj->ver : $this->default_version; |
138 |
140 } |
139 if ( isset($this->args[$handle]) ) |
141 |
140 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
142 if ( isset( $this->args[ $handle ] ) ) { |
|
143 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; |
|
144 } |
|
145 |
|
146 $src = $obj->src; |
|
147 $cond_before = $cond_after = ''; |
|
148 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
|
149 |
|
150 if ( $conditional ) { |
|
151 $cond_before = "<!--[if {$conditional}]>\n"; |
|
152 $cond_after = "<![endif]-->\n"; |
|
153 } |
|
154 |
|
155 $inline_style = $this->print_inline_style( $handle, false ); |
|
156 |
|
157 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 ); |
|
159 } else { |
|
160 $inline_style_tag = ''; |
|
161 } |
141 |
162 |
142 if ( $this->do_concat ) { |
163 if ( $this->do_concat ) { |
143 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
164 if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) { |
144 $this->concat .= "$handle,"; |
165 $this->concat .= "$handle,"; |
145 $this->concat_version .= "$handle$ver"; |
166 $this->concat_version .= "$handle$ver"; |
146 |
167 |
147 $this->print_code .= $this->print_inline_style( $handle, false ); |
168 $this->print_code .= $inline_style; |
148 |
169 |
149 return true; |
170 return true; |
150 } |
171 } |
151 } |
172 } |
152 |
173 |
153 if ( isset($obj->args) ) |
174 if ( isset( $obj->args ) ) { |
154 $media = esc_attr( $obj->args ); |
175 $media = esc_attr( $obj->args ); |
155 else |
176 } else { |
156 $media = 'all'; |
177 $media = 'all'; |
|
178 } |
157 |
179 |
158 // A single item may alias a set of items, by having dependencies, but no source. |
180 // A single item may alias a set of items, by having dependencies, but no source. |
159 if ( ! $obj->src ) { |
181 if ( ! $src ) { |
160 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
182 if ( $inline_style_tag ) { |
161 $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
|
162 if ( $this->do_concat ) { |
183 if ( $this->do_concat ) { |
163 $this->print_html .= $inline_style; |
184 $this->print_html .= $inline_style_tag; |
164 } else { |
185 } else { |
165 echo $inline_style; |
186 echo $inline_style_tag; |
166 } |
187 } |
167 } |
188 } |
|
189 |
168 return true; |
190 return true; |
169 } |
191 } |
170 |
192 |
171 $href = $this->_css_href( $obj->src, $ver, $handle ); |
193 $href = $this->_css_href( $src, $ver, $handle ); |
172 if ( ! $href ) { |
194 if ( ! $href ) { |
173 return true; |
195 return true; |
174 } |
196 } |
175 |
197 |
176 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
198 $rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
177 $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; |
199 $title = isset( $obj->extra['title'] ) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; |
178 |
200 |
179 /** |
201 /** |
180 * Filters the HTML link tag of an enqueued style. |
202 * Filters the HTML link tag of an enqueued style. |
181 * |
203 * |
182 * @since 2.6.0 |
204 * @since 2.6.0 |
186 * @param string $html The link tag for the enqueued style. |
208 * @param string $html The link tag for the enqueued style. |
187 * @param string $handle The style's registered handle. |
209 * @param string $handle The style's registered handle. |
188 * @param string $href The stylesheet's source URL. |
210 * @param string $href The stylesheet's source URL. |
189 * @param string $media The stylesheet's media attribute. |
211 * @param string $media The stylesheet's media attribute. |
190 */ |
212 */ |
191 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); |
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 ); |
192 if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) { |
214 |
|
215 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) { |
193 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
216 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
194 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
217 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
195 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" )); |
218 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) ); |
196 } else { |
219 } else { |
197 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
220 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
198 } |
221 } |
199 |
222 |
200 /** This filter is documented in wp-includes/class.wp-styles.php */ |
223 /** This filter is documented in wp-includes/class.wp-styles.php */ |
205 } else { |
228 } else { |
206 $tag .= $rtl_tag; |
229 $tag .= $rtl_tag; |
207 } |
230 } |
208 } |
231 } |
209 |
232 |
210 $conditional_pre = $conditional_post = ''; |
|
211 if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) { |
|
212 $conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n"; |
|
213 $conditional_post = "<![endif]-->\n"; |
|
214 } |
|
215 |
|
216 if ( $this->do_concat ) { |
233 if ( $this->do_concat ) { |
217 $this->print_html .= $conditional_pre; |
234 $this->print_html .= $cond_before; |
218 $this->print_html .= $tag; |
235 $this->print_html .= $tag; |
219 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
236 if ( $inline_style_tag ) { |
220 $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
237 $this->print_html .= $inline_style_tag; |
221 } |
238 } |
222 $this->print_html .= $conditional_post; |
239 $this->print_html .= $cond_after; |
223 } else { |
240 } else { |
224 echo $conditional_pre; |
241 echo $cond_before; |
225 echo $tag; |
242 echo $tag; |
226 $this->print_inline_style( $handle ); |
243 $this->print_inline_style( $handle ); |
227 echo $conditional_post; |
244 echo $cond_after; |
228 } |
245 } |
229 |
246 |
230 return true; |
247 return true; |
231 } |
248 } |
232 |
249 |
318 * @param string $ver The version of the enqueued style. |
335 * @param string $ver The version of the enqueued style. |
319 * @param string $handle The style's registered handle. |
336 * @param string $handle The style's registered handle. |
320 * @return string Style's fully-qualified URL. |
337 * @return string Style's fully-qualified URL. |
321 */ |
338 */ |
322 public function _css_href( $src, $ver, $handle ) { |
339 public function _css_href( $src, $ver, $handle ) { |
323 if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { |
340 if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { |
324 $src = $this->base_url . $src; |
341 $src = $this->base_url . $src; |
325 } |
342 } |
326 |
343 |
327 if ( !empty($ver) ) |
344 if ( ! empty( $ver ) ) { |
328 $src = add_query_arg('ver', $ver, $src); |
345 $src = add_query_arg( 'ver', $ver, $src ); |
|
346 } |
329 |
347 |
330 /** |
348 /** |
331 * Filters an enqueued style's fully-qualified URL. |
349 * Filters an enqueued style's fully-qualified URL. |
332 * |
350 * |
333 * @since 2.6.0 |
351 * @since 2.6.0 |
368 * @see WP_Dependencies::do_items() |
388 * @see WP_Dependencies::do_items() |
369 * |
389 * |
370 * @return array Handles of items that have been processed. |
390 * @return array Handles of items that have been processed. |
371 */ |
391 */ |
372 public function do_footer_items() { |
392 public function do_footer_items() { |
373 $this->do_items(false, 1); |
393 $this->do_items( false, 1 ); |
374 return $this->done; |
394 return $this->done; |
375 } |
395 } |
376 |
396 |
377 /** |
397 /** |
378 * Resets class properties. |
398 * Resets class properties. |
379 * |
399 * |
380 * @since 3.3.0 |
400 * @since 3.3.0 |
381 */ |
401 */ |
382 public function reset() { |
402 public function reset() { |
383 $this->do_concat = false; |
403 $this->do_concat = false; |
384 $this->concat = ''; |
404 $this->concat = ''; |
385 $this->concat_version = ''; |
405 $this->concat_version = ''; |
386 $this->print_html = ''; |
406 $this->print_html = ''; |
387 } |
407 } |
388 } |
408 } |