Skip to content

Commit d5dc4ea

Browse files
authored
Merge pull request #269 from wp-media/branch-2.9.1
2.9.1
2 parents 0cbd725 + 4e5150c commit d5dc4ea

File tree

11 files changed

+199
-103
lines changed

11 files changed

+199
-103
lines changed

inc/3rd-party/3rd-party.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require( WP_ROCKET_3RD_PARTY_PATH . 'age-verify.php' );
2525
require( WP_ROCKET_3RD_PARTY_PATH . 'autoptimize.php' );
2626
require( WP_ROCKET_3RD_PARTY_PATH . 'eu-cookie-law.php' );
27+
require( WP_ROCKET_3RD_PARTY_PATH . 'weepie-cookie-allow.php' );
2728
require( WP_ROCKET_3RD_PARTY_PATH . 'kk-star-ratings.php' );
2829
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-postratings.php' );
2930
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-print.php' );
@@ -42,5 +43,6 @@
4243
require( WP_ROCKET_3RD_PARTY_PATH . 'page-builder/visual-composer.php' );
4344
require( WP_ROCKET_3RD_PARTY_PATH . 'security/secupress.php' );
4445
require( WP_ROCKET_3RD_PARTY_PATH . 'simple-custom-css.php' );
46+
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-retina-2x.php' );
4547

4648
require( WP_ROCKET_3RD_PARTY_PATH . 'themes/divi.php' );

inc/3rd-party/simple-custom-css.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
33

