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 {
22
public $default_version;
23
public $text_direction = 'ltr';
25
public $concat_version = '';
26
public $do_concat = false;
27
public $print_html = '';
28
public $print_code = '';
31
public 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
public 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" );
96
/** This filter is documented in wp-includes/class.wp-styles.php */
97
$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 );
99
if ( $obj->extra['rtl'] === 'replace' ) {
106
if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
107
$tag = "<!--[if {$obj->extra['conditional']}]>\n" . $tag . "<![endif]-->\n";
110
if ( $this->do_concat ) {
111
$this->print_html .= $tag;
112
if ( $inline_style = $this->print_inline_style( $handle, false ) )
113
$this->print_html .= sprintf( "<style type='text/css'>\n%s\n</style>\n", $inline_style );
116
$this->print_inline_style( $handle );
122
public function add_inline_style( $handle, $code ) {
126
$after = $this->get_data( $handle, 'after' );
132
return $this->add_data( $handle, 'after', $after );
135
public function print_inline_style( $handle, $echo = true ) {
136
$output = $this->get_data( $handle, 'after' );
138
if ( empty( $output ) )
141
$output = implode( "\n", $output );
146
echo "<style type='text/css'>\n";
153
public function all_deps( $handles, $recursion = false, $group = false ) {
154
$r = parent::all_deps( $handles, $recursion );
157
* Filter the array of enqueued styles before processing for output.
161
* @param array $to_do The list of enqueued styles about to be processed.
163
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
168
public function _css_href( $src, $ver, $handle ) {
169
if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
170
$src = $this->base_url . $src;
174
$src = add_query_arg('ver', $ver, $src);
177
* Filter an enqueued style's fully-qualified URL.
181
* @param string $src The source URL of the enqueued style.
182
* @param string $handle The style's registered handle.
184
$src = apply_filters( 'style_loader_src', $src, $handle );
185
return esc_url( $src );
188
public function in_default_dir($src) {
189
if ( ! $this->default_dirs )
192
foreach ( (array) $this->default_dirs as $test ) {
193
if ( 0 === strpos($src, $test) )
199
public function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
200
$this->do_items(false, 1);
204
public function reset() {
205
$this->do_concat = false;
207
$this->concat_version = '';
208
$this->print_html = '';