*
* @since 2.11
*/
public function warning_critical_css_dir_permissions() {
if (
current_user_can( 'rocket_manage_options' )
&&
( ! $this->filesystem->is_writable( WP_ROCKET_CRITICAL_CSS_PATH ) )
&&
( $this->options->get( 'async_css', false ) )
&&
rocket_valid_key()
) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = rocket_notice_writing_permissions(
trim( str_replace( ABSPATH, '', WP_ROCKET_CRITICAL_CSS_PATH ), '/' )
);
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
/**
* Insert loadCSS script in
.
*
* @since 2.11.2 Updated loadCSS rel=preload polyfill to version 2.0.1
* @since 2.10
*/
public function insert_load_css() {
if ( ! $this->should_async_css() ) {
return;
}
// This filter is documented in inc/classes/Buffer/class-tests.php.
$rocket_cache_search = apply_filters( 'rocket_cache_search', false );
// Don't apply on search page.
if ( is_search() && ! $rocket_cache_search ) {
return;
}
// Don't apply on 404 page.
if ( is_404() ) {
return;
}
if (
empty( $this->critical_css->get_current_page_critical_css() )
&&
empty( $this->options->get( 'critical_css', '' ) )
) {
return;
}
echo /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view. */ <<
/*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
(function(w){"use strict";if(!w.loadCSS){w.loadCSS=function(){}}
var rp=loadCSS.relpreload={};rp.support=(function(){var ret;try{ret=w.document.createElement("link").relList.supports("preload")}catch(e){ret=!1}
return function(){return ret}})();rp.bindMediaToggle=function(link){var finalMedia=link.media||"all";function enableStylesheet(){link.media=finalMedia}
if(link.addEventListener){link.addEventListener("load",enableStylesheet)}else if(link.attachEvent){link.attachEvent("onload",enableStylesheet)}
setTimeout(function(){link.rel="stylesheet";link.media="only x"});setTimeout(enableStylesheet,3000)};rp.poly=function(){if(rp.support()){return}
var links=w.document.getElementsByTagName("link");for(var i=0;i
JS;
}
/**
* Insert critical CSS before combined CSS when option is active.
*
* @since 2.11.5
*
* @param string $buffer HTML output of the page.
*
* @return string Updated HTML output
*/
public function insert_critical_css_buffer( $buffer ) {
if ( ! $this->should_async_css() ) {
return $buffer;
}
$critical_css_content = $this->critical_css->get_critical_css_content();
if ( empty( $critical_css_content ) ) {
return $buffer;
}
$critical_css_content = str_replace( '\\', '\\\\', $critical_css_content );
$buffer = preg_replace(
'##iU',
'',
$buffer,
1
);
return preg_replace( '##iU', $this->return_remove_cpcss_script() . '