Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
45 changed files
with
3,440 additions
and
1,566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.