Skip to content

Commit

Permalink
3.15.5 (PR #6283)
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan authored Nov 23, 2023
2 parents cb55163 + 89d66aa commit 83c269c
Show file tree
Hide file tree
Showing 144 changed files with 2,010 additions and 318 deletions.
2 changes: 1 addition & 1 deletion dynamic-lists-delayjs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inc/3rd-party/hosting/pagely.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ function rocket_clean_pagely() {
$purger->purgeAll();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_pagely' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_pagely' );
2 changes: 1 addition & 1 deletion inc/3rd-party/hosting/siteground.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function rocket_sg_clear_cache() {

if ( rocket_is_supercacher_active() ) {
add_action( 'admin_post_sg-cachepress-purge', 'rocket_sg_clear_cache', 0 );
add_action( 'after_rocket_clean_domain', 'rocket_clean_supercacher' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_supercacher' );
add_filter( 'rocket_display_varnish_options_tab', '__return_false' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/i18n/polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function rocket_force_clean_domain_on_polylang() {
rocket_clean_cache_dir();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_force_clean_domain_on_polylang' );
add_action( 'rocket_after_clean_domain', 'rocket_force_clean_domain_on_polylang' );

// Filter mandatory cookies and WP Rocket rewrite rules if Polylang module 'Detect browser language' is enabled.
if ( function_exists( 'PLL' ) && PLL()->options['browser'] ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/nginx-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function rocket_clean_nginx_helper_cache() {

do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_nginx_helper_cache' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_nginx_helper_cache' );

/**
* Clean the NGINX cache after the Used CSS has been generated.
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/varnish-http-purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function rocket_clear_cache_after_varnish_http_purge() {
}
endif;

add_action( 'after_rocket_clean_domain', 'rocket_clean_varnish_http_purge' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_varnish_http_purge' );
/**
* Call the cache server to purge the cache with Varnish HTTP Purge.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/themes/studiopress.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function rocket_clear_cache_after_studiopress_accelerator() {
}
}

add_action( 'after_rocket_clean_domain', 'rocket_clean_studiopress_accelerator' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_studiopress_accelerator' );
/**
* Call the cache server to purge the cache with StudioPress Accelerator.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/Addon/Cloudflare/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function get_subscribed_events() {
'rocket_varnish_ip' => 'set_varnish_localhost',
'rocket_varnish_purge_request_host' => 'set_varnish_purge_request_host',
'rocket_cron_deactivate_cloudflare_devmode' => 'deactivate_devmode',
'after_rocket_clean_domain' => 'auto_purge',
'rocket_after_clean_domain' => 'auto_purge',
'after_rocket_clean_post' => [ 'auto_purge_by_url', 10, 3 ],
'admin_post_rocket_purge_cloudflare' => 'purge_cache',
'init' => [ 'set_real_ip', 1 ],
Expand Down
2 changes: 1 addition & 1 deletion inc/Addon/Sucuri/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct( Options_Data $options ) {
*/
public static function get_subscribed_events() {
return [
'after_rocket_clean_domain' => 'maybe_clean_firewall_cache',
'rocket_after_clean_domain' => 'maybe_clean_firewall_cache',
'after_rocket_clean_post' => 'maybe_clean_firewall_cache',
'after_rocket_clean_term' => 'maybe_clean_firewall_cache',
'after_rocket_clean_user' => 'maybe_clean_firewall_cache',
Expand Down
5 changes: 5 additions & 0 deletions inc/Engine/Cache/PurgeActionsSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace WP_Rocket\Engine\Cache;

use WP_Post;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Logger\Logger;
Expand Down Expand Up @@ -88,6 +89,10 @@ public function purge_user_cache( $user_id ) {
* @return void
*/
public function maybe_purge_cache_on_term_change( $term_id, $tt_id, $taxonomy ) {
if ( rocket_is_importing() ) {
return;
}

if ( ! $this->is_taxonomy_public( $taxonomy ) ) {
return;
}
Expand Down
27 changes: 27 additions & 0 deletions inc/Engine/Common/Clock/ClockInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WP_Rocket\Engine\Common\Clock;

interface ClockInterface {
/**
* Retrieves the current time based on specified type.
*
* - The 'mysql' type will return the time in the format for MySQL DATETIME field.
* - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp
* and timezone offset, depending on `$gmt`.
* - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If `$gmt` is a truthy value then both types will use GMT time, otherwise the
* output is adjusted with the GMT offset for the site.
*
* @since 1.0.0
* @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned.
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U',
* or PHP date format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
*
* @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
*/
public function current_time( string $type, $gmt = 0 );
}
35 changes: 35 additions & 0 deletions inc/Engine/Common/Clock/WPRClock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace WP_Rocket\Engine\Common\Clock;

class WPRClock implements ClockInterface {

/**
* Retrieves the current time based on specified type.
*
* - The 'mysql' type will return the time in the format for MySQL DATETIME field.
* - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp
* and timezone offset, depending on `$gmt`.
* - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
*
* If `$gmt` is a truthy value then both types will use GMT time, otherwise the
* output is adjusted with the GMT offset for the site.
*
* @since 1.0.0
* @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned.
*
* @param string $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U',
* or PHP date format string (e.g. 'Y-m-d').
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default false.
*
* @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
*/
public function current_time( string $type, $gmt = 0 ) {
$current_time = current_time( $type, $gmt );
$output = apply_filters( 'rocket_current_time', $current_time );
if ( ( is_string( $current_time ) && strtotime( $current_time ) ) || ( is_int( $current_time ) && $current_time >= 0 ) ) {
return $output;
}
return $current_time;
}
}
2 changes: 1 addition & 1 deletion inc/Engine/Media/Lazyload/CSS/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function get_subscribed_events() {
[ 'add_lazy_tag', 24 ],
],
'rocket_buffer' => [ 'maybe_replace_css_images', 1002 ],
'after_rocket_clean_domain' => 'clear_generated_css',
'rocket_after_clean_domain' => 'clear_generated_css',
'wp_enqueue_scripts' => 'insert_lazyload_script',
'rocket_css_image_lazyload_images_load' => [ 'exclude_rocket_lazyload_excluded_src', 10, 2 ],
'rocket_lazyload_css_ignored_urls' => 'remove_svg_from_lazyload_css',
Expand Down
11 changes: 11 additions & 0 deletions inc/Engine/Optimization/DynamicLists/DynamicLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,15 @@ public function get_incompatible_plugins() {

return isset( $lists ) ? $lists : [];
}

/**
* Get the staging list
*
* @return array
*/
public function get_stagings(): array {
$lists = $this->providers['defaultlists']->data_manager->get_lists();

return isset( $lists->staging_domains ) ? $lists->staging_domains : [];
}
}
12 changes: 12 additions & 0 deletions inc/Engine/Optimization/DynamicLists/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function get_subscribed_events() {
'rocket_preload_exclude_urls' => 'add_preload_exclusions',
'rocket_exclude_js' => 'add_js_exclude_files',
'rocket_plugins_to_deactivate' => 'add_incompatible_plugins_to_deactivate',
'rocket_staging_list' => 'add_staging_exclusions',
];
}

Expand Down Expand Up @@ -201,4 +202,15 @@ public function add_js_exclude_files( $js_files = [] ): array {
public function add_incompatible_plugins_to_deactivate( $plugins = [] ): array {
return array_merge( (array) $plugins, $this->dynamic_lists->get_incompatible_plugins() );
}

/**
* Add the staging exclusions to the array
*
* @param array $stagings Array of staging urls.
*
* @return array
*/
public function add_staging_exclusions( $stagings = [] ): array {
return array_merge( (array) $stagings, (array) $this->dynamic_lists->get_stagings() );
}
}
78 changes: 41 additions & 37 deletions inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace WP_Rocket\Engine\Optimization\RUCSS\Controller;

use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Common\Clock\WPRClock;
use WP_Rocket\Engine\Common\Context\ContextInterface;
use WP_Rocket\Engine\Common\Queue\QueueInterface;
use WP_Rocket\Engine\Optimization\CSSTrait;
Expand All @@ -12,6 +13,7 @@
use WP_Rocket\Engine\Optimization\RUCSS\Database\Queries\UsedCSS as UsedCSS_Query;
use WP_Rocket\Engine\Optimization\RUCSS\Frontend\APIClient;
use WP_Admin_Bar;
use WP_Rocket\Engine\Optimization\RUCSS\Strategy\Factory\StrategyFactory;
use WP_Rocket\Logger\LoggerAware;
use WP_Rocket\Logger\LoggerAwareInterface;

Expand Down Expand Up @@ -97,6 +99,20 @@ class UsedCSS implements LoggerAwareInterface {
*/
private $inline_content_exclusions = [];

/**
* Retry Strategy Factory
*
* @var StrategyFactory
*/
protected $strategy_factory;

/**
* Clock instance.
*
* @var WPRClock
*/
protected $wpr_clock;

/**
* Instantiate the class.
*
Expand All @@ -108,6 +124,8 @@ class UsedCSS implements LoggerAwareInterface {
* @param Filesystem $filesystem Filesystem instance.
* @param ContextInterface $context RUCSS context.
* @param ContextInterface $optimize_url_context RUCSS optimize url context.
* @param StrategyFactory $strategy_factory Strategy Factory used for RUCSS retry process.
* @param WPRClock $clock Clock object instance.
*/
public function __construct(
Options_Data $options,
Expand All @@ -117,7 +135,9 @@ public function __construct(
DataManager $data_manager,
Filesystem $filesystem,
ContextInterface $context,
ContextInterface $optimize_url_context
ContextInterface $optimize_url_context,
StrategyFactory $strategy_factory,
WPRClock $clock
) {
$this->options = $options;
$this->used_css_query = $used_css_query;
Expand All @@ -127,6 +147,8 @@ public function __construct(
$this->filesystem = $filesystem;
$this->context = $context;
$this->optimize_url_context = $optimize_url_context;
$this->strategy_factory = $strategy_factory;
$this->wpr_clock = $clock;
}

/**
Expand Down Expand Up @@ -500,12 +522,14 @@ public function process_pending_jobs() {
}

foreach ( $pending_jobs as $used_css_row ) {
$this->logger::debug( "RUCSS: Send the job for url {$used_css_row->url} to Async task to check its job status." );

// Change status to in-progress.
$this->used_css_query->make_status_inprogress( (int) $used_css_row->id );
$current_time = $this->wpr_clock->current_time( 'timestamp', true );
if ( strtotime( $used_css_row->next_retry_time ) < $current_time ) {
$this->logger::debug( "RUCSS: Send the job for url {$used_css_row->url} to Async task to check its job status." );

$this->queue->add_job_status_check_async( (int) $used_css_row->id );
// Change status to in-progress.
$this->used_css_query->make_status_inprogress( (int) $used_css_row->id );
$this->queue->add_job_status_check_async( (int) $used_css_row->id );
}
}
}

Expand All @@ -518,6 +542,7 @@ public function process_pending_jobs() {
*/
public function check_job_status( int $id ) {
$this->logger::debug( 'RUCSS: Start checking job status for row ID: ' . $id );

$row_details = $this->used_css_query->get_item( $id );
if ( ! $row_details ) {
$this->logger::debug( 'RUCSS: Row ID not found ', compact( 'id' ) );
Expand Down Expand Up @@ -550,39 +575,9 @@ public function check_job_status( int $id ) {

if (
200 !== (int) $job_details['code']
||
empty( $job_details['contents'] )
||
! isset( $job_details['contents']['shakedCSS'] )
) {
$this->logger::debug( 'RUCSS: Job status failed for url: ' . $row_details->url, $job_details );

// Failure, check the retries number.
if ( $row_details->retries >= 3 ) {
$this->logger::debug( 'RUCSS: Job failed 3 times for url: ' . $row_details->url );
/**
* Unlock preload URL.
*
* @param string $url URL to unlock
*/
do_action( 'rocket_preload_unlock_url', $row_details->url );

$this->used_css_query->make_status_failed( $id, strval( $job_details['code'] ), $job_details['message'] );

return;
}

// on timeout errors with code 408 create new job.
switch ( $job_details['code'] ) {
case 408:
$this->add_url_to_the_queue( $row_details->url, (bool) $row_details->is_mobile );
return;
}

// Increment the retries number with 1 , Change status to pending again and change job id on timeout.
$this->used_css_query->increment_retries( $id, (int) $job_details['code'], $job_details['message'] );

// @Todo: Maybe we can add this row to the async job to get the status before the next cron
$this->strategy_factory->manage( $row_details, $job_details );

return;
}
Expand Down Expand Up @@ -992,6 +987,13 @@ public function has_one_completed_row_at_least() {
* @return void
*/
public function process_on_submit_jobs() {

if ( ! $this->is_enabled() ) {
$this->logger::debug( 'RUCSS: Stop processing cron iteration because option is disabled.' );

return;
}

/**
* Pending rows cont.
*
Expand All @@ -1010,6 +1012,8 @@ public function process_on_submit_jobs() {
foreach ( $rows as $row ) {
$response = $this->send_api( $row->url, (bool) $row->is_mobile );
if ( false === $response || ! isset( $response['contents'], $response['contents']['jobId'], $response['contents']['queueName'] ) ) {

$this->used_css_query->make_status_failed( (int) $row->id, '', '' );
continue;
}

Expand Down
Loading

0 comments on commit 83c269c

Please sign in to comment.