Skip to content

Commit

Permalink
Merge pull request #663 from wp-media/branch-2.11.2
Browse files Browse the repository at this point in the history
2.11.2
  • Loading branch information
remyperona authored Dec 18, 2017
2 parents 1647d10 + 42eb2d6 commit 4a98450
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 141 deletions.
2 changes: 1 addition & 1 deletion inc/admin/ui/modules/cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$rocket_do_cloudflare_settings[] = array(
'type' => 'helper_warning',
'name' => 'rocket_cloudflare_warning',
'description' => __( 'Your PHP version is lower than 5.4. Cloudflare’s integration requires PHP 5.4 or greater and therefore is not available for you currently. We recommend you contact your web host in order to upgrade to a PHP 5.6 or greater.', 'rocket' ),
'description' => __( 'Your PHP version is lower than 5.4. Cloudflare’s integration requires PHP 5.4 or greater and therefore is not available for you currently. We recommend you contact your web host in order to upgrade to the latest PHP version.', 'rocket' ),
);
}

Expand Down
35 changes: 30 additions & 5 deletions inc/admin/upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function rocket_upgrader() {

rocket_renew_all_boxes( 0, array( 'rocket_warning_plugin_modification' ) );

$options = get_option( WP_ROCKET_SLUG ); // do not use get_rocket_option() here.
$options = get_option( WP_ROCKET_SLUG ); // do not use get_rocket_option() here.
$options['version'] = WP_ROCKET_VERSION;

$keys = rocket_check_key();
Expand Down Expand Up @@ -60,11 +60,11 @@ function rocket_first_install() {

// Generate an random key for minify md5 filename.
$minify_css_key = create_rocket_uniqid();
$minify_js_key = create_rocket_uniqid();
$minify_js_key = create_rocket_uniqid();

// Create Option.
add_option(
WP_ROCKET_SLUG,
WP_ROCKET_SLUG,
/**
* Filters the default rocket options array
*
Expand Down Expand Up @@ -210,10 +210,10 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
}

// Add a value to the new CF zone_id field if the CF domain is set.
if ( version_compare( $actual_version, '2.8.21', '<' ) && phpversion() >= '5.4' ) {
if ( version_compare( $actual_version, '2.8.21', '<' ) && version_compare( phpversion(), '5.4' ) >= 0 ) {
$options = get_option( WP_ROCKET_SLUG );
if ( 0 < $options['do_cloudflare'] && '' !== $options['cloudflare_domain'] ) {
require( WP_ROCKET_ADMIN_PATH . 'compat/cf-upgrader-5.4.php' );
require WP_ROCKET_ADMIN_PATH . 'compat/cf-upgrader-5.4.php';
}
}

Expand Down Expand Up @@ -248,5 +248,30 @@ function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
rocket_clean_cache_busting();
rocket_generate_advanced_cache_file();
}

if ( version_compare( $actual_version, '2.11.2', '<' ) ) {
$options = get_option( WP_ROCKET_SLUG );
$options = is_array( $options ) ? $options : array();
$update = false;

if ( ! isset( $options['wl_plugin_URI'] ) || 'http://www.wp-rocket.me' === $options['wl_plugin_URI'] ) {
$options['wl_plugin_URI'] = 'https://wp-rocket.me';
$update = true;
}

if ( ! isset( $options['wl_author'] ) || 'WP Rocket' === $options['wl_author'] ) {
$options['wl_author'] = 'WP Media';
$update = true;
}

if ( ! isset( $options['wl_author_URI'] ) || 'http://www.wp-rocket.me' === $options['wl_author_URI'] ) {
$options['wl_author_URI'] = 'https://wp-media.me';
$update = true;
}

if ( $update ) {
update_option( WP_ROCKET_SLUG, $options );
}
}
}
add_action( 'wp_rocket_upgrade', 'rocket_new_upgrade', 10, 2 );
25 changes: 19 additions & 6 deletions inc/classes/class-rocket-critical-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ public function init() {
*/
public function process_handler() {
$this->clean_critical_css();
$this->process->cancel_process();

if ( method_exists( $this->process, 'cancel_process' ) ) {
$this->process->cancel_process();
}

$this->set_items();

foreach ( $this->items as $item ) {
Expand Down Expand Up @@ -172,7 +176,10 @@ public function generate_critical_css_on_activation( $old_value, $value ) {
*/
public function stop_process_on_deactivation( $old_value, $value ) {
if ( ! empty( $_POST[ WP_ROCKET_SLUG ] ) && isset( $old_value['async_css'], $value['async_css'] ) && ( $old_value['async_css'] !== $value['async_css'] ) && 0 === (int) $value['async_css'] ) {
$this->process->cancel_process();
if ( method_exists( $this->process, 'cancel_process' ) ) {
$this->process->cancel_process();
}

delete_transient( 'rocket_critical_css_generation_process_running' );
delete_transient( 'rocket_critical_css_generation_process_complete' );
}
Expand Down Expand Up @@ -536,7 +543,7 @@ public function async_css( $buffer ) {
$onload = str_replace( $tags_match[3][ $i ], ' as="style" onload=""' . $tags_match[3][ $i ] . '>', $tags_match[3][ $i ] );
$tag = str_replace( $tags_match[3][ $i ] . '>', $onload, $tag );
$tag = str_replace( $tags_match[1][ $i ], $preload, $tag );
$tag = str_replace( 'onload=""', 'onload="this.rel=\'stylesheet\'"', $tag );
$tag = str_replace( 'onload=""', 'onload="this.onload=null;this.rel=\'stylesheet\'"', $tag );
$buffer = str_replace( $tags_match[0][ $i ], $tag, $buffer );

$noscripts .= '<noscript>' . $tags_match[0][ $i ] . '</noscript>';
Expand Down Expand Up @@ -619,6 +626,7 @@ public function insert_critical_css() {
/**
* Insert loadCSS script in <head>
*
* @since 2.11.2 Updated loadCSS rel=preload polyfill to version 2.0.1
* @since 2.10
* @author Remy Perona
*/
Expand Down Expand Up @@ -671,10 +679,15 @@ public function insert_load_css() {

echo <<<JS
<script>
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
!function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
/*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
!function(a){if(a.loadCSS){var b=loadCSS.relpreload={};if(b.support=function(){try{return a.document.createElement("link").relList.supports("preload")}catch(b){return!1}},b.poly=function(){for(var b=a.document.getElementsByTagName("link"),c=0;c<b.length;c++){var d=b[c];"preload"===d.rel&&"style"===d.getAttribute("as")&&(a.loadCSS(d.href,d,d.getAttribute("media")),d.rel=null)}},!b.support()){b.poly();var c=a.setInterval(b.poly,300);a.addEventListener&&a.addEventListener("load",function(){b.poly(),a.clearInterval(c)}),a.attachEvent&&a.attachEvent("onload",function(){a.clearInterval(c)})}}}(this);
(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<links.length;i++){var link=links[i];if(link.rel==="preload"&&link.getAttribute("as")==="style"&&!link.getAttribute("data-loadcss")){link.setAttribute("data-loadcss",!0);rp.bindMediaToggle(link)}}};if(!rp.support()){rp.poly();var run=w.setInterval(rp.poly,500);if(w.addEventListener){w.addEventListener("load",function(){rp.poly();w.clearInterval(run)})}else if(w.attachEvent){w.attachEvent("onload",function(){rp.poly();w.clearInterval(run)})}}
if(typeof exports!=="undefined"){exports.loadCSS=loadCSS}
else{w.loadCSS=loadCSS}}(typeof global!=="undefined"?global:this))
</script>
JS;
}
Expand Down
9 changes: 6 additions & 3 deletions inc/classes/class-rocket-database-optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct() {
public static function init() {
$self = new self();

add_action( 'init', array( $self, 'database_optimization_scheduled' ) );
add_action( 'init', array( $self, 'database_optimization_scheduled' ) );
add_action( 'rocket_database_optimization_time_event', array( $self, 'process_handler' ) );
add_action( 'update_option_' . WP_ROCKET_SLUG, array( $self, 'save_optimize' ) );
add_action( 'admin_post_rocket_optimize_database', array( $self, 'optimize' ) );
Expand All @@ -69,7 +69,9 @@ public static function init() {
* @author Remy Perona
*/
public function process_handler() {
$this->process->cancel_process();
if ( method_exists( $this->process, 'cancel_process' ) ) {
$this->process->cancel_process();
}

foreach ( $this->options as $option ) {
if ( get_rocket_option( 'database_' . $option, false ) ) {
Expand Down Expand Up @@ -163,7 +165,7 @@ public function count_cleanup_items( $type ) {
$count = $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE (comment_approved = 'trash' OR comment_approved = 'post-trashed')" );
break;
case 'expired_transients':
$time = isset( $_SERVER['REQUEST_TIME'] ) ? (int) $_SERVER['REQUEST_TIME'] : time();
$time = isset( $_SERVER['REQUEST_TIME'] ) ? (int) $_SERVER['REQUEST_TIME'] : time();
$count = $wpdb->get_var( "SELECT COUNT(option_name) FROM $wpdb->options WHERE option_name LIKE '_transient_timeout%' AND option_value < $time" );
break;
case 'all_transients':
Expand Down Expand Up @@ -259,6 +261,7 @@ public function notice_process_complete() {
* —Kris Kristofferson
*
* We shall do the same, shan’t we?
*
* @todo Replace $k in the printf() arguments with something nicer to read.
*/
?>
Expand Down
34 changes: 27 additions & 7 deletions inc/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ function rocket_insert_deferred_js( $buffer ) {
foreach ( $tags_match[0] as $i => $tag ) {
// Strip query args.
$url = strtok( $tags_match[1][ $i ] , '?' );
$url = strtok( $tags_match[1][ $i ], '?' );
$deferred_js_files = array_flip( get_rocket_deferred_js_files() );
// Check if this file should be deferred.
if ( isset( $deferred_js_files[ $url ] ) ) {
$deferred_tag = str_replace( '></script>', ' defer></script>', $tag );
$buffer = str_replace( $tag, $deferred_tag, $buffer );
$buffer = str_replace( $tag, $deferred_tag, $buffer );
}
}
Expand Down Expand Up @@ -809,7 +809,7 @@ function do_rocket_database_optimization() {
_deprecated_function( __FUNCTION__, '2.11', 'Rocket_Database_Optimisation->process_handler()' );
}

if ( ! function_exists( 'rocket_define_donotminify_constants') ) {
if ( ! function_exists( 'rocket_define_donotminify_constants' ) ) {
/**
* Declare and set value to DONOTMINIFYCSS & DONOTMINIFYJS constant
*
Expand Down Expand Up @@ -870,12 +870,12 @@ function rocket_async_css( $buffer ) {

/**
* Insert critical CSS in the <head>
*
*
* @since 2.10
* @deprecated 2.11
* @see Rocket_Critical_CSS->insert_critical_css()
* @author Remy Perona
*/
* @see Rocket_Critical_CSS->insert_critical_css()
* @author Remy Perona
*/
function rocket_insert_critical_css() {
_deprecated_function( __FUNCTION__, '2.11', 'Rocket_Critical_CSS->insert_critical_css()' );
}
Expand All @@ -891,3 +891,23 @@ function rocket_insert_critical_css() {
function rocket_insert_load_css() {
_deprecated_function( __FUNCTION__, '2.11', 'Rocket_Critical_CSS->insert_load_css()' );
}

if ( ! function_exists( 'rocket_lazyload_async_script' ) ) {
/**
* Add tags to the lazyload script to async and prevent concatenation
*
* @since 2.11
* @deprecated 2.11.2
* @author Remy Perona
*
* @param string $tag HTML for the script.
* @param string $handle Handle for the script.
*
* @return string Updated HTML
*/
function rocket_lazyload_async_script( $tag, $handle ) {
_deprecated_function( __FUNCTION__, '2.11.2' );

return $tag;
}
}
14 changes: 7 additions & 7 deletions inc/front/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function rocket_browser_cache_busting( $src ) {

return get_rocket_browser_cache_busting( $src, $current_filter );
}
add_filter( 'style_loader_src', 'rocket_browser_cache_busting', PHP_INT_MAX );
add_filter( 'style_loader_src', 'rocket_browser_cache_busting', PHP_INT_MAX );
add_filter( 'script_loader_src', 'rocket_browser_cache_busting', PHP_INT_MAX );

/**
Expand Down Expand Up @@ -190,11 +190,11 @@ function rocket_cache_dynamic_resource( $src ) {

switch ( $current_filter ) {
case 'script_loader_src':
$extension = '.js';
$extension = '.js';
$minify_key = get_rocket_option( 'minify_js_key' );
break;
case 'style_loader_src':
$extension = '.css';
$extension = '.css';
$minify_key = get_rocket_option( 'minify_css_key' );
break;
}
Expand All @@ -216,8 +216,8 @@ function rocket_cache_dynamic_resource( $src ) {
return $src;
}

$relative_src = ltrim( $file['path'], '/' );
$abspath_src = rocket_realpath( strtok( $full_src, '?' ), true, $hosts_index );
$relative_src = ltrim( $file['path'], '/' );
$abspath_src = rocket_realpath( strtok( $full_src, '?' ), true, $hosts_index );

/*
* Filters the dynamic resource cache filename
Expand All @@ -227,7 +227,7 @@ function rocket_cache_dynamic_resource( $src ) {
*
* @param string $filename filename for the cache file
*/
$cache_dynamic_resource_filename = apply_filters( 'rocket_dynamic_resource_cache_filename', preg_replace( '/\.(php)$/', '-' . $minify_key . $extension, $relative_src ) );
$cache_dynamic_resource_filename = apply_filters( 'rocket_dynamic_resource_cache_filename', preg_replace( '/\.(php)$/', '-' . $minify_key . '.' . $extension, $relative_src ) );
$cache_busting_paths = rocket_get_cache_busting_paths( $cache_dynamic_resource_filename, $extension );

if ( file_exists( $cache_busting_paths['filepath'] ) && is_readable( $cache_busting_paths['filepath'] ) ) {
Expand All @@ -240,5 +240,5 @@ function rocket_cache_dynamic_resource( $src ) {
return $src;
}
}
add_filter( 'style_loader_src', 'rocket_cache_dynamic_resource', 16 );
add_filter( 'style_loader_src', 'rocket_cache_dynamic_resource', 16 );
add_filter( 'script_loader_src', 'rocket_cache_dynamic_resource', 16 );
Loading

0 comments on commit 4a98450

Please sign in to comment.