3 * BackPress Styles enqueue.
5 * These classes were refactored from the WordPress WP_Scripts and WordPress
13 * BackPress Styles enqueue class.
16 * @uses WP_Dependencies
19 class WP_Styles extends WP_Dependencies {
23 var $text_direction = 'ltr';
25 var $concat_version = '';
26 var $do_concat = false;
31 function __construct() {
33 * Fires when the WP_Styles instance is initialized.
37 * @param WP_Styles &$this WP_Styles instance, passed by reference.
39 do_action_ref_array( 'wp_default_styles', array(&$this) );
42 function do_item( $handle ) {
43 if ( !parent::do_item($handle) )
46 $obj = $this->registered[$handle];
47 if ( null === $obj->ver )
50 $ver = $obj->ver ? $obj->ver : $this->default_version;
52 if ( isset($this->args[$handle]) )
53 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
55 if ( $this->do_concat ) {
56 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
57 $this->concat .= "$handle,";
58 $this->concat_version .= "$handle$ver";
60 $this->print_code .= $this->print_inline_style( $handle, false );
66 if ( isset($obj->args) )
67 $media = esc_attr( $obj->args );
71 $href = $this->_css_href( $obj->src, $ver, $handle );
72 if ( empty( $href ) ) {
73 // Turns out there is nothing to print.
76 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
77 $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
80 * Filter the HTML link tag of an enqueued style.
84 * @param string The link tag for the enqueued style.
85 * @param string $handle The style's registered handle.
87 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle );
88 if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
89 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
90 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
91 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));
93 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
97 * Filter the right-to-left (RTL) HTML link tag of an enqueued style.
101 * @param string $rtl_style The right to left link tag for the enqueued style.
102 * @param string $handle The style's registered handle.
104 $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 );
106 if ( $obj->extra['rtl'] === 'replace' ) {
113 if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
114 $tag = "<!--[if {$obj->extra['conditional']}]>\n" . $tag . "<![endif]-->\n";
117 if ( $this->do_concat ) {
118 $this->print_html .= $tag;
119 if ( $inline_style = $this->print_inline_style( $handle, false ) )
120 $this->print_html .= sprintf( "<style type='text/css'>\n%s\n</style>\n", $inline_style );
123 $this->print_inline_style( $handle );
129 function add_inline_style( $handle, $code ) {
133 $after = $this->get_data( $handle, 'after' );
139 return $this->add_data( $handle, 'after', $after );
142 function print_inline_style( $handle, $echo = true ) {
143 $output = $this->get_data( $handle, 'after' );
145 if ( empty( $output ) )
148 $output = implode( "\n", $output );
153 echo "<style type='text/css'>\n";
160 function all_deps( $handles, $recursion = false, $group = false ) {
161 $r = parent::all_deps( $handles, $recursion );
164 * Filter the array of enqueued styles before processing for output.
168 * @param array $to_do The list of enqueued styles about to be processed.
170 $this->to_do = apply_filters( 'print_styles_array', $this->to_do );
175 function _css_href( $src, $ver, $handle ) {
176 if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
177 $src = $this->base_url . $src;
181 $src = add_query_arg('ver', $ver, $src);
184 * Filter an enqueued style's fully-qualified URL.
188 * @param string $src The source URL of the enqueued style.
189 * @param string $handle The style's registered handle.
191 $src = apply_filters( 'style_loader_src', $src, $handle );
192 return esc_url( $src );
195 function in_default_dir($src) {
196 if ( ! $this->default_dirs )
199 foreach ( (array) $this->default_dirs as $test ) {
200 if ( 0 === strpos($src, $test) )
206 function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
207 $this->do_items(false, 1);
212 $this->do_concat = false;
214 $this->concat_version = '';
215 $this->print_html = '';