content ); if ( $noptimizeCSS ) { return false; } $whitelistCSS = apply_filters( 'autoptimize_filter_css_whitelist', '', $this->content ); if ( ! empty( $whitelistCSS ) ) { $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelistCSS ) ) ); } $removableCSS = apply_filters( 'autoptimize_filter_css_removables', '' ); if ( ! empty( $removableCSS ) ) { $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removableCSS ) ) ); } $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 ); // filter to "late inject minified CSS", default to true for now (it is faster). $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true ); // Remove everything that's not the header. if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) { $content = explode( '', $this->content, 2 ); $this->content = $content[0] . ''; $this->restofcontent = $content[1]; } // Determine whether we're doing CSS-files aggregation or not. if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) { $this->aggregate = false; } // Returning true for "dontaggregate" turns off aggregation. if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) { $this->aggregate = false; } // include inline? if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) { $this->include_inline = true; } // List of CSS strings which are excluded from autoptimization. $excludeCSS = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content ); if ( '' !== $excludeCSS ) { $this->dontmove = array_filter( array_map( 'trim', explode( ',', $excludeCSS ) ) ); } else { $this->dontmove = array(); } // forcefully exclude CSS with data-noptimize attrib. $this->dontmove[] = 'data-noptimize'; // Should we defer css? // value: true / false. $this->defer = $options['defer']; $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content ); // Should we inline while deferring? // value: inlined CSS. $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content ); // Should we inline? // value: true / false. $this->inline = $options['inline']; $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content ); // Store cdn url. $this->cdn_url = $options['cdn_url']; // Store data: URIs setting for later use. $this->datauris = $options['datauris']; // noptimize me. $this->content = $this->hide_noptimize( $this->content ); // Exclude (no)script, as those may contain CSS which should be left as is. $this->content = $this->replace_contents_with_marker_if_exists( 'SCRIPT', '#is', $this->content ); // Save IE hacks. $this->content = $this->hide_iehacks( $this->content ); // Hide HTML comments. $this->content = $this->hide_comments( $this->content ); // Get )|(]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) { foreach ( $matches[0] as $tag ) { if ( $this->isremovable( $tag, $this->cssremovables ) ) { $this->content = str_replace( $tag, '', $this->content ); } elseif ( $this->ismovable( $tag ) ) { // Get the media. if ( false !== strpos( $tag, 'media=' ) ) { preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias ); $medias = explode( ',', $medias[1] ); $media = array(); foreach ( $medias as $elem ) { /* $media[] = current(explode(' ',trim($elem),2)); */ if ( empty( $elem ) ) { $elem = 'all'; } $media[] = $elem; } } else { // No media specified - applies to all. $media = array( 'all' ); } $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag ); if ( preg_match( '#. $url = current( explode( '?', $source[2], 2 ) ); $path = $this->getpath( $url ); if ( false !== $path && preg_match( '#\.css$#', $path ) ) { // Good link. $this->css[] = array( $media, $path ); } else { // Link is dynamic (.php etc). $tag = ''; } } else { // Inline css in style tags can be wrapped in comment tags, so restore comments. $tag = $this->restore_comments( $tag ); preg_match( '#(.*)#Usmi', $tag, $code ); // And re-hide them to be able to to the removal based on tag. $tag = $this->hide_comments( $tag ); if ( $this->include_inline ) { $code = preg_replace( '#^.*.*$#sm', '$1', $code[1] ); $this->css[] = array( $media, 'INLINE;' . $code ); } else { $tag = ''; } } // Remove the original style tag. $this->content = str_replace( $tag, '', $this->content ); } else { // Excluded CSS, minify if getpath and filter says so... if ( preg_match( '#getpath( $url ); if ( $path && apply_filters( 'autoptimize_filter_css_minify_excluded', true, $url ) ) { $minified_url = $this->minify_single( $path ); if ( ! empty( $minified_url ) ) { // Replace orig URL with cached minified URL. $new_tag = str_replace( $url, $minified_url, $tag ); } else { $new_tag = $tag; } // Defer single CSS if "inline & defer" is ON and there is inline CSS. if ( $this->defer && ! empty( $this->defer_inline ) ) { // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS. $_preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'", $url ); // Adapt original element for CSS to be preloaded and add