Edit File by line
/home/barbar84/www/wp-inclu...
File: class.wp-styles.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Dependencies API: WP_Styles class
[2] Fix | Delete
*
[3] Fix | Delete
* @since 2.6.0
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Dependencies
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Core class used to register styles.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 2.6.0
[13] Fix | Delete
*
[14] Fix | Delete
* @see WP_Dependencies
[15] Fix | Delete
*/
[16] Fix | Delete
class WP_Styles extends WP_Dependencies {
[17] Fix | Delete
/**
[18] Fix | Delete
* Base URL for styles.
[19] Fix | Delete
*
[20] Fix | Delete
* Full URL with trailing slash.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 2.6.0
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public $base_url;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* URL of the content directory.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 2.8.0
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
public $content_url;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Default version string for stylesheets.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 2.6.0
[39] Fix | Delete
* @var string
[40] Fix | Delete
*/
[41] Fix | Delete
public $default_version;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* The current text direction.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 2.6.0
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
public $text_direction = 'ltr';
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Holds a list of style handles which will be concatenated.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 2.8.0
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
public $concat = '';
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Holds a string which contains style handles and their version.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 2.8.0
[63] Fix | Delete
* @deprecated 3.4.0
[64] Fix | Delete
* @var string
[65] Fix | Delete
*/
[66] Fix | Delete
public $concat_version = '';
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Whether to perform concatenation.
[70] Fix | Delete
*
[71] Fix | Delete
* @since 2.8.0
[72] Fix | Delete
* @var bool
[73] Fix | Delete
*/
[74] Fix | Delete
public $do_concat = false;
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Holds HTML markup of styles and additional data if concatenation
[78] Fix | Delete
* is enabled.
[79] Fix | Delete
*
[80] Fix | Delete
* @since 2.8.0
[81] Fix | Delete
* @var string
[82] Fix | Delete
*/
[83] Fix | Delete
public $print_html = '';
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Holds inline styles if concatenation is enabled.
[87] Fix | Delete
*
[88] Fix | Delete
* @since 3.3.0
[89] Fix | Delete
* @var string
[90] Fix | Delete
*/
[91] Fix | Delete
public $print_code = '';
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* List of default directories.
[95] Fix | Delete
*
[96] Fix | Delete
* @since 2.8.0
[97] Fix | Delete
* @var array
[98] Fix | Delete
*/
[99] Fix | Delete
public $default_dirs;
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Holds a string which contains the type attribute for style tag.
[103] Fix | Delete
*
[104] Fix | Delete
* If the current theme does not declare HTML5 support for 'style',
[105] Fix | Delete
* then it initializes as `type='text/css'`.
[106] Fix | Delete
*
[107] Fix | Delete
* @since 5.3.0
[108] Fix | Delete
* @var string
[109] Fix | Delete
*/
[110] Fix | Delete
private $type_attr = '';
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Constructor.
[114] Fix | Delete
*
[115] Fix | Delete
* @since 2.6.0
[116] Fix | Delete
*/
[117] Fix | Delete
public function __construct() {
[118] Fix | Delete
if (
[119] Fix | Delete
function_exists( 'is_admin' ) && ! is_admin()
[120] Fix | Delete
&&
[121] Fix | Delete
function_exists( 'current_theme_supports' ) && ! current_theme_supports( 'html5', 'style' )
[122] Fix | Delete
) {
[123] Fix | Delete
$this->type_attr = " type='text/css'";
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Fires when the WP_Styles instance is initialized.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 2.6.0
[130] Fix | Delete
*
[131] Fix | Delete
* @param WP_Styles $this WP_Styles instance (passed by reference).
[132] Fix | Delete
*/
[133] Fix | Delete
do_action_ref_array( 'wp_default_styles', array( &$this ) );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Processes a style dependency.
[138] Fix | Delete
*
[139] Fix | Delete
* @since 2.6.0
[140] Fix | Delete
* @since 5.5.0 Added the `$group` parameter.
[141] Fix | Delete
*
[142] Fix | Delete
* @see WP_Dependencies::do_item()
[143] Fix | Delete
*
[144] Fix | Delete
* @param string $handle The style's registered handle.
[145] Fix | Delete
* @param int|false $group Optional. Group level: level (int), no groups (false).
[146] Fix | Delete
* Default false.
[147] Fix | Delete
* @return bool True on success, false on failure.
[148] Fix | Delete
*/
[149] Fix | Delete
public function do_item( $handle, $group = false ) {
[150] Fix | Delete
if ( ! parent::do_item( $handle ) ) {
[151] Fix | Delete
return false;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
$obj = $this->registered[ $handle ];
[155] Fix | Delete
[156] Fix | Delete
if ( null === $obj->ver ) {
[157] Fix | Delete
$ver = '';
[158] Fix | Delete
} else {
[159] Fix | Delete
$ver = $obj->ver ? $obj->ver : $this->default_version;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if ( isset( $this->args[ $handle ] ) ) {
[163] Fix | Delete
$ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
$src = $obj->src;
[167] Fix | Delete
$cond_before = '';
[168] Fix | Delete
$cond_after = '';
[169] Fix | Delete
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
[170] Fix | Delete
[171] Fix | Delete
if ( $conditional ) {
[172] Fix | Delete
$cond_before = "<!--[if {$conditional}]>\n";
[173] Fix | Delete
$cond_after = "<![endif]-->\n";
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
$inline_style = $this->print_inline_style( $handle, false );
[177] Fix | Delete
[178] Fix | Delete
if ( $inline_style ) {
[179] Fix | Delete
$inline_style_tag = sprintf(
[180] Fix | Delete
"<style id='%s-inline-css'%s>\n%s\n</style>\n",
[181] Fix | Delete
esc_attr( $handle ),
[182] Fix | Delete
$this->type_attr,
[183] Fix | Delete
$inline_style
[184] Fix | Delete
);
[185] Fix | Delete
} else {
[186] Fix | Delete
$inline_style_tag = '';
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( $this->do_concat ) {
[190] Fix | Delete
if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) {
[191] Fix | Delete
$this->concat .= "$handle,";
[192] Fix | Delete
$this->concat_version .= "$handle$ver";
[193] Fix | Delete
[194] Fix | Delete
$this->print_code .= $inline_style;
[195] Fix | Delete
[196] Fix | Delete
return true;
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
if ( isset( $obj->args ) ) {
[201] Fix | Delete
$media = esc_attr( $obj->args );
[202] Fix | Delete
} else {
[203] Fix | Delete
$media = 'all';
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
// A single item may alias a set of items, by having dependencies, but no source.
[207] Fix | Delete
if ( ! $src ) {
[208] Fix | Delete
if ( $inline_style_tag ) {
[209] Fix | Delete
if ( $this->do_concat ) {
[210] Fix | Delete
$this->print_html .= $inline_style_tag;
[211] Fix | Delete
} else {
[212] Fix | Delete
echo $inline_style_tag;
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
return true;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
$href = $this->_css_href( $src, $ver, $handle );
[220] Fix | Delete
if ( ! $href ) {
[221] Fix | Delete
return true;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
$rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
[225] Fix | Delete
$title = isset( $obj->extra['title'] ) ? sprintf( "title='%s'", esc_attr( $obj->extra['title'] ) ) : '';
[226] Fix | Delete
[227] Fix | Delete
$tag = sprintf(
[228] Fix | Delete
"<link rel='%s' id='%s-css' %s href='%s'%s media='%s' />\n",
[229] Fix | Delete
$rel,
[230] Fix | Delete
$handle,
[231] Fix | Delete
$title,
[232] Fix | Delete
$href,
[233] Fix | Delete
$this->type_attr,
[234] Fix | Delete
$media
[235] Fix | Delete
);
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Filters the HTML link tag of an enqueued style.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 2.6.0
[241] Fix | Delete
* @since 4.3.0 Introduced the `$href` parameter.
[242] Fix | Delete
* @since 4.5.0 Introduced the `$media` parameter.
[243] Fix | Delete
*
[244] Fix | Delete
* @param string $html The link tag for the enqueued style.
[245] Fix | Delete
* @param string $handle The style's registered handle.
[246] Fix | Delete
* @param string $href The stylesheet's source URL.
[247] Fix | Delete
* @param string $media The stylesheet's media attribute.
[248] Fix | Delete
*/
[249] Fix | Delete
$tag = apply_filters( 'style_loader_tag', $tag, $handle, $href, $media );
[250] Fix | Delete
[251] Fix | Delete
if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) {
[252] Fix | Delete
if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
[253] Fix | Delete
$suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
[254] Fix | Delete
$rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $src, $ver, "$handle-rtl" ) );
[255] Fix | Delete
} else {
[256] Fix | Delete
$rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
$rtl_tag = sprintf(
[260] Fix | Delete
"<link rel='%s' id='%s-rtl-css' %s href='%s'%s media='%s' />\n",
[261] Fix | Delete
$rel,
[262] Fix | Delete
$handle,
[263] Fix | Delete
$title,
[264] Fix | Delete
$rtl_href,
[265] Fix | Delete
$this->type_attr,
[266] Fix | Delete
$media
[267] Fix | Delete
);
[268] Fix | Delete
[269] Fix | Delete
/** This filter is documented in wp-includes/class.wp-styles.php */
[270] Fix | Delete
$rtl_tag = apply_filters( 'style_loader_tag', $rtl_tag, $handle, $rtl_href, $media );
[271] Fix | Delete
[272] Fix | Delete
if ( 'replace' === $obj->extra['rtl'] ) {
[273] Fix | Delete
$tag = $rtl_tag;
[274] Fix | Delete
} else {
[275] Fix | Delete
$tag .= $rtl_tag;
[276] Fix | Delete
}
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
if ( $this->do_concat ) {
[280] Fix | Delete
$this->print_html .= $cond_before;
[281] Fix | Delete
$this->print_html .= $tag;
[282] Fix | Delete
if ( $inline_style_tag ) {
[283] Fix | Delete
$this->print_html .= $inline_style_tag;
[284] Fix | Delete
}
[285] Fix | Delete
$this->print_html .= $cond_after;
[286] Fix | Delete
} else {
[287] Fix | Delete
echo $cond_before;
[288] Fix | Delete
echo $tag;
[289] Fix | Delete
$this->print_inline_style( $handle );
[290] Fix | Delete
echo $cond_after;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
return true;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Adds extra CSS styles to a registered stylesheet.
[298] Fix | Delete
*
[299] Fix | Delete
* @since 3.3.0
[300] Fix | Delete
*
[301] Fix | Delete
* @param string $handle The style's registered handle.
[302] Fix | Delete
* @param string $code String containing the CSS styles to be added.
[303] Fix | Delete
* @return bool True on success, false on failure.
[304] Fix | Delete
*/
[305] Fix | Delete
public function add_inline_style( $handle, $code ) {
[306] Fix | Delete
if ( ! $code ) {
[307] Fix | Delete
return false;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
$after = $this->get_data( $handle, 'after' );
[311] Fix | Delete
if ( ! $after ) {
[312] Fix | Delete
$after = array();
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
$after[] = $code;
[316] Fix | Delete
[317] Fix | Delete
return $this->add_data( $handle, 'after', $after );
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
/**
[321] Fix | Delete
* Prints extra CSS styles of a registered stylesheet.
[322] Fix | Delete
*
[323] Fix | Delete
* @since 3.3.0
[324] Fix | Delete
*
[325] Fix | Delete
* @param string $handle The style's registered handle.
[326] Fix | Delete
* @param bool $echo Optional. Whether to echo the inline style
[327] Fix | Delete
* instead of just returning it. Default true.
[328] Fix | Delete
* @return string|bool False if no data exists, inline styles if `$echo` is true,
[329] Fix | Delete
* true otherwise.
[330] Fix | Delete
*/
[331] Fix | Delete
public function print_inline_style( $handle, $echo = true ) {
[332] Fix | Delete
$output = $this->get_data( $handle, 'after' );
[333] Fix | Delete
[334] Fix | Delete
if ( empty( $output ) ) {
[335] Fix | Delete
return false;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
$output = implode( "\n", $output );
[339] Fix | Delete
[340] Fix | Delete
if ( ! $echo ) {
[341] Fix | Delete
return $output;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
printf(
[345] Fix | Delete
"<style id='%s-inline-css'%s>\n%s\n</style>\n",
[346] Fix | Delete
esc_attr( $handle ),
[347] Fix | Delete
$this->type_attr,
[348] Fix | Delete
$output
[349] Fix | Delete
);
[350] Fix | Delete
[351] Fix | Delete
return true;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Determines style dependencies.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 2.6.0
[358] Fix | Delete
*
[359] Fix | Delete
* @see WP_Dependencies::all_deps()
[360] Fix | Delete
*
[361] Fix | Delete
* @param string|string[] $handles Item handle (string) or item handles (array of strings).
[362] Fix | Delete
* @param bool $recursion Optional. Internal flag that function is calling itself.
[363] Fix | Delete
* Default false.
[364] Fix | Delete
* @param int|false $group Optional. Group level: level (int), no groups (false).
[365] Fix | Delete
* Default false.
[366] Fix | Delete
* @return bool True on success, false on failure.
[367] Fix | Delete
*/
[368] Fix | Delete
public function all_deps( $handles, $recursion = false, $group = false ) {
[369] Fix | Delete
$r = parent::all_deps( $handles, $recursion, $group );
[370] Fix | Delete
if ( ! $recursion ) {
[371] Fix | Delete
/**
[372] Fix | Delete
* Filters the array of enqueued styles before processing for output.
[373] Fix | Delete
*
[374] Fix | Delete
* @since 2.6.0
[375] Fix | Delete
*
[376] Fix | Delete
* @param string[] $to_do The list of enqueued style handles about to be processed.
[377] Fix | Delete
*/
[378] Fix | Delete
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
[379] Fix | Delete
}
[380] Fix | Delete
return $r;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Generates an enqueued style's fully-qualified URL.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 2.6.0
[387] Fix | Delete
*
[388] Fix | Delete
* @param string $src The source of the enqueued style.
[389] Fix | Delete
* @param string $ver The version of the enqueued style.
[390] Fix | Delete
* @param string $handle The style's registered handle.
[391] Fix | Delete
* @return string Style's fully-qualified URL.
[392] Fix | Delete
*/
[393] Fix | Delete
public function _css_href( $src, $ver, $handle ) {
[394] Fix | Delete
if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) {
[395] Fix | Delete
$src = $this->base_url . $src;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
if ( ! empty( $ver ) ) {
[399] Fix | Delete
$src = add_query_arg( 'ver', $ver, $src );
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
/**
[403] Fix | Delete
* Filters an enqueued style's fully-qualified URL.
[404] Fix | Delete
*
[405] Fix | Delete
* @since 2.6.0
[406] Fix | Delete
*
[407] Fix | Delete
* @param string $src The source URL of the enqueued style.
[408] Fix | Delete
* @param string $handle The style's registered handle.
[409] Fix | Delete
*/
[410] Fix | Delete
$src = apply_filters( 'style_loader_src', $src, $handle );
[411] Fix | Delete
return esc_url( $src );
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* Whether a handle's source is in a default directory.
[416] Fix | Delete
*
[417] Fix | Delete
* @since 2.8.0
[418] Fix | Delete
*
[419] Fix | Delete
* @param string $src The source of the enqueued style.
[420] Fix | Delete
* @return bool True if found, false if not.
[421] Fix | Delete
*/
[422] Fix | Delete
public function in_default_dir( $src ) {
[423] Fix | Delete
if ( ! $this->default_dirs ) {
[424] Fix | Delete
return true;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
foreach ( (array) $this->default_dirs as $test ) {
[428] Fix | Delete
if ( 0 === strpos( $src, $test ) ) {
[429] Fix | Delete
return true;
[430] Fix | Delete
}
[431] Fix | Delete
}
[432] Fix | Delete
return false;
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Processes items and dependencies for the footer group.
[437] Fix | Delete
*
[438] Fix | Delete
* HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
[439] Fix | Delete
*
[440] Fix | Delete
* @since 3.3.0
[441] Fix | Delete
*
[442] Fix | Delete
* @see WP_Dependencies::do_items()
[443] Fix | Delete
*
[444] Fix | Delete
* @return string[] Handles of items that have been processed.
[445] Fix | Delete
*/
[446] Fix | Delete
public function do_footer_items() {
[447] Fix | Delete
$this->do_items( false, 1 );
[448] Fix | Delete
return $this->done;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Resets class properties.
[453] Fix | Delete
*
[454] Fix | Delete
* @since 3.3.0
[455] Fix | Delete
*/
[456] Fix | Delete
public function reset() {
[457] Fix | Delete
$this->do_concat = false;
[458] Fix | Delete
$this->concat = '';
[459] Fix | Delete
$this->concat_version = '';
[460] Fix | Delete
$this->print_html = '';
[461] Fix | Delete
}
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function