Skip to content

Commit

Permalink
Release v3.15.4 (PR #6260)
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Nov 6, 2023
2 parents 62f7a3d + 8aa0b8d commit cb55163
Show file tree
Hide file tree
Showing 30 changed files with 534 additions and 245 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
},
"scripts": {
"test-unit": "\"vendor/bin/phpunit\" --testsuite unit --colors=always --configuration tests/Unit/phpunit.xml.dist",
"test-integration": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --exclude-group AdminOnly,BeaverBuilder,Elementor,Hummingbird,WithSmush,WithWoo,WithAmp,WithAmpAndCloudflare,WithSCCSS,Cloudways,Dreampress,Cloudflare,CloudflareAdmin,Multisite,WPEngine,SpinUpWP,WordPressCom,O2Switch,PDFEmbedder,PDFEmbedderPremium,PDFEmbedderSecure,Godaddy,LiteSpeed,RevolutionSlider,WordFence,ConvertPlug,Kinsta,Jetpack,RankMathSEO,AllInOneSeoPack,SEOPress,TheSEOFramework,OneCom,RocketLazyLoad,WPXCloud,TheEventsCalendar,Perfmatters,RapidLoad,ProIsp,TranslatePress,WPGeotargeting,Pressidium",
"test-integration": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --exclude-group AdminOnly,BeaverBuilder,Elementor,Hummingbird,WithSmush,WithWoo,WithAmp,WithAmpAndCloudflare,WithSCCSS,Cloudways,Dreampress,Cloudflare,CloudflareAdmin,Multisite,WPEngine,SpinUpWP,WordPressCom,O2Switch,PDFEmbedder,PDFEmbedderPremium,PDFEmbedderSecure,Godaddy,LiteSpeed,RevolutionSlider,WordFence,ConvertPlug,Kinsta,Jetpack,RankMathSEO,AllInOneSeoPack,SEOPress,TheSEOFramework,OneCom,RocketLazyLoad,WPXCloud,TheEventsCalendar,Perfmatters,RapidLoad,ProIsp,TranslatePress,WPGeotargeting,Weglot,Pressidium",
"test-integration-adminonly": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group AdminOnly",
"test-integration-bb": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group BeaverBuilder",
"test-integration-cloudflare": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group Cloudflare",
Expand Down Expand Up @@ -158,9 +158,9 @@
"test-integration-rapidload": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group RapidLoad",
"test-integration-proisp": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group ProIsp",
"test-integration-wp-geotargeting": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group WPGeotargeting",
"test-integration-translatepress": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group TranslatePress",
"test-integration-pressidium": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group Pressidium",

"test-integration-translatepress": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group TranslatePress",
"test-integration-weglot": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group Weglot",
"test-integration-pressidium": "\"vendor/bin/phpunit\" --testsuite integration --colors=always --configuration tests/Integration/phpunit.xml.dist --group Pressidium",
"run-tests": [
"@test-unit",
"@test-integration",
Expand Down Expand Up @@ -202,7 +202,8 @@
"@test-integration-rapidload",
"@test-integration-proisp",
"@test-integration-wp-geotargeting",
"@test-integration-translatepress",
"@test-integration-translatepress",
"@test-integration-weglot",
"@test-integration-pressidium"
],
"run-stan": "vendor/bin/phpstan analyze --memory-limit=2G --no-progress",
Expand Down
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.

6 changes: 6 additions & 0 deletions inc/Engine/Cache/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ public function purge_url( $url, $pagination = false ) {
}

foreach ( $this->get_iterator( $path ) as $item ) {

if ( $item->isFile() ) {
$this->filesystem->delete( $item->getPathname() );
continue;
}

if ( str_contains( $item->getPathname(), '#' ) ) {
$this->filesystem->delete( $item->getPathname(), true );
}
}

Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/Media/Lazyload/CSS/Front/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function ( $matches ) {
$content
);

$background_regex = '(?<selector>[ \-,:\w.()\n\r^>[*"\'=\]#]+)\s?{[^{}]*background\s*:(?<property>[^;}]*)[^}]*}';
$background_regex = '(?<selector>(?:[ \-,:\w.()\n\r^>[*"\'=\]#]|(?:\[[^\]]+\]))+)\s?{[^{}]*background\s*:(?<property>[^;}]*)[^}]*}';

$background_image_regex = '(?<selector>[ \-,:\w.()\n\r>^[*"\'=\]#]+)\s?{[^{}]*background-image\s*:(?<property>[^;}]*)[^}]*}';
$background_image_regex = '(?<selector>(?:[ \-,:\w.()\n\r^>[*"\'=\]#]|(?:\[[^\]]+\]))+)\s?{[^{}]*background-image\s*:(?<property>[^;}]*)[^}]*}';

/**
* Lazyload background property regex.
Expand Down
14 changes: 10 additions & 4 deletions inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public function check_job_status( int $id ) {
}

if (
200 !== $job_details['code']
200 !== (int) $job_details['code']
||
empty( $job_details['contents'] )
||
Expand Down Expand Up @@ -580,8 +580,7 @@ public function check_job_status( int $id ) {
}

// 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) $row_details->retries );
$this->used_css_query->update_message( $id, $job_details['code'], $job_details['message'], $row_details->error_message );
$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

Expand Down Expand Up @@ -658,7 +657,14 @@ public function add_clear_usedcss_bar_item( WP_Admin_Bar $wp_admin_bar ) {

if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
$referer_url = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
$referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer_url ) );

/**
* Filters to act on the referer url for the admin bar.
*
* @param string $uri Current uri
*/
$referer = (string) apply_filters( 'rocket_admin_bar_referer', esc_url( $referer_url ) );
$referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer ) );
}

