Skip to content

Commit

Permalink
3.5.4 (PR #2575)
Browse files Browse the repository at this point in the history
- Enhancement: Add additional exclusions from combine JavaScript (#2472, #2521)
- Bugfix: Correctly rewrite assets URLs inside CSS files when updating the CDN or cnames options values (#2425)
- Bugfix: Prevent false positives when displaying our cron status notice (#2211)
- Bugfix: Prevent some folders from being deleted when clearing the cache on an installation where the domain name is part of the absolute path to the website (#2571, #2574)
  • Loading branch information
Tabrisrp committed Apr 23, 2020
2 parents 93fd3ac + 14f6669 commit adab7a8
Show file tree
Hide file tree
Showing 45 changed files with 3,440 additions and 1,566 deletions.
149 changes: 149 additions & 0 deletions inc/Engine/Admin/HealthCheck.php
@@ -0,0 +1,149 @@
<?php

namespace WP_Rocket\Engine\Admin;

use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;

class HealthCheck implements Subscriber_Interface {
/**
* Instance of options.
*
* @var Options_Data
*/
private $options;

/**
* Array of events with their descriptions.
*
* @var array
*/
private $events;

/**
* Creates an instance of the health checker.
*
* @param Options_Data $options Options_Data instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
$this->events = $this->get_events();
}

/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_notices' => 'missed_cron',
];
}

/**
* Display a warning notice if WP Rocket scheduled events are not running properly.
*
* @since 3.5.4
*/
public function missed_cron() {
if ( ! $this->should_check() ) {
return;
}

$delay = rocket_get_constant( 'DISABLE_WP_CRON' ) ? HOUR_IN_SECONDS : 5 * MINUTE_IN_SECONDS;
$list = '';
$events = $this->events;

foreach ( $this->events as $event => $description ) {
$timestamp = wp_next_scheduled( $event );

if (
false === $timestamp
||
( $timestamp + $delay - time() ) > 0
) {
unset( $events[ $event ] );
continue;
}

$list .= "<li>{$description}</li>";
}

if ( empty( $events ) ) {
return;
}

$message = sprintf(
'<p>%1$s</p>
<ul>%2$s</ul>
<p>%3$s</p>',
_n(
'The following scheduled event failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:',
'The following scheduled events failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:',
count( $events ),
'rocket'
),
$list,
__( 'Please contact your host to check if CRON is working.', 'rocket' )
);

rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'message' => $message,
'dismiss_button' => 'rocket_warning_cron',
]
);
}

/**
* Checks if health check should run.
*
* @since 3.5.4
*
* @return bool true when should do health check; else, false.
*/
protected function should_check() {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return false;
}

if ( 'settings_page_wprocket' !== get_current_screen()->id ) {
return false;
}

$dismissed = (array) get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( 'rocket_warning_cron', $dismissed, true ) ) {
return false;
}

return ! (
0 === (int) $this->options->get( 'purge_cron_interval', 0 )
&&
0 === (int) $this->options->get( 'async_css', 0 )
&&
0 === (int) $this->options->get( 'manual_preload', 0 )
&&
0 === (int) $this->options->get( 'schedule_automatic_cleanup', 0 )
);
}

/**
* Gets an array of events with their descriptions.
*
* @since 3.5.4
*
* @return array array of events => descriptions.
*/
protected function get_events() {
return [
'rocket_purge_time_event' => __( 'Scheduled Cache Purge', 'rocket' ),
'rocket_database_optimization_time_event' => __( 'Scheduled Database Optimization', 'rocket' ),
'rocket_database_optimization_cron_interval' => __( 'Database Optimization Process', 'rocket' ),
'rocket_preload_cron_interval' => _x( 'Preload', 'noun', 'rocket' ),
'rocket_critical_css_generation_cron_interval' => __( 'Critical Path CSS Generation Process', 'rocket' ),
];
}
}
3 changes: 3 additions & 0 deletions inc/Engine/Admin/ServiceProvider.php
Expand Up @@ -25,6 +25,7 @@ class ServiceProvider extends AbstractServiceProvider {
'deactivation_intent_render',
'deactivation_intent_subscriber',
'hummingbird_subscriber',
'health_check',
];

/**
Expand All @@ -48,5 +49,7 @@ public function register() {
->withArgument( $options );
$this->getContainer()->share( 'hummingbird_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Optimization\Hummingbird_Subscriber' )
->withArgument( $options );
$this->getContainer()->share( 'health_check', 'WP_Rocket\Engine\Admin\HealthCheck' )
->withArgument( $options );
}
}
36 changes: 36 additions & 0 deletions inc/Engine/Optimization/AdminServiceProvider.php
@@ -0,0 +1,36 @@
<?php
namespace WP_Rocket\Engine\Optimization;

use League\Container\ServiceProvider\AbstractServiceProvider;

/**
* Service provider for the WP Rocket optimizations
*
* @since 3.5.3
*/
class AdminServiceProvider extends AbstractServiceProvider {

/**
* The provides array is a way to let the container
* know that a service is provided by this service
* provider. Every service that is registered via
* this service provider must have an alias added
* to this array or it will be ignored.
*
* @var array
*/
protected $provides = [
'minify_css_admin_subscriber',
];

/**
* Registers the option array in the container
*
* @since 3.5.3
*
* @return void
*/
public function register() {
$this->getContainer()->share( 'minify_css_admin_subscriber', 'WP_Rocket\Engine\Optimization\Minify\CSS\AdminSubscriber' );
}
}
125 changes: 125 additions & 0 deletions inc/Engine/Optimization/Minify/CSS/AdminSubscriber.php
@@ -0,0 +1,125 @@
<?php

namespace WP_Rocket\Engine\Optimization\Minify\CSS;

use WP_Rocket\Event_Management\Subscriber_Interface;

/**
* Minify/Combine CSS Admin subscriber
*
* @since 3.5.4
*/
class AdminSubscriber implements Subscriber_Interface {
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.5.4
*
* @return array
*/
public static function get_subscribed_events() {
$slug = rocket_get_constant( 'WP_ROCKET_SLUG', 'wp_rocket_settings' );

return [
"update_option_{$slug}" => [ 'clean_minify', 10, 2 ],
"pre_update_option_{$slug}" => [ 'regenerate_minify_css_key', 10, 2 ],
];
}

/**
* Clean minify CSS files when options change.
*
* @since 3.5.4
*
* @param array $old An array of previous settings.
* @param array $new An array of submitted settings.
*/
public function clean_minify( $old, $new ) {
if ( ! is_array( $old ) || ! is_array( $new ) ) {
return;
}

if ( ! $this->maybe_minify_regenerate( $new, $old ) ) {
return;
}
// Purge all minify cache files.
rocket_clean_minify( 'css' );
}

/**
* Regenerate the minify key if CSS files have been modified.
*
* @since 3.5.4
*
* @param array $new An array of submitted settings.
* @param array $old An array of previous settings.
*
* @return array Updates 'minify_css_key' setting when regenerated; else, original submitted settings.
*/
public function regenerate_minify_css_key( $new, $old ) {
if ( ! is_array( $old ) || ! is_array( $new ) ) {
return $new;
}

if ( ! $this->maybe_minify_regenerate( $new, $old ) ) {
return $new;
}

$new['minify_css_key'] = create_rocket_uniqid();

return $new;
}

/**
* Checks minify CSS condition when options change.
*
* @since 3.5.4
*
* @param array $new An array of submitted settings.
* @param array $old An array of previous settings.
*
* @return bool true when should regenerate; else false.
*/
protected function maybe_minify_regenerate( array $new, array $old ) {
$settings_to_check = [
'minify_css',
'exclude_css',
'cdn',
];

foreach ( $settings_to_check as $setting ) {
if ( $this->did_setting_change( $setting, $new, $old ) ) {
return true;
}
}

return (
array_key_exists( 'cdn', $new )
&&
1 === (int) $new['cdn']
&&
$this->did_setting_change( 'cdn_cnames', $new, $old )
);
}

/**
* Checks if the given setting's value changed.
*
* @since 3.5.4
*
* @param string $setting The settings's value to check in the old and new values.
* @param array $new An array of submitted settings.
* @param array $old An array of previous settings.
*
* @return bool
*/
protected function did_setting_change( $setting, array $new, array $old ) {
return (
array_key_exists( $setting, $old )
&&
array_key_exists( $setting, $new )
&&
$old[ $setting ] !== $new[ $setting ]
);
}
}
6 changes: 6 additions & 0 deletions inc/Engine/Optimization/Minify/JS/Combine.php
Expand Up @@ -634,6 +634,10 @@ protected function get_excluded_inline_content() {
'tarteaucitron',
'pw_brand_product_list',
'tminusCountDown',
'pysWooSelectContentData',
'wpvq_ans89733',
'_isp_version',
'price_range_data',
];

$excluded_inline = array_merge( $defaults, $this->options->get( 'exclude_inline_js', [] ) );
Expand Down Expand Up @@ -722,6 +726,7 @@ protected function get_excluded_external_file_path() {
'cdn.jsdelivr.net/gh/AmauriC/',
'static.klaviyo.com/onsite/js/klaviyo.js',
'a.omappapi.com/app/js/api.min.js',
'static.zdassets.com',
];

$excluded_external = array_merge( $defaults, $this->options->get( 'exclude_js', [] ) );
Expand Down Expand Up @@ -841,6 +846,7 @@ protected function get_move_after_inline_scripts() {
'tdbMenuItem',
'tdbSearchItem',
'best_seller_badge',
'jQuery(\'#product-top-bar',
];

/**
Expand Down

0 comments on commit adab7a8

Please sign in to comment.