44
if ( defined( 'SCCSS_FILE' ) ) :
5-
add_action( 'wp_enqueue_scripts', 'rocket_cache_sccss', 1 );
5+
add_action( 'wp_enqueue_scripts', 'rocket_cache_sccss', 98 );
66
add_action( 'update_option_sccss_settings', 'rocket_delete_sccss_cache_file' );
77
add_filter( 'rocket_cache_busting_filename', 'rocket_sccss_cache_busting_filename' );
88
endif;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3+
4+
/**
5+
* Compatibility with WeePie Cookie Allow
6+
*
7+
* @since 2.9
8+
*/
9+
if ( class_exists( 'WpieCookieAllow' ) ) :
10+
/*
11+
* Update .htaccess & config files when the "Enabled" and "Autoblock" options are turned on
12+
*
13+
*/
14+
add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_weepie_cookie_allow_mandatory_cookie' );
15+
add_action( 'update_option_wpca_settings_general', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
16+
function rocket_after_update_wp_cookie_allow_options( $old_value, $value ) {
17+
if ( ( isset( $old_value['general_plugin_status'], $value['general_plugin_status'] ) && ( $old_value['general_plugin_status'] == $value['general_plugin_status'] ) ) && isset( $old_value['general_cookies_before_consent'], $value['general_cookies_before_consent'] ) && $old_value['general_cookies_before_consent'] == $value['general_cookies_before_consent'] ) {
18+
return;
19+
}
20+
21+
// Update the WP Rocket rules on the .htaccess file
22+
flush_rocket_htaccess();
23+
24+
// Update the config file
25+
rocket_generate_config_file();
26+
}
27+
28+
// Don't add the WP Rocket rewrite rules to avoid issues
29+
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false' );
30+
endif;
31+
32+
// Add cookies when we activate the plugin
33+
add_action( 'activate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_activate_wp_cookie_allow', 11 );
34+
function rocket_activate_wp_cookie_allow() {
35+
add_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' );
36+
add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_weepie_cookie_allow_mandatory_cookie' );
37+
38+
// Update the WP Rocket rules on the .htaccess file
39+
flush_rocket_htaccess();
40+
41+
// Regenerate the config file
42+
rocket_generate_config_file();
43+
}
44+
45+
// Remove cookies when we deactivate the plugin
46+
add_action( 'deactivate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_deactivate_wp_cookie_allow', 11 );
47+
function rocket_deactivate_wp_cookie_allow() {
48+
remove_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' );
49+
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_weepie_cookie_allow_mandatory_cookie' );
50+
51+
// Update the WP Rocket rules on the .htaccess file
52+
flush_rocket_htaccess();
53+
54+
// Regenerate the config file
55+
rocket_generate_config_file();
56+
}
57+
58+
// Add the WeePie Cookie Allow cookie to the list of mandatory cookies before generating caching files
59+
function rocket_add_weepie_cookie_allow_mandatory_cookie( $cookies ) {
60+
$options = get_option( 'wpca_settings_general' );
61+
62+
if ( 1 === (int) $options['general_plugin_status'] && 1 === (int) $options['general_cookies_before_consent'] ) {
63+
$cookies['weepie-cookie-allow'] = 'wpca_consent';
64+
}
65+
66+
return $cookies;
67+
}

inc/3rd-party/wp-retina-2x.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
if ( class_exists( 'WR2X_Admin' ) ) :
4+
add_filter( 'wr2x_img_retina_url', 'rocket_cdn_on_images_from_wp_retina_x2' );
5+
add_filter( 'wr2x_img_url', 'rocket_cdn_on_images_from_wp_retina_x2' );
6+
/**
7+
* Conflict with WP Retina x2: Apply CDN on srcset attribute.
8+
*
9+
* @since 2.9.1 Use global $wr2x_admin
10+
* @since 2.5.5
11+
*
12+
* @param string $url URL of the image.
13+
* @return string Updated URL with CDN
14+
*/
15+
function rocket_cdn_on_images_from_wp_retina_x2( $url ) {
16+
global $wr2x_admin;
17+
18+
if ( ! method_exists( $wr2x_admin, 'is_pro' ) || ! $wr2x_admin->is_pro() ) {
19+
return $url;
20+
}
21+
22+
$cdn_domain = get_option( 'wr2x_cdn_domain' );
23+
24+
if ( ! empty( $cdn_domain ) ) {
25+
return $url;
26+
}
27+
28+
return get_rocket_cdn_url( $url, array( 'all', 'images' ) );
29+
}
30+
endif;

inc/domain-mapping.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
function rocket_parse_url_domain_mapping( $url ) {
1111
$original_siteurl_host = parse_url( get_original_url( 'siteurl' ), PHP_URL_HOST );
1212
$domain_mapping_siteurl_host = parse_url( domain_mapping_siteurl( false ), PHP_URL_HOST );
13-
14-
$url[0] = str_replace( $original_siteurl_host, $domain_mapping_siteurl_host, $url[0] );
13+
14+
if ( false === strpos( $domain_mapping_siteurl_host, $original_siteurl_host ) ) {
15+
$url[0] = str_replace( $original_siteurl_host, $domain_mapping_siteurl_host, $url[0] );
16+
}
1517

1618
return $url;
1719
}

inc/front/cdn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function rocket_cdn_custom_files( $html ) {
220220
$filetypes = apply_filters( 'rocket_cdn_custom_filetypes', array( 'mp3', 'ogg', 'mp4', 'm4v', 'avi', 'mov', 'flv', 'swf', 'webm', 'pdf', 'doc', 'docx', 'txt', 'zip', 'tar', 'bz2', 'tgz', 'rar' ) );
221221
$filetypes = implode( '|', $filetypes );
222222

223-
preg_match_all( '#<a[^>]+?href=[\'"]?(.*\.(?:' . $filetypes . '))[\'"]?[^>]*>#i', $html, $matches );
223+
preg_match_all( '#<a[^>]+?href=[\'"]?([^"\'>]+\.(?:' . $filetypes . '))[\'"]?[^>]*>#i', $html, $matches );
224224

225225
if ( ( bool ) $matches ) {
226226
$i = 0;

inc/front/enqueue.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
6464
$hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
6565
$hosts[] = parse_url( home_url(), PHP_URL_HOST );
6666
$hosts_index = array_flip( $hosts );
67-
list( $file_host, $relative_src_path ) = get_rocket_parse_url( $full_src );
67+
list( $file_host, $relative_src_path, $scheme, $query ) = get_rocket_parse_url( $full_src );
6868

6969
if ( $file_host == '' ) {
7070
$full_src = home_url() . $src;
@@ -74,7 +74,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
7474
return $src;
7575
}
7676

77-
$relative_src_path = ltrim( $relative_src_path, '/' );
77+
$relative_src_path = ltrim( $relative_src_path . '?' . $query, '/' );
7878
$full_src_path = ABSPATH . dirname( $relative_src_path );
7979
/*
8080
* Filters the cache busting filename
@@ -140,7 +140,9 @@ function rocket_cache_dynamic_resource( $src ) {
140140

141141
$full_src = ( substr( $src, 0, 2 ) === '//' ) ? rocket_add_url_protocol( $src ) : $src;
142142

143-
switch ( current_filter() ) {
143+
$current_filter = current_filter();
144+
145+
switch ( $current_filter ) {
144146
case 'script_loader_src':
145147
$extension = '.js';
146148
break;
@@ -152,7 +154,7 @@ function rocket_cache_dynamic_resource( $src ) {
152154
$hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
153155
$hosts[] = parse_url( home_url(), PHP_URL_HOST );
154156
$hosts_index = array_flip( $hosts );
155-
list( $file_host, $relative_src_path ) = get_rocket_parse_url( $full_src );
157+
list( $file_host, $relative_src_path, $scheme, $query ) = get_rocket_parse_url( $full_src );
156158

157159
if ( $file_host == '' ) {
158160
$full_src = home_url() . $src;
@@ -162,7 +164,8 @@ function rocket_cache_dynamic_resource( $src ) {
162164
return $src;
163165
}
164166

165-
$relative_src_path = ltrim( $relative_src_path, '/' );
167+
$relative_src_path = ltrim( $relative_src_path . '?' . $query, '/' );
168+
$full_src_path = ABSPATH . dirname( $relative_src_path );
166169
/*
167170
* Filters the dynamic resource cache filename
168171
*
@@ -184,11 +187,21 @@ function rocket_cache_dynamic_resource( $src ) {
184187
return $src;
185188
}
186189

190+
if ( 'style_loader_src' === $current_filter ) {
191+
if ( ! class_exists( 'Minify_CSS_UriRewriter' ) ) {
192+
require( WP_ROCKET_PATH . 'min/lib/Minify/CSS/UriRewriter.php' );
193+
}
194+
// Rewrite import/url in CSS content to add the absolute path to the file
195+
$file_content = Minify_CSS_UriRewriter::rewrite( $response['body'], $full_src_path );
196+
} else {
197+
$file_content = $response['body'];
198+
}
199+
187200
if ( ! is_dir( $cache_busting_paths['bustingpath'] ) ) {
188201
rocket_mkdir_p( $cache_busting_paths['bustingpath'] );
189202
}
190203

191-
rocket_put_content( $cache_busting_paths['filepath'], $response['body'] );
204+
rocket_put_content( $cache_busting_paths['filepath'], $file_content );
192205

193206
return $cache_busting_paths['url'];
194207
}

inc/front/plugin-compatibility.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,6 @@ function __rocket_cdn_on_sliders_with_lazyload() {
157157
}
158158
}
159159

160-
/**
161-
* Conflict with WP Retina x2: Apply CDN on srcset attribute.
162-
*
163-
* @since 2.5.5
164-
*/
165-
add_filter( 'wr2x_img_retina_url', '__rocket_cdn_on_images_from_wp_retina_x2' );
166-
add_filter( 'wr2x_img_url', '__rocket_cdn_on_images_from_wp_retina_x2' );
167-
function __rocket_cdn_on_images_from_wp_retina_x2( $url ) {
168-
if ( wr2x_is_pro() ) {
169-
$cdn_domain = wr2x_getoption( "cdn_domain", "wr2x_advanced", "" );
170-
}
171-
172-
if ( empty( $cdn_domain ) ) {
173-
return get_rocket_cdn_url( $url, array( 'all', 'images' ) );
174-
}
175-
176-
return $url;
177-
}
178-
179160
/**
180161
* Conflict with MailChimp List Subscribe Form: Enqueue style without lack of performance, grrrr!!!
181162
*

languages/rocket-pt_BR.mo

14.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)