/**
Expand Down
58 changes: 28 additions & 30 deletions inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,33 @@ public function get_on_submit_jobs( int $count = 100 ) {
/**
* Increment retries number and change status back to pending.
*
* @param int $id DB row ID.
* @param int $retries Current number of retries.
* @param int $id DB row ID.
* @param int $error_code error code.
* @param string $error_message error message.
*
* @return bool
*/
public function increment_retries( $id, $retries = 0 ) {
public function increment_retries( $id, int $error_code, string $error_message ) {
if ( ! self::$table_exists && ! $this->table_exists() ) {
return false;
}

$old = $this->get_item( $id );

$retries = 0;
$previous_message = '';

if ( $old ) {
$retries = $old->retries;
$previous_message = $old->error_message;
}

$update_data = [
'retries' => $retries + 1,
'status' => 'pending',
'retries' => $retries + 1,
'status' => 'pending',
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
];

return $this->update_item( $id, $update_data );
}

Expand Down Expand Up @@ -219,7 +232,6 @@ public function create_new_job( string $url, string $job_id = '', string $queue_
'status' => 'to-submit',
'retries' => 0,
'last_accessed' => current_time( 'mysql', true ),
'submitted_at' => current_time( 'mysql', true ),
];
return $this->add_item( $item );
}
Expand Down Expand Up @@ -285,12 +297,16 @@ public function make_status_failed( int $id, string $error_code, string $error_m
return false;
}

$old = $this->get_item( $id );

$previous_message = $old ? $old->error_message : '';

return $this->update_item(
$id,
[
'status' => 'failed',
'error_code' => $error_code,
'error_message' => current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$error_code}: {$error_message}",
]
);
}
Expand Down Expand Up @@ -562,25 +578,6 @@ private function table_exists(): bool {
return $exists;
}

/**
* Update the error message.
*
* @param int $job_id Job ID.
* @param int $code Response code.
* @param string $message Response message.
* @param string $previous_message Previous saved message.
*
* @return bool
*/
public function update_message( int $job_id, int $code, string $message, string $previous_message = '' ): bool {
return $this->update_item(
$job_id,
[
'error_message' => $previous_message . ' - ' . current_time( 'mysql', true ) . " {$code}: {$message}",
]
);
}

/**
* Change the status to be pending.
*
Expand All @@ -598,10 +595,11 @@ public function make_status_pending( int $id, string $job_id = '', string $queue
return $this->update_item(
$id,
[
'job_id' => $job_id,
'queue_name' => $queue_name,
'status' => 'pending',
'is_mobile' => $is_mobile,
'job_id' => $job_id,
'queue_name' => $queue_name,
'status' => 'pending',
'is_mobile' => $is_mobile,
'submitted_at' => current_time( 'mysql', true ),
]
);
}
Expand Down
12 changes: 12 additions & 0 deletions inc/Engine/Preload/Controller/CheckExcludedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ protected function is_excluded_by_filter( string $url ): bool {
$url = strtok( $url, '?' );
$url = user_trailingslashit( $url );

/**
* Check if the url is excluded or not.
*
* @param bool $isExcluded Default excluded or not.
* @param string $url URL to check.
*/
$is_excluded = apply_filters( 'rocket_preload_exclude', false, $url );

if ( $is_excluded ) {
return true;
}

