Skip to content

Commit

Permalink
Release v3.14.2 (PR #6051)
Browse files Browse the repository at this point in the history
Release v3.14.2
  • Loading branch information
engahmeds3ed authored Jul 18, 2023
2 parents b5e13c1 + 6394832 commit 05762d9
Show file tree
Hide file tree
Showing 124 changed files with 50,693 additions and 49,150 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
"mnsami/composer-custom-directory-installer": "^2.0",
"mobiledetect/mobiledetectlib": "^2.8",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"psr/container": "1.0.0",
"roave/security-advisories": "dev-master",
"szepeviktor/phpstan-wordpress": "^0.7.0",
"szepeviktor/phpstan-wordpress": "^1.3",
"woocommerce/action-scheduler": "^3.4",
"wp-coding-standards/wpcs": "^2",
"wp-media/background-processing": "^1.3",
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.

18 changes: 13 additions & 5 deletions inc/Addon/Cloudflare/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Client {
/**
* An array of arguments for wp_remote_request()
*
* @var array
* @var mixed[]
*/
protected $args = [];

Expand Down Expand Up @@ -50,8 +50,8 @@ public function set_auth( AuthInterface $auth ) {
/**
* API call method for sending requests using GET.
*
* @param string $path Path of the endpoint.
* @param array $data Data to be sent along with the request.
* @param string $path Path of the endpoint.
* @param mixed[] $data Data to be sent along with the request.
*
* @return object
*/
Expand Down Expand Up @@ -131,10 +131,18 @@ protected function request( $path, $method = 'get', array $data = [] ) {

$content = json_decode( $content );

if ( ! is_object( $content ) ) {
return new WP_Error( 'cloudflare_content_error', __( 'Cloudflare unexpected response', 'rocket' ) );
}

if ( empty( $content->success ) ) {
return $this->set_request_error( $content );
}

if ( ! property_exists( $content, 'result' ) ) {
return new WP_Error( 'cloudflare_no_reply', __( 'Missing Cloudflare result.', 'rocket' ) );
}

return $content->result;
}

Expand All @@ -147,8 +155,8 @@ protected function request( $path, $method = 'get', array $data = [] ) {
*
* @return array|WP_Error
*/
private function do_remote_request( string $path, string $method, array $data ) {
$this->args['method'] = isset( $method ) ? strtoupper( $method ) : 'GET';
private function do_remote_request( string $path, string $method = 'GET', array $data = [] ) {
$this->args['method'] = strtoupper( $method );

$headers = [
'User-Agent' => 'wp-rocket/' . rocket_get_constant( 'WP_ROCKET_VERSION' ),
Expand Down
6 changes: 3 additions & 3 deletions inc/Addon/Cloudflare/API/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function update_rocket_loader( string $zone_id, $value ) {
/**
* Updates the zone's minify setting.
*
* @param string $zone_id Zone ID.
* @param string $value Minify value.
* @param string $zone_id Zone ID.
* @param string[] $value Minify value.
*
* @return object
*/
Expand Down Expand Up @@ -133,7 +133,7 @@ public function change_development_mode( string $zone_id, $value ) {
*
* @param string $zone_id Zone ID.
* @param string $setting Name of the setting to change.
* @param string $value Setting value.
* @param mixed $value Setting value.
*
* @return object
*/
Expand Down
6 changes: 6 additions & 0 deletions inc/Addon/Cloudflare/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace WP_Rocket\Addon\Cloudflare\Admin;

use WP_Rocket\Engine\Admin\Settings\Settings;
use WP_Rocket\Event_Management\Subscriber_Interface;

class Subscriber implements Subscriber_Interface {
Expand All @@ -21,6 +22,8 @@ public static function get_subscribed_events() {

/**
* This notice is displayed after purging the CloudFlare cache.
*
* @return void
*/
public function maybe_display_purge_notice() {
if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
Expand All @@ -46,6 +49,8 @@ public function maybe_display_purge_notice() {

/**
* This notice is displayed after modifying the CloudFlare settings.
*
* @return void
*/
public function maybe_display_update_settings_notice() {
$screen = get_current_screen();
Expand All @@ -63,6 +68,7 @@ public function maybe_display_update_settings_notice() {

$errors = '';
$success = '';
$pre = '';
delete_transient( $user_id . '_cloudflare_update_settings' );

if ( isset( $notices['pre'] ) ) {
Expand Down
12 changes: 4 additions & 8 deletions inc/Addon/Cloudflare/Auth/APIKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class APIKey implements AuthInterface {
*
* @var string
*/
private $email;
private $email = '';

/**
* Cloudflare API Key
*
* @var string
*/
private $api_key;
private $api_key = '';

/**
* Constructor
*
* @param string $email Cloudflare email.
* @param string $api_key Cloudflare API key.
*/
public function __construct( string $email, string $api_key ) {
public function __construct( string $email = '', string $api_key = '' ) {
$this->email = $email;
$this->api_key = $api_key;
}
Expand Down Expand Up @@ -66,10 +66,6 @@ public function is_valid_credentials() {
);
}

return (
isset( $this->email, $this->api_key )
&&
false !== filter_var( $this->email, FILTER_VALIDATE_EMAIL )
);
return false !== filter_var( $this->email, FILTER_VALIDATE_EMAIL );
}
}
2 changes: 2 additions & 0 deletions inc/Addon/Cloudflare/Auth/AuthInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WP_Rocket\Addon\Cloudflare\Auth;

use WP_Error;

interface AuthInterface {
/**
* Gets headers for Cloudflare API request
Expand Down
28 changes: 13 additions & 15 deletions inc/Addon/Cloudflare/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CloudFlare\IpRewrite;
use DateTimeImmutable;
use WP_Error;
use WP_Post;
use WP_Rocket\Addon\Cloudflare\Auth\AuthInterface;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Addon\Cloudflare\API\Endpoints;
Expand Down Expand Up @@ -93,12 +94,10 @@ public function is_auth_valid( string $zone_id ) {
$site_url = domain_mapping_siteurl( $site_url );
}

if ( ! empty( $result ) ) {
$parsed_url = wp_parse_url( $site_url );
$parsed_url = wp_parse_url( $site_url );

if ( is_object( $result ) && property_exists( $result, 'name' ) && false !== strpos( strtolower( $parsed_url['host'] ), $result->name ) ) {
$zone_found = true;
}
if ( property_exists( $result, 'name' ) && false !== strpos( strtolower( $parsed_url['host'] ), $result->name ) ) {
$zone_found = true;
}

if ( ! $zone_found ) {
Expand Down Expand Up @@ -195,11 +194,7 @@ public function set_browser_cache_ttl( $value ) {
*
* @return string
*/
private function convert_time( $value ): string {
if ( ! is_int( $value ) ) {
$value = 0;
}

private function convert_time( int $value ): string {
$base = new DateTimeImmutable( '@0' );
$time = new DateTimeImmutable( "@$value" );
$format = '%a ' . __( 'days', 'rocket' );
Expand Down Expand Up @@ -320,6 +315,11 @@ public function get_settings() {
return $cf_settings;
}

$browser_cache_ttl = 0;
$cache_level = '';
$rocket_loader = '';
$cf_minify = '';

foreach ( $cf_settings as $cloudflare_option ) {
switch ( $cloudflare_option->id ) {
case 'browser_cache_ttl':
Expand Down Expand Up @@ -372,11 +372,7 @@ public function get_cloudflare_ips() {

$cf_ips = $this->endpoints->get_ips();

if (
is_wp_error( $cf_ips )
||
empty( $cf_ips )
) {
if ( is_wp_error( $cf_ips ) ) {
// Set default IPs from Cloudflare if call to Cloudflare /ips API does not contain a success.
// Prevents from making API calls on each page load.
$cf_ips = $this->get_default_ips();
Expand Down Expand Up @@ -448,6 +444,8 @@ public static function set_ip_rewrite() {

/**
* Fixes Cloudflare Flexible SSL redirect loop
*
* @return void
*/
public static function fix_cf_flexible_ssl() {
$ip_rewrite = self::set_ip_rewrite();
Expand Down
10 changes: 5 additions & 5 deletions inc/Addon/Cloudflare/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ public function register() {

$this->getLeagueContainer()->add( 'cloudflare_auth_factory', APIKeyFactory::class )->addArgument( $options );

$this->getContainer()->add( 'cloudflare_client', Client::class )
$this->getLeagueContainer()->add( 'cloudflare_client', Client::class )
->addArgument( $this->getContainer()->get( 'cloudflare_auth_factory' )->create() );
$this->getContainer()->add( 'cloudflare_endpoints', Endpoints::class )
$this->getLeagueContainer()->add( 'cloudflare_endpoints', Endpoints::class )
->addArgument( $this->getContainer()->get( 'cloudflare_client' ) );

$this->getContainer()->add( 'cloudflare', Cloudflare::class )
$this->getLeagueContainer()->add( 'cloudflare', Cloudflare::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'cloudflare_endpoints' ) );
$this->getContainer()->share( 'cloudflare_subscriber', CloudflareSubscriber::class )
$this->getLeagueContainer()->share( 'cloudflare_subscriber', CloudflareSubscriber::class )
->addArgument( $this->getContainer()->get( 'cloudflare' ) )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $this->getContainer()->get( 'cloudflare_auth_factory' ) )
->addTag( 'cloudflare_subscriber' );
$this->getContainer()->share(
$this->getLeagueContainer()->share(
'cloudflare_admin_subscriber',
CloudflareAdminSubscriber::class
);
Expand Down
23 changes: 23 additions & 0 deletions inc/Addon/Cloudflare/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace WP_Rocket\Addon\Cloudflare;

use WP_Post;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Admin\{Options, Options_Data};
use WPMedia\Cloudflare\Auth\AuthFactoryInterface;
Expand Down Expand Up @@ -133,6 +134,8 @@ private function should_filter_varnish(): bool {

/**
* Automatically set Cloudflare development mode value to off after 3 hours to reflect Cloudflare behaviour.
*
* @return void
*/
public function deactivate_devmode() {
$this->options->set( 'cloudflare_devmode', 0 );
Expand Down Expand Up @@ -177,6 +180,8 @@ public function auto_purge() {
* @param WP_Post $post The post object.
* @param array $purge_urls URLs cache files to remove.
* @param string $lang The post language.
*
* @return void
*/
public function auto_purge_by_url( $post, $purge_urls, $lang ) {
if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
Expand Down Expand Up @@ -209,6 +214,8 @@ public function auto_purge_by_url( $post, $purge_urls, $lang ) {

/**
* Purge CloudFlare cache.
*
* @return void
*/
public function purge_cache_no_die() {
if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
Expand Down Expand Up @@ -264,6 +271,8 @@ public function purge_cache_no_die() {

/**
* Purge CloudFlare cache.
*
* @return void
*/
public function purge_cache() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_purge_cloudflare' ) ) {
Expand All @@ -278,6 +287,8 @@ public function purge_cache() {

/**
* Set Real IP from CloudFlare.
*
* @return void
*/
public function set_real_ip() {
Cloudflare::set_ip_rewrite();
Expand All @@ -287,6 +298,8 @@ public function set_real_ip() {
* Save Cloudflare dev mode admin option.
*
* @param string $value New value for Cloudflare dev mode.
*
* @return string[]
*/
private function save_cloudflare_devmode( $value ) {
$result = $this->cloudflare->set_devmode( $value );
Expand All @@ -310,6 +323,8 @@ private function save_cloudflare_devmode( $value ) {
* Save Cloudflare cache_level admin option.
*
* @param string $value New value for Cloudflare cache_level.
*
* @return string[]
*/
private function save_cache_level( $value ) {
// Set Cache Level to Aggressive.
Expand Down Expand Up @@ -340,6 +355,8 @@ private function save_cache_level( $value ) {
* Save Cloudflare minify admin option.
*
* @param string $value New value for Cloudflare minify.
*
* @return string[]
*/
private function save_minify( $value ) {
$result = $this->cloudflare->set_minify( $value );
Expand All @@ -363,6 +380,8 @@ private function save_minify( $value ) {
* Save Cloudflare rocket loader admin option.
*
* @param string $value New value for Cloudflare rocket loader.
*
* @return string[]
*/
private function save_rocket_loader( $value ) {
$result = $this->cloudflare->set_rocket_loader( $value );
Expand All @@ -386,6 +405,8 @@ private function save_rocket_loader( $value ) {
* Save Cloudflare browser cache ttl admin option.
*
* @param int $value New value for Cloudflare browser cache ttl.
*
* @return string[]
*/
private function save_browser_cache_ttl( $value ) {
$result = $this->cloudflare->set_browser_cache_ttl( $value );
Expand All @@ -410,6 +431,8 @@ private function save_browser_cache_ttl( $value ) {
*
* @param int $auto_settings New value for Cloudflare auto_settings.
* @param string $old_settings Cloudflare cloudflare_old_settings.
*
* @return array<int, array<string>>
*/
private function save_cloudflare_auto_settings( $auto_settings, $old_settings ) {
$cf_old_settings = explode( ',', $old_settings );
Expand Down
10 changes: 10 additions & 0 deletions inc/Engine/Admin/Beacon/Beacon.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,16 @@ public function get_suggest( $doc_id ) {
'url' => 'https://fr.docs.wp-rocket.me/article/1327-problemes-critical-css-fouc#critical-path-css-de-secours',
],
],
'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',
],
'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',
],
],
];

return isset( $suggest[ $doc_id ][ $this->get_user_locale() ] )
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Optimization/DelayJS/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function maybe_disable_combine_js( $value, $old_value ): array {
public static function get_delay_js_default_exclusions(): array {

$exclusions = [
'\/jquery(-migrate)?-?([0-9.]+)?(.min|.slim|.slim.min)?.js(\?(.*))?$',
'\/jquery(-migrate)?-?([0-9.]+)?(.min|.slim|.slim.min)?.js(\?(.*))?( |\'|"|>)',
'js-(before|after)',
];

Expand Down
Loading

0 comments on commit 05762d9

Please sign in to comment.