Skip to content

Commit

Permalink
Release v3.17.3 (PR #7117)
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan authored Nov 19, 2024
2 parents 4c31774 + 4442d04 commit eda2094
Show file tree
Hide file tree
Showing 33 changed files with 488 additions and 292 deletions.
4 changes: 3 additions & 1 deletion assets/js/wpr-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js.map

Large diffs are not rendered by default.

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.

8 changes: 4 additions & 4 deletions inc/Engine/Admin/Beacon/Beacon.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,12 @@ public function get_suggest( $doc_id ) {
],
'rucss_firewall_ips' => [
'en' => [
'id' => '6076083ff8c0ef2d98df1f97',
'url' => 'https://docs.wp-rocket.me/article/1529-remove-unused-css?utm_source=wp_plugin&utm_medium=wp_rocket#basic-requirements',
'id' => '60ed8bde00fd0d7c253ff547',
'url' => 'https://docs.wp-rocket.me/article/1628-which-ip-do-i-need-to-allow-for-wp-rocket?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '60d499a705ff892e6bc2a89e',
'url' => 'https://fr.docs.wp-rocket.me/article/1577-supprimer-les-ressources-css-inutilisees?utm_source=wp_plugin&utm_medium=wp_rocket#basic-requirements',
'id' => '6246fe1a2ce7ed0fb091c543',
'url' => 'https://fr.docs.wp-rocket.me/article/1690-quelles-adresses-ip-url-autoriser-pour-wp-rocket?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'optimize_critical_images' => [
Expand Down
26 changes: 9 additions & 17 deletions inc/Engine/Admin/Database/Optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,13 @@ class Optimization {
*/
protected $process;

/**
* Array of option name/label pairs.
*
* @var array
*/
private $options;

/**
* Class constructor.
*
* @param OptimizationProcess $process Background process instance.
*/
public function __construct( OptimizationProcess $process ) {
$this->process = $process;
$this->options = [
'database_revisions' => __( 'Revisions', 'rocket' ),
'database_auto_drafts' => __( 'Auto Drafts', 'rocket' ),
'database_trashed_posts' => __( 'Trashed Posts', 'rocket' ),
'database_spam_comments' => __( 'Spam Comments', 'rocket' ),
'database_trashed_comments' => __( 'Trashed Comments', 'rocket' ),
'database_all_transients' => __( 'Transients', 'rocket' ),
'database_optimize_tables' => __( 'Tables', 'rocket' ),
];
}

/**
Expand All @@ -45,7 +29,15 @@ public function __construct( OptimizationProcess $process ) {
* @return array
*/
public function get_options() {
return $this->options;
return [
'database_revisions' => __( 'Revisions', 'rocket' ),
'database_auto_drafts' => __( 'Auto Drafts', 'rocket' ),
'database_trashed_posts' => __( 'Trashed Posts', 'rocket' ),
'database_spam_comments' => __( 'Spam Comments', 'rocket' ),
'database_trashed_comments' => __( 'Trashed Comments', 'rocket' ),
'database_all_transients' => __( 'Transients', 'rocket' ),
'database_optimize_tables' => __( 'Tables', 'rocket' ),
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private function assets_section() {
'sanitize_callback' => 'sanitize_checkbox',
'options' => [
'remove_unused_css' => [
'label' => __( 'Remove Unused CSS (RUCSS)', 'rocket' ),
'label' => __( 'Remove Unused CSS', 'rocket' ),
'disabled' => $invalid_license || $rucss_status['disable'] ? 'disabled' : false,
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
'description' => sprintf( __( 'Removes unused CSS per page and helps to reduce page size and HTTP requests. Recommended for best performance. Test thoroughly! %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $rucss_beacon['url'] ) . '" data-beacon-article="' . esc_attr( $rucss_beacon['id'] ) . '" target="_blank">', '</a>' ),
Expand Down
60 changes: 59 additions & 1 deletion inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace WP_Rocket\Engine\CDN\RocketCDN;

use WP_Rocket\Admin\Options;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Optimization\RegexTrait;
use WP_Rocket\Event_Management\Subscriber_Interface;

/**
Expand All @@ -9,6 +12,8 @@
* @since 3.5
*/
class DataManagerSubscriber implements Subscriber_Interface {
use RegexTrait;

const CRON_EVENT = 'rocketcdn_check_subscription_status_event';

/**
Expand All @@ -25,15 +30,33 @@ class DataManagerSubscriber implements Subscriber_Interface {
*/
private $cdn_options;

/**
* WP Options API instance
*
* @var Options
*/
private $options_api;

/**
* WP Rocket Options instance
*
* @var Options_Data
*/
private $options;

/**
* Constructor
*
* @param APIClient $api_client RocketCDN API Client instance.
* @param CDNOptionsManager $cdn_options CDNOptionsManager instance.
* @param Options_Data $options Options instance.
* @param Options $options_api Options API instance.
*/
public function __construct( APIClient $api_client, CDNOptionsManager $cdn_options ) {
public function __construct( APIClient $api_client, CDNOptionsManager $cdn_options, Options_Data $options, Options $options_api ) {
$this->api_client = $api_client;
$this->cdn_options = $cdn_options;
$this->options = $options;
$this->options_api = $options_api;
}

/**
Expand All @@ -48,6 +71,7 @@ public static function get_subscribed_events() {
'wp_ajax_rocketcdn_process_status' => 'get_process_status',
'wp_ajax_rocketcdn_validate_token_cname' => 'validate_token_cname',
self::CRON_EVENT => 'maybe_disable_cdn',
'wp_rocket_upgrade' => [ 'refresh_cdn_cname', 10, 2 ],
];
}

Expand Down Expand Up @@ -315,4 +339,38 @@ private function schedule_subscription_check( $subscription ) {
wp_schedule_single_event( $timestamp, self::CRON_EVENT );
}
}

/**
* Upgrade callback.
*
* @param string $new_version Plugin new version.
* @param string $old_version Plugin old version.
* @return void
*/
public function refresh_cdn_cname( $new_version, $old_version ): void {
if ( version_compare( $old_version, '3.17.3', '>=' ) ) {
return;
}

$cdn_cnames = $this->options->get( 'cdn_cnames', [] );
if ( empty( $cdn_cnames ) ) {
return;
}

$subscription_data = $this->api_client->get_subscription_data();
if ( ! $subscription_data['is_active'] || empty( $subscription_data['cdn_url'] ) ) {
return;
}

$cdn_matches = $this->find( 'https:\/\/(?<cdn_id>[a-zA-Z0-9]{8})\.rocketcdn\.me', $cdn_cnames[0] );
if ( empty( $cdn_matches ) || empty( $cdn_matches[0]['cdn_id'] ) ) {
return;
}

$this->options_api->set( 'rocketcdn_old_url', $cdn_cnames[0] );
$cdn_cnames[0] = str_replace( $cdn_matches[0]['cdn_id'], $cdn_matches[0]['cdn_id'] . '.delivery', $cdn_cnames[0] );
$this->options->set( 'cdn_cnames', $cdn_cnames );

$this->options_api->set( 'settings', $this->options->get_options() );
}
}
57 changes: 57 additions & 0 deletions inc/Engine/CDN/RocketCDN/NoticesSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function get_subscribed_events() {
'admin_notices' => [
[ 'promote_rocketcdn_notice' ],
[ 'purge_cache_notice' ],
[ 'change_cname_notice' ],
],
'rocket_before_cdn_sections' => 'display_rocketcdn_cta',
'wp_ajax_toggle_rocketcdn_cta' => 'toggle_cta',
Expand Down Expand Up @@ -353,4 +354,60 @@ public function purge_cache_notice() {
private function is_white_label_account() {
return (bool) rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' );
}

/**
* Change CName admin notice contents.
*
* @return void
*/
public function change_cname_notice() {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}

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

$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );

if ( in_array( 'rocketcdn_change_cname', (array) $boxes, true ) ) {
return;
}

$old_cname = get_option( 'wp_rocket_rocketcdn_old_url' );
if ( empty( $old_cname ) ) {
return;
}

$new_subscription = $this->api_client->get_subscription_data();
if ( empty( $new_subscription['cdn_url'] ) || $old_cname === $new_subscription['cdn_url'] ) {
return;
}

$support_url = rocket_get_external_url(
'support',
[
'utm_source' => 'wp_plugin',
'utm_medium' => 'wp_rocket',
]
);

$message_lines = [
// translators: %1$s = Old CName, %2$s = New CName.
sprintf( esc_html__( 'We\'ve updated your RocketCDN CNAME from %1$s to %2$s.', 'rocket' ), $old_cname, $new_subscription['cdn_url'] ),
// translators: %1$s = New CName.
sprintf( esc_html__( 'The change is already applied to the plugin settings. If you were using the CNAME in your code, make sure to update it to: %1$s.', 'rocket' ), $new_subscription['cdn_url'] ),
];

rocket_notice_html(
[
'status' => 'info',
'message' => implode( '<br>', $message_lines ),
'dismiss_button' => 'rocketcdn_change_cname',
'id' => 'rocketcdn_change_cname_notice',
'action' => sprintf( '<a href="%1$s" target="_blank" rel="noopener" class="wpr-button" id="rocketcdn-change-cname-button">%2$s</a>', $support_url, esc_html__( 'contact support', 'rocket' ) ),
]
);
}
}
4 changes: 3 additions & 1 deletion inc/Engine/CDN/RocketCDN/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function register(): void {
// RocketCDN Data manager subscriber.
$this->getContainer()->addShared( 'rocketcdn_data_manager_subscriber', DataManagerSubscriber::class )
->addArgument( $this->getContainer()->get( 'rocketcdn_api_client' ) )
->addArgument( $this->getContainer()->get( 'rocketcdn_options_manager' ) );
->addArgument( $this->getContainer()->get( 'rocketcdn_options_manager' ) )
->addArgument( $this->getContainer()->get( 'options' ) )
->addArgument( $this->getContainer()->get( 'options_api' ) );
// RocketCDN REST API Subscriber.
$this->getContainer()->addShared( 'rocketcdn_rest_subscriber', RESTSubscriber::class )
->addArgument( $this->getContainer()->get( 'rocketcdn_options_manager' ) )
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Cache/TaxonomySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ private function is_not_valid_taxonomy_page() {
$term_link = trailingslashit( $term_link ) . 'page/' . get_query_var( 'paged' );
}

return untrailingslashit( $term_link ) !== untrailingslashit( $current_link );
return urldecode( untrailingslashit( $term_link ) ) !== urldecode( untrailingslashit( $current_link ) );
}
}
12 changes: 2 additions & 10 deletions inc/Engine/HealthCheck/HealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ class HealthCheck implements Subscriber_Interface {
*/
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();
}

/**
Expand All @@ -53,9 +45,9 @@ public function missed_cron() {

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

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

if (
Expand Down
14 changes: 14 additions & 0 deletions inc/Engine/Optimization/DynamicLists/AbstractDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,18 @@ private function put_lists_to_file( string $content ): bool {
private function set_lists_cache( $content ) {
set_transient( $this->get_cache_transient_name(), $content, $this->cache_duration );
}

/**
* Removes the lists cache
*
* @return void
*/
public function remove_lists_cache() {
delete_transient( $this->get_cache_transient_name() );
$lists_filepath = $this->get_json_filepath();
if ( ! $this->filesystem->exists( $lists_filepath ) ) {
return;
}
$this->filesystem->delete( $lists_filepath );
}
}
30 changes: 24 additions & 6 deletions inc/Engine/Optimization/DynamicLists/DynamicLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ public function update_lists_from_remote() {
$response = [];
$success = false;
$should_purge = false;
$titles = [
'defaultlists' => __( 'Default Lists', 'rocket' ),
'delayjslists' => __( 'Delay JavaScript Execution Exclusion Lists', 'rocket' ),
'incompatible_plugins' => __( 'Incompatible plugins Lists', 'rocket' ),
];

foreach ( $this->providers as $provider ) {
foreach ( $this->providers as $provider_id => $provider ) {
$result = $provider->api_client->get_exclusions_list( $provider->data_manager->get_lists_hash() );

if ( empty( $result['code'] ) || empty( $result['body'] ) ) {
$response[ $provider->title ] = [
$response[ $titles[ $provider_id ] ] = [
'success' => false,
'data' => '',
'message' => __( 'Could not get updated lists from server.', 'rocket' ),
Expand All @@ -119,7 +124,7 @@ public function update_lists_from_remote() {
}

if ( 206 === $result['code'] ) {
$response[ $provider->title ] = [
$response[ $titles[ $provider_id ] ] = [
'success' => true,
'data' => '',
'message' => __( 'Lists are up to date.', 'rocket' ),
Expand All @@ -128,16 +133,17 @@ public function update_lists_from_remote() {
}

if ( ! $provider->data_manager->save_dynamic_lists( $result['body'] ) ) {
$response[ $provider->title ] = [
$response[ $titles[ $provider_id ] ] = [
'success' => false,
'data' => '',
'message' => __( 'Could not update lists.', 'rocket' ),
];
continue;
}

$success = true;
$response[ $provider->title ] = [
$success = true;

$response[ $titles[ $provider_id ] ] = [
'success' => true,
'data' => '',
'message' => __( 'Lists are successfully updated.', 'rocket' ),
Expand Down Expand Up @@ -313,4 +319,16 @@ public function get_lrc_exclusions(): array {

return $lists->lazy_rendering_exclusions ?? [];
}

/**
* Updates the lists from JSON files
*
* @return void
*/
public function update_lists_from_files() {
foreach ( $this->providers as $provider ) {
$provider->data_manager->remove_lists_cache();
$provider->data_manager->get_lists();
}
}
}
Loading

0 comments on commit eda2094

Please sign in to comment.