Skip to content

Commit

Permalink
Release v3.15.0.1
Browse files Browse the repository at this point in the history
Release v3.15.0.1
  • Loading branch information
engahmeds3ed authored Sep 12, 2023
2 parents 6417d8f + 98b0513 commit 240d37d
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 37 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.

84 changes: 80 additions & 4 deletions inc/Engine/Media/Lazyload/CSS/Front/MappingFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MappingFormatter {
*/
public function format( array $data ): array {
$formatted_urls = [];

foreach ( $data as $datum ) {
$hash = $datum['hash'];

Expand All @@ -31,17 +32,92 @@ public function format( array $data ): array {
}

/**
* Remove pseudo classes.
* Get pseudo elements to remove.
*
* @return string[]
*/
private function get_pseudo_elements_to_remove() {
$original_pseudo_elements = [
':before',
':after',
':first-line',
':first-letter',
':active',
':hover',
':focus',
':visited',
':focus-within',
':focus-visible',
];

/**
* Pseudo elements to remove from lazyload CSS selector.
*
* @param string[] Pseudo elements to remove.
*/
$pseudo_elements_to_remove = apply_filters( 'rocket_lazyload_css_ignored_pseudo_elements', $original_pseudo_elements );

if ( ! is_array( $original_pseudo_elements ) ) {
$pseudo_elements_to_remove = $original_pseudo_elements;
}

usort(
$pseudo_elements_to_remove,
static function ( $first, $second ) {
if ( strlen( $first ) === strlen( $second ) ) {
return 0;
}
return ( strlen( $first ) > strlen( $second ) ) ? -1 : 1;
}
);

return $pseudo_elements_to_remove;
}

/**
* Remove pseudo classes from the selector while mapping on each selector.
*
* @param string $selector Selector to clean.
* @return string
*/
public function remove_pseudo_classes_for_selector( string $selector ): string {
$selector = preg_replace( '/::[\w-]+/', '', $selector );

$pseudo_elements_to_remove = $this->get_pseudo_elements_to_remove();
foreach ( $pseudo_elements_to_remove as $element ) {
$selector = str_replace( $element, '', $selector );
}
if ( in_array( substr( $selector, -1 ), [ '&', '~', '+', '>' ], true ) ) {
$selector .= '*';
}

if ( ! $selector ) {
return 'body';
}

return $selector;
}


/**
* Remove pseudo classes from the selector.
*
* @param string $selector Selector to clean.
* @return string
*/
protected function remove_pseudo_classes( string $selector ): string {
$result = preg_replace( '/::[\w\-]+/', '', $selector );
if ( ! $result ) {
$selectors = explode( ',', $selector );

$selectors = array_map( [ $this, 'remove_pseudo_classes_for_selector' ], $selectors );

$selectors = array_unique( $selectors );

$selector = implode( ',', $selectors );

if ( ! $selector ) {
return 'body';
}
return (string) $result;

return (string) $selector;
}
}
1 change: 1 addition & 0 deletions inc/Engine/Support/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Data {
'delay_js' => 'Delay JS',
'async_css' => 'Load CSS asynchronously',
'lazyload' => 'Lazyload Images',
'lazyload_css_bg_img' => 'Lazyload CSS Background Images',
'lazyload_iframes' => 'Lazyload Iframes',
'lazyload_youtube' => 'Lazyload Youtube',
'cache_webp' => 'WebP Cache',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,72 @@
'hash' => 'a122ad12df3',
'selector' => '::after',
'url' => 'http://example.org/test',
]
],
[
'hash' => 'a122ad12df3',
'selector' => '::after',
'url' => 'http://example.org/test',
],
[
'hash' => 'a21ss2',
'selector' => 'dd:nth-last-of-type(3n)',
'url' => 'images/underline.png'
],
[
'hash' => 'a21ss4',
'selector' => '.background-image~:after',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss8',
'selector' => '.background-image>:before,.background-image>:after',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss18',
'selector' => '.background-image>::before,.background-image>::after',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss18',
'selector' => '.background-image>::before',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.background-image::first-letter',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.subscribe:active',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.subscribe:focus',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.subscribe:hover',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => 'a:visited',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.subscribe:focus-within',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
[
'hash' => 'a21ss25',
'selector' => '.subscribe:focus-visible',
'url' => 'images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
],
],
'expected' => [
Expand All @@ -58,7 +123,59 @@
[
'selector' => 'body',
'style' => ':root{--wpr-bg-a122ad12df3: http://example.org/test;}'
]
],
[
'selector' => 'body',
'style' => ':root{--wpr-bg-a122ad12df3: http://example.org/test;}'
],
[
'selector' => 'dd:nth-last-of-type(3n)',
'style' => ':root{--wpr-bg-a21ss2: images/underline.png;}'
],
[
'selector' => '.background-image~*',
'style' => ':root{--wpr-bg-a21ss4: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.background-image>*',
'style' => ':root{--wpr-bg-a21ss8: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.background-image>*',
'style' => ':root{--wpr-bg-a21ss18: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.background-image>*',
'style' => ':root{--wpr-bg-a21ss18: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.background-image',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.subscribe',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.subscribe',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.subscribe',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => 'a',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.subscribe',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
[
'selector' => '.subscribe',
'style' => ':root{--wpr-bg-a21ss25: images/maxime-lebrun-6g3Akg708E0-unsplash.jpg;}'
],
]
],
];
1 change: 1 addition & 0 deletions tests/Fixtures/inc/Engine/Support/Data/getSupportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'async_css' => 0,
'critical_css' => '',
'lazyload' => 0,
'lazyload_css_bg_img' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class Test_CronCleanRows extends TestCase {
use DBTrait;

private $input;

protected function loadTestDataConfig() {
$obj = new ReflectionObject( $this );
$filename = $obj->getFileName();
Expand All @@ -34,7 +36,7 @@ public static function tear_down_after_class() {
self::uninstallAll();
}

public function tear_down() : void {
public function tear_down() {
remove_filter( 'rocket_rucss_delete_interval', [ $this, 'set_rucss_delay' ] );

parent::tear_down();
Expand All @@ -43,21 +45,22 @@ public function tear_down() : void {
/**
* @dataProvider configTestData
*/
public function testShouldDoExpected( $input ){
public function testShouldDoExpected( $input ) {
$container = apply_filters( 'rocket_container', null );
$rucss_usedcss_query = $container->get( 'rucss_used_css_query' );
$current_date = current_time( 'mysql', true );
$old_date = strtotime( $current_date. ' - 32 days' );
$old_date = strtotime( $current_date . ' - 32 days' );

$this->input = $input;

add_filter( 'rocket_rucss_delete_interval', [ $this, 'set_rucss_delay' ] );
$this->set_permalink_structure( "/%postname%/" );

$count_remain_used_css = 0;

foreach ( $input['used_css'] as $used_css ) {
if ( $old_date < strtotime( $used_css['last_accessed']) ) {
$count_remain_used_css ++;
if ( $old_date < strtotime( $used_css['last_accessed'] ) ) {
++$count_remain_used_css;
}
$rucss_usedcss_query->add_item( $used_css );
}
Expand All @@ -72,7 +75,7 @@ public function testShouldDoExpected( $input ){


if ( $this->input['delay'] ) {
$this->assertCount( $count_remain_used_css,$resultUsedCssAfterClean );
$this->assertCount( $count_remain_used_css, $resultUsedCssAfterClean );
} else {
$this->assertCount( count( $input['used_css'] ), $resultUsedCssAfterClean );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,45 @@ class Test_addCdnHelperMessage extends TestCase {

protected $config;

public function set_up()
{
public function set_up() {
parent::set_up();
add_filter('pre_option_active_plugins', [$this, 'plugin_enabled']);
add_filter('pre_option_cloudflare_api_email', [$this, 'cloudflare_api_email']);
add_filter('pre_option_cloudflare_api_key', [$this, 'cloudflare_api_key']);
add_filter('pre_option_cloudflare_cached_domain_name', [$this, 'cloudflare_cached_domain_name']);

add_filter( 'pre_option_active_plugins', [ $this, 'plugin_enabled' ] );
add_filter( 'pre_option_cloudflare_api_email', [ $this, 'cloudflare_api_email' ] );
add_filter( 'pre_option_cloudflare_api_key', [ $this, 'cloudflare_api_key' ] );
add_filter( 'pre_option_cloudflare_cached_domain_name', [ $this, 'cloudflare_cached_domain_name' ] );
}

public function tear_down()
{
remove_filter('pre_option_active_plugins', [$this, 'plugin_enabled']);
remove_filter('pre_option_cloudflare_api_email', [$this, 'cloudflare_api_email']);
remove_filter('pre_option_cloudflare_api_key', [$this, 'cloudflare_api_key']);
remove_filter('pre_option_cloudflare_cached_domain_name', [$this, 'cloudflare_cached_domain_name']);
public function tear_down() {
remove_filter( 'pre_option_active_plugins', [ $this, 'plugin_enabled' ] );
remove_filter( 'pre_option_cloudflare_api_email', [ $this, 'cloudflare_api_email' ] );
remove_filter( 'pre_option_cloudflare_api_key', [ $this, 'cloudflare_api_key' ] );
remove_filter( 'pre_option_cloudflare_cached_domain_name', [ $this, 'cloudflare_cached_domain_name' ] );

parent::tear_down();
}

/**
* @dataProvider configTestData
*/
public function testShouldReturnAsExpected( $config, $expected )
{
* @dataProvider configTestData
*/
public function testShouldReturnAsExpected( $config, $expected ) {
$this->config = $config;
$this->assertSame($expected, apply_filters('rocket_cdn_helper_addons', $config['addons']));
}
$this->assertSame(
$expected,
apply_filters( 'rocket_cdn_helper_addons', $config['addons'] )
);
}

public function plugin_enabled($plugins) {
if(! $this->config['plugin_enabled']) {
public function plugin_enabled( $plugins ) {
if ( ! $this->config['plugin_enabled'] ) {
return $plugins;
}
$plugins []= 'cloudflare/cloudflare.php';

if ( ! is_array( $plugins ) ) {
$plugins = (array) $plugins;
}

$plugins[] = 'cloudflare/cloudflare.php';

return $plugins;
}
Expand Down
4 changes: 2 additions & 2 deletions wp-rocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Rocket
* Plugin URI: https://wp-rocket.me
* Description: The best WordPress performance plugin.
* Version: 3.15
* Version: 3.15.0.1
* Requires at least: 5.8
* Requires PHP: 7.3
* Code Name: Iego
Expand All @@ -20,7 +20,7 @@
defined( 'ABSPATH' ) || exit;

// Rocket defines.
define( 'WP_ROCKET_VERSION', '3.15' );
define( 'WP_ROCKET_VERSION', '3.15.0.1' );
define( 'WP_ROCKET_WP_VERSION', '5.8' );
define( 'WP_ROCKET_WP_VERSION_TESTED', '6.3' );
define( 'WP_ROCKET_PHP_VERSION', '7.3' );
Expand Down

0 comments on commit 240d37d

Please sign in to comment.