Skip to content

Commit 57fab4b

Browse files
authored
Merge pull request #384 from wp-media/branch-2.9.9
2.9.9
2 parents 16363bc + 563c2d8 commit 57fab4b

File tree

15 files changed

+420
-588
lines changed

15 files changed

+420
-588
lines changed

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

Lines changed: 130 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,136 @@
1-
<?php
1+
<?php
22
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
33

4-
if ( class_exists( 'GD_System_Plugin_Cache_Purge' ) ) :
5-
6-
/**
7-
* Clear WP Rocket cache after purged the Varnish cache via GoDaddy Hosting
8-
*
9-
* @since 2.6.5
10-
*
11-
* @return void
12-
*/
13-
add_action( 'init', '__rocket_clear_cache_after_godaddy', 0 );
14-
function __rocket_clear_cache_after_godaddy() {
15-
if ( ! isset( $_REQUEST['GD_COMMAND'] ) || $_REQUEST['GD_COMMAND'] != 'FLUSH_CACHE' ) {
16-
return;
4+
if ( class_exists( 'WPaaS\Plugin' ) ) :
5+
6+
add_filter( 'rocket_display_varnish_options_tab', '__return_false' );
7+
add_filter( 'set_rocket_wp_cache_define', '__return_true' );
8+
9+
/**
10+
* Remove expiration on HTML to prevent issue with Varnish cache
11+
*
12+
* @since 2.9.5
13+
* @author Remy Perona
14+
*
15+
* @param string $rules htaccess rules.
16+
* @return Updated htaccess rules
17+
*/
18+
function rocket_remove_html_expire_goddady( $rules ) {
19+
$rules = <<<HTACCESS
20+
# Expires headers (for better cache control)
21+
<IfModule mod_expires.c>
22+
ExpiresActive on
23+
# Perhaps better to whitelist expires rules? Perhaps.
24+
ExpiresDefault "access plus 1 month"
25+
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
26+
ExpiresByType text/cache-manifest "access plus 0 seconds"
27+
# Data
28+
ExpiresByType text/xml "access plus 0 seconds"
29+
ExpiresByType application/xml "access plus 0 seconds"
30+
ExpiresByType application/json "access plus 0 seconds"
31+
# Feed
32+
ExpiresByType application/rss+xml "access plus 1 hour"
33+
ExpiresByType application/atom+xml "access plus 1 hour"
34+
# Favicon (cannot be renamed)
35+
ExpiresByType image/x-icon "access plus 1 week"
36+
# Media: images, video, audio
37+
ExpiresByType image/gif "access plus 1 month"
38+
ExpiresByType image/png "access plus 1 month"
39+
ExpiresByType image/jpeg "access plus 1 month"
40+
ExpiresByType video/ogg "access plus 1 month"
41+
ExpiresByType audio/ogg "access plus 1 month"
42+
ExpiresByType video/mp4 "access plus 1 month"
43+
ExpiresByType video/webm "access plus 1 month"
44+
# HTC files (css3pie)
45+
ExpiresByType text/x-component "access plus 1 month"
46+
# Webfonts
47+
ExpiresByType application/x-font-ttf "access plus 1 month"
48+
ExpiresByType font/opentype "access plus 1 month"
49+
ExpiresByType application/x-font-woff "access plus 1 month"
50+
ExpiresByType application/x-font-woff2 "access plus 1 month"
51+
ExpiresByType image/svg+xml "access plus 1 month"
52+
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
53+
# CSS and JavaScript
54+
ExpiresByType text/css "access plus 1 year"
55+
ExpiresByType application/javascript "access plus 1 year"
56+
</IfModule>
57+
58+
HTACCESS;
59+
60+
return $rules;
61+
}
62+
add_filter('rocket_htaccess_mod_expires', 'rocket_remove_html_expire_goddady');
63+
64+
/**
65+
* Call the Varnish server to purge the cache with GoDaddy.
66+
*
67+
* @since 2.9.5
68+
*
69+
* @return void
70+
*/
71+
function rocket_clean_domain_godaddy() {
72+
rocket_godaddy_request( 'BAN' );
73+
}
74+
add_action( 'before_rocket_clean_domain', 'rocket_clean_domain_godaddy' );
75+
76+
/**
77+
* Call the Varnish server to purge a specific URL with GoDaddy.
78+
*
79+
* @since 2.9.5
80+
*
81+
* @return void
82+
*/
83+
function rocket_clean_file_godaddy( $url ) {
84+
rocket_godaddy_request( 'PURGE', home_url( $url ) );
1785
}
18-
19-
if ( wp_verify_nonce( $_REQUEST['GD_NONCE'], 'GD_FLUSH_CACHE' ) ) {
20-
// Clear all caching files
21-
rocket_clean_domain();
22-
23-
// Preload cache
24-
run_rocket_preload_cache( 'cache-preload' );
86+
add_action( 'before_rocket_clean_file', 'rocket_clean_file_godaddy' );
87+
88+
/**
89+
* Call the Varnish server to purge the home with GoDaddy.
90+
*
91+
* @since 2.9.5
92+
*
93+
* @return void
94+
*/
95+
function rocket_clean_home_godaddy( $root, $lang ) {
96+
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
97+
$home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base );
98+
99+
rocket_godaddy_request( 'PURGE', $home_url );
100+
rocket_godaddy_request( 'PURGE', $home_pagination_url );
25101
}
26-
}
27-
28-
/* @since 2.6.5
29-
* For not conflit with GoDaddy
30-
*/
31-
add_action( 'after_rocket_clean_domain', 'rocket_clean_godaddy' );
32-
33-
/**
34-
* Call the cache server to purge the cache with GoDaddy hosting.
35-
*
36-
* @since 2.6.5
37-
*
38-
* @return void
39-
*/
40-
function rocket_clean_godaddy() {
41-
global $gd_cache_purge;
42-
43-
if( is_a( $gd_cache_purge, 'GD_System_Plugin_Cache_Purge' ) && method_exists( 'GD_System_Plugin_Cache_Purge', 'ban_cache' ) ) {
44-
$gd_cache_purge->ban_cache();
102+
add_action( 'before_rocket_clean_home', 'rocket_clean_home_godaddy', 10, 2 );
103+
104+
/**
105+
* Perform the call to the Varnish server to purge
106+
*
107+
* @since 2.9.5
108+
* @source WPaaS\Cache
109+
*
110+
* @param string $method can be BAN or PURGE.
111+
* @param string $url URL to purge.
112+
* @return void
113+
*/
114+
function rocket_godaddy_request( $method, $url = null ) {
115+
$url = empty( $url ) ? home_url() : $url;
116+
$host = parse_url( $url, PHP_URL_HOST );
117+
$url = set_url_scheme( str_replace( $host, WPaas\Plugin::vip(), $url ), 'http' );
118+
119+
wp_cache_flush();
120+
121+
// This forces the APC cache to flush across the server
122+
update_option( 'gd_system_last_cache_flush', time() );
123+
124+
wp_remote_request(
125+
esc_url_raw( $url ),
126+
array(
127+
'method' => $method,
128+
'blocking' => false,
129+
'headers' => array(
130+
'Host' => $host,
131+
),
132+
)
133+
);
45134
}
46-
}
47135

48-
endif;
136+
endif;

inc/admin/ui/css/admin.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ p.description.file-error{color:#F00}
1414
.rocket-renew{font-weight:400}
1515
.rkt-disabled{color:#CCC}
1616
.rkt-note{font-style:italic; font-weight:bold; font-size:smaller}
17-
.rkt-imagify-notice.rkt-imagify-notice{position:relative; display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex; -webkit-box-align:center; -webkit-align-items:center; -ms-flex-align:center; -ms-grid-row-align:center; align-items:center; padding:5px 45px 5px 0; border:0 none; box-shadow:none; color:#FFF; background:#2e3243}
17+
.rkt-imagify-notice.rkt-imagify-notice{position:relative; display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex; -webkit-box-align:center; -webkit-align-items:center; -ms-flex-align:center; -ms-grid-row-align:center; align-items:center; float:none; width:auto; padding:5px 45px 5px 0; border:0 none; box-shadow:none; color:#FFF; background:#2e3243}
1818
.rkt-imagify-notice .rkt-cross{position:absolute; right:8px; top:50%; width:22px; height:22px; padding:0; margin-top:-11px; background:#FFF; color:#2e3243; border-radius:50%; transition:all .275s}
1919
.rkt-imagify-notice .rkt-cross .dashicons{position:relative; top:2px; left:1px; transition:all .275s}
2020
.rkt-imagify-notice .rkt-cross:hover{background:#2e3243}
2121
.rkt-imagify-notice .rkt-cross:hover .dashicons{color:#FFF}
2222
.rkt-imagify-notice .rkt-imagify-logo, .rkt-imagify-notice .rkt-imagify-cta{-webkit-flex-shrink: 0;-ms-flex-negative: 0;flex-shrink: 0;}
2323
.rkt-imagify-notice .rkt-imagify-logo{width:160px!important; text-align:right; padding:0 15px; line-height:0.8}
2424
.rkt-imagify-notice .rkt-imagify-msg{width:100%!important; padding:0 15px; }
25-
.rkt-imagify-notice .rkt-imagify-cta{width:200px;!important; -webkit-box-flex: 1; -webkit-flex-grow: 1; -ms-flex-positive: 1; flex-grow: 1; -webkit-flex-basis: 200px; -ms-flex-preferred-size: 200px; flex-basis: 200px; }
25+
.rkt-imagify-notice .rkt-imagify-cta{padding-top: 7px; -webkit-box-flex: 1; -webkit-flex-grow: 1; -ms-flex-positive: 1; flex-grow: 1; -webkit-flex-basis: 200px; -ms-flex-preferred-size: 200px; flex-basis: 200px; }
2626
.rkt-imagify-notice .button.button{height:auto; font-weight:600; font-size:14px; box-shadow:0 3px 0 rgba(0,0,0,.15); border:0 none; padding:4px 18px; background:#40B1D0; text-shadow:1px 1px 1px rgba(0,0,0,.2)}
27+
.rkt-imagify-cta .thickbox{display: inline-block;margin-top:.5em;color:rgba(255,255,255,.5);}
2728
@media (max-width:650px){.rkt-imagify-notice{-webkit-flex-wrap:wrap; -ms-flex-wrap:wrap; flex-wrap:wrap}
2829
.rkt-imagify-notice .rkt-imagify-msg,
2930
.rkt-imagify-notice .rkt-imagify-cta,

inc/admin/ui/enqueue.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ function __rocket_admin_print_styles() {
8989
add_action( 'admin_print_styles-upload.php', '__rocket_enqueue_modal_plugin' );
9090
add_action( 'admin_print_styles-settings_page_' . WP_ROCKET_PLUGIN_SLUG, '__rocket_enqueue_modal_plugin' );
9191
function __rocket_enqueue_modal_plugin() {
92-
wp_enqueue_style( 'thickbox' );
9392
wp_enqueue_style( 'plugin-install' );
9493

9594
wp_enqueue_script( 'plugin-install' );
96-
wp_enqueue_script( 'tgm-modal-wp-rocket', WP_ROCKET_ADMIN_UI_JS_URL . 'vendors/tgm-modal.min.js', array( 'jquery' ), WP_ROCKET_VERSION, true );
97-
}
95+
wp_enqueue_script( 'updates' );
96+
add_thickbox();
97+
}

inc/admin/ui/js/vendors/tgm-modal.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

inc/admin/ui/notices.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,15 @@ function __rocket_imagify_notice() {
527527
$action_url = $is_imagify_installed ?
528528
rocket_get_plugin_activation_link( $imagify_plugin )
529529
:
530-
add_query_arg(
530+
wp_nonce_url( add_query_arg(
531+
array(
532+
'action' => 'install-plugin',
533+
'plugin' => 'imagify',
534+
),
535+
admin_url( 'update.php' )
536+
), 'install-plugin_imagify' );
537+
538+
$details_url = add_query_arg(
531539
array(
532540
'tab' => 'plugin-information',
533541
'plugin' => 'imagify',
@@ -538,7 +546,7 @@ function __rocket_imagify_notice() {
538546
admin_url( 'plugin-install.php' )
539547
);
540548

541-
$classes = $is_imagify_installed ? '' : ' tgm-plugin-update-modal';
549+
$classes = $is_imagify_installed ? '' : ' install-now';
542550
$cta_txt = $is_imagify_installed ? esc_html__( 'Activate Imagify', 'rocket' ) : esc_html__( 'Install Imagify for Free', 'rocket' );
543551

544552
$dismiss_url = wp_nonce_url(
@@ -547,7 +555,7 @@ function __rocket_imagify_notice() {
547555
);
548556
?>
549557

550-
<div class="updated rkt-imagify-notice">
558+
<div id="plugin-filter" class="updated plugin-card plugin-card-imagify rkt-imagify-notice">
551559
<a href="<?php echo $dismiss_url; ?>" class="rkt-cross"><span class="dashicons dashicons-no"></span></a>
552560

553561
<p class="rkt-imagify-logo">
@@ -557,7 +565,10 @@ function __rocket_imagify_notice() {
557565
<?php _e( 'Speed up your website and boost your SEO by reducing image file sizes without losing quality with Imagify.', 'rocket' ); ?>
558566
</p>
559567
<p class="rkt-imagify-cta">
560-
<a href="<?php echo $action_url; ?>" class="button button-primary<?php echo $classes; ?>"><?php echo $cta_txt; ?></a>
568+
<a data-slug="imagify" href="<?php echo $action_url; ?>" class="button button-primary<?php echo $classes; ?>"><?php echo $cta_txt; ?></a>
569+
<?php if ( ! $is_imagify_installed ) : ?>
570+
<br><a data-slug="imagify" data-name="Imagify Image Optimizer" class="thickbox open-plugin-details-modal" href="<?php echo $details_url; ?>"><?php _e( 'More details', 'rocket' ); ?></a>
571+
<?php endif; ?>
561572
</p>
562573
</div>
563574

@@ -641,4 +652,4 @@ function rocket_cloudflare_update_settings() {
641652
</div>
642653
<?php }
643654
}
644-
}
655+
}

inc/front/cdn.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function rocket_cdn_images( $html ) {
136136
list( $host, $path, $scheme, $query ) = get_rocket_parse_url( $image_url );
137137
$path = trim( $path );
138138

139-
if ( empty( $path ) || '{href}' === $path ) {
139+
if ( empty( $path ) || '{href}' === $path || '+markerData[i].thumbnail+' === $path ) {
140140
continue;
141141
}
142142

@@ -211,7 +211,12 @@ function rocket_cdn_inline_styles( $html ) {
211211
if ( ( bool ) $matches ) {
212212
$i = 0;
213213
foreach( $matches[1] as $url ) {
214-
$url = trim( $url, " \t\n\r\0\x0B\"'&quot;#039;" );
214+
$url = str_replace( array( ' ', '\t', '\n', '\r', '\0', '\x0B', '"', "'", '&quot;', '#039;' ), '', $url );
215+
216+
if ( '#' === substr( $url, 0, 1 ) ) {
217+
continue;
218+
}
219+
215220
$url = get_rocket_cdn_url( $url, $zone );
216221
$property = str_replace( $matches[1][$i], $url, $matches[0][$i] );
217222
$html = str_replace( $matches[0][$i], $property, $html );

0 commit comments

Comments
 (0)