/**
* Regex to exclude URI from preload.
*
Expand Down
29 changes: 13 additions & 16 deletions inc/Engine/Preload/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public static function get_subscribed_events() {
'rocket_preload_exclude_urls' => [
[ 'add_preload_excluded_uri' ],
[ 'add_cache_reject_uri_to_excluded' ],
[ 'exclude_private_post_uri', 10, 2 ],
],
'rocket_rucss_after_clearing_failed_url' => [ 'clean_urls', 20 ],
'transition_post_status' => [ 'remove_private_post', 10, 3 ],
'rocket_preload_exclude' => [ 'exclude_private_url', 10, 2 ],
];
}

Expand Down Expand Up @@ -523,25 +523,22 @@ private function get_all_private_urls() {
/**
* Exclude private urls.
*
* @param array $regexes regexes containing excluded uris.
* @param string $url Current url to test against.
* @return array
* @param bool $excluded In case we want to exclude that url.
* @param string $url Current URL to test..
*
* @return bool Tells if it's excluded or not.
*/
public function exclude_private_post_uri( $regexes, $url ): array {
if ( ! is_array( $regexes ) ) {
$regexes = (array) $regexes;
public function exclude_private_url( $excluded, string $url ): bool {
if ( $excluded ) {
return true;
}

$private_urls = $this->get_all_private_urls();
if ( empty( $private_urls ) ) {
return $regexes;
}
$post_id = rocket_url_to_postid( $url );

if ( ! isset( $private_urls[ md5( $url ) ] ) ) {
return $regexes;
$post = get_post( $post_id );
if ( $post ) {
return 'private' === $post->post_status;
}

$regexes[] = $url;
return $regexes;
return false;
}
}
1 change: 1 addition & 0 deletions inc/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ private function init_common_subscribers() {
'wpgeotargeting',
'lazyload_css_subscriber',
'shoptimizer',
'weglot',
];

$host_type = HostResolver::get_host_service();
Expand Down
40 changes: 40 additions & 0 deletions inc/ThirdParty/Plugins/I18n/Weglot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace WP_Rocket\ThirdParty\Plugins\I18n;

use WP_Rocket\Event_Management\Subscriber_Interface;

/**
* Subscriber for compatibility with Weglot.
*/
class Weglot implements Subscriber_Interface {

/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array|string[]
*/
public static function get_subscribed_events() {
if ( ! class_exists( 'Context_Weglot' ) ) {
return [];
}

return [
'rocket_admin_bar_referer' => 'add_langs_to_referer',
];
}

/**
* Modify the referer URL by appending the current language from Weglot as a prefix to the URL path.
*
* @param string $referer The original referer URL.
* @return string The modified referer URL with the language as a prefix.
*/
public function add_langs_to_referer( $referer ) {
if ( ! function_exists( 'weglot_get_request_url_service' ) || ! function_exists( 'weglot_get_current_full_url' ) ) {
return $referer;
}

return weglot_get_request_url_service()->url_to_relative( weglot_get_current_full_url() );
}
}
4 changes: 4 additions & 0 deletions inc/ThirdParty/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use WP_Rocket\ThirdParty\Plugins\Optimization\RocketLazyLoad;
use WP_Rocket\ThirdParty\Plugins\Optimization\Perfmatters;
use WP_Rocket\ThirdParty\Plugins\Optimization\RapidLoad;
use WP_Rocket\ThirdParty\Plugins\I18n\Weglot;

/**
* Service provider for WP Rocket third party compatibility
Expand Down Expand Up @@ -101,6 +102,7 @@ class ServiceProvider extends AbstractServiceProvider {
'rapidload',
'translatepress',
'wpgeotargeting',
'weglot',
];

/**
Expand Down Expand Up @@ -255,6 +257,8 @@ public function register() {
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'rapidload', RapidLoad::class );
$this->getContainer()
->share( 'weglot', Weglot::class );
$this->getContainer()->share( 'translatepress', TranslatePress::class );
$this->getContainer()->share( 'wpgeotargeting', WPGeotargeting::class );
}
Expand Down
8 changes: 7 additions & 1 deletion inc/common/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ function rocket_admin_bar( $wp_admin_bar ) {
global $pagenow, $post;

if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
$referer = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
$uri = filter_var( wp_unslash( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ) );
/**
* Filters to act on the referer url for the admin bar.
*
* @param string $uri Current uri
*/
$referer = (string) apply_filters( 'rocket_admin_bar_referer', esc_url( $uri ) );
$referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer ) );
} else {
$referer = '';
Expand Down
8 changes: 8 additions & 0 deletions inc/functions/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,14 @@ function rocket_clean_home( $lang = '' ) {
}
}

$param_dirs = glob( $root . '/#*', GLOB_NOSORT );

if ( $param_dirs ) {
foreach ( $param_dirs as $dir ) {
rocket_rrmdir( $dir );
}
}

// Remove the hidden empty file for mobile detection on NGINX with the Rocket NGINX configuration.
$nginx_mobile_detect_files = glob( $root . '/.mobile-active', GLOB_NOSORT );
if ( $nginx_mobile_detect_files ) {
Expand Down

0 comments on commit cb55163

Please sign in to comment.