W3 Total Cache - Version 2.2.1

Version Description

Download this release

Release Info

Developer joemoto
Plugin Icon 128x128 W3 Total Cache
Version 2.2.1
Comparing to
See all releases

Code changes from version 2.2.0 to 2.2.1

CdnEngine_Mirror_CloudFront.php CHANGED
@@ -80,7 +80,7 @@ class CdnEngine_Mirror_CloudFront extends CdnEngine_Mirror {
80
  }
81
 
82
  try {
83
- $invalidation = $this->api->createInvalidationAsync( array(
84
  'DistributionId' => $dist['Id'],
85
  'InvalidationBatch' => array(
86
  'CallerReference' => 'w3tc-' . microtime(),
80
  }
81
 
82
  try {
83
+ $invalidation = $this->api->createInvalidation( array(
84
  'DistributionId' => $dist['Id'],
85
  'InvalidationBatch' => array(
86
  'CallerReference' => 'w3tc-' . microtime(),
Extension_CloudFlare_Api.php CHANGED
@@ -31,33 +31,6 @@ class Extension_CloudFlare_Api {
31
 
32
 
33
 
34
- /**
35
- * Makes ip_lkup API request
36
- *
37
- * @param string $ip
38
- * @return object
39
- */
40
- public function ip_lkup( $ip ) {
41
- @set_time_limit( $this->_timelimit_api_request );
42
-
43
- $response = Util_Http::request(
44
- 'https://www.cloudflare.com/api_json.html', array(
45
- 'method' => 'POST',
46
- 'body' => array(
47
- 'a' => 'ip_lkup',
48
- 'tkn' => $this->_key,
49
- 'email' => $this->_email,
50
- 'ip' => $ip
51
- )
52
- ) );
53
- if ( isset( $response['body'] ) )
54
- return @json_decode( $response['body'] );
55
-
56
- return null;
57
- }
58
-
59
-
60
-
61
  /**
62
  * Makes external event request
63
  *
31
 
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  /**
35
  * Makes external event request
36
  *
Extension_CloudFlare_Page_View.php CHANGED
@@ -131,6 +131,15 @@ CloudFlare not available: <?php echo $error_message; ?>
131
  )
132
  );
133
 
 
 
 
 
 
 
 
 
 
134
  ?>
135
  </table>
136
  <?php endif; ?>
131
  )
132
  );
133
 
134
+ Util_Ui::config_item( array(
135
+ 'key' => array( 'cloudflare', 'minify_js_rl_exclude' ),
136
+ 'label' => __( 'Minified JS Rocket Loader Exclude:', 'w3-total-cache' ),
137
+ 'checkbox_label' => 'Exclude minified JS files from being processed by Rocket Loader:',
138
+ 'control' => 'checkbox',
139
+ 'description' => 'Exclusion achieved by adding data-cfasync="false" to script tags.'
140
+ )
141
+ );
142
+
143
  ?>
144
  </table>
145
  <?php endif; ?>
Extension_CloudFlare_Plugin_Admin.php CHANGED
@@ -111,16 +111,6 @@ class Extension_CloudFlare_Plugin_Admin {
111
  ) );
112
  }
113
 
114
- // add check to comments page
115
- add_filter( 'comment_row_actions', array( $this, 'comment_row_actions' ),
116
- 10, 2 );
117
- add_action( 'admin_print_styles-edit-comments.php',
118
- array( $this, 'admin_print_styles_edit_comments' ) );
119
- add_action( 'admin_print_scripts-edit-comments.php',
120
- array( $this, 'admin_print_scripts_edit_comments' ) );
121
- add_action( 'wp_ajax_w3tc_cloudflare_ip_check',
122
- array( $this, 'w3tc_cloudflare_ip_check' ) );
123
-
124
  // add notices about api health
125
  if ( Util_Admin::is_w3tc_admin_page() ) {
126
  add_action( 'admin_notices', array(
@@ -352,64 +342,4 @@ class Extension_CloudFlare_Plugin_Admin {
352
  $config = $this->_config;
353
  include W3TC_DIR . '/Extension_CloudFlare_GeneralPage_View.php';
354
  }
355
-
356
-
357
-
358
- /**
359
- * Comments page modification
360
- */
361
- public function comment_row_actions( $actions, $comment_id ) {
362
- $ip = get_comment_author_IP( $comment_id );
363
- if ( !empty( $ip ) )
364
- $actions[] = '<a href="#ip=' . urlencode( $ip ) .
365
- '" class="w3tc_cloudflare_ip_check">CloudFlare IP score</a>';
366
- return $actions;
367
- }
368
-
369
-
370
-
371
- public function admin_print_styles_edit_comments() {
372
- wp_enqueue_style( 'w3tc_extension_cloudflare_general',
373
- plugins_url( 'Extension_CloudFlare_View_Comments.css', W3TC_FILE ) );
374
- }
375
-
376
-
377
-
378
- public function admin_print_scripts_edit_comments() {
379
- wp_enqueue_script( 'w3tc_extension_cloudflare_general',
380
- plugins_url( 'Extension_CloudFlare_View_Comments.js', W3TC_FILE ),
381
- array( 'jquery' ), '1.0' );
382
- }
383
-
384
-
385
-
386
- public function w3tc_cloudflare_ip_check() {
387
- $api = new Extension_CloudFlare_Api();
388
-
389
- $ip = $_REQUEST['ip'];
390
- $response = $this->api->ip_lkup( $ip );
391
-
392
- $error = true;
393
-
394
- //var_dump($response);
395
- if ( !isset( $response->result ) )
396
- $message = 'API failed';
397
- else if ( $response->result != 'success' )
398
- $message = 'API error: ' . $response->msg;
399
- else if ( !isset( $response->response ) || !isset( $response->response->$ip ) )
400
- $message = 'no information';
401
- else if ( !$response->response->$ip ) {
402
- $message = 'valid IP';
403
- $error = false;
404
- } else
405
- $message = 'invalid IP';
406
-
407
- echo json_encode( array(
408
- 'message' => $message,
409
- 'error' => $error
410
- ) );
411
-
412
- exit();
413
- }
414
-
415
  }
111
  ) );
112
  }
113
 
 
 
 
 
 
 
 
 
 
 
114
  // add notices about api health
115
  if ( Util_Admin::is_w3tc_admin_page() ) {
116
  add_action( 'admin_notices', array(
342
  $config = $this->_config;
343
  include W3TC_DIR . '/Extension_CloudFlare_GeneralPage_View.php';
344
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  }
Extension_CloudFlare_View_Comments.css DELETED
@@ -1,17 +0,0 @@
1
- .cloudflare_ip_check {
2
- padding-left: 10px;
3
- }
4
-
5
- img.cloudflare_ip_check_img {
6
- float: none;
7
- vertical-align:middle;
8
- padding-bottom: 2px;
9
- }
10
-
11
- .cloudflare_ip_check_error {
12
- color: #990000;
13
- }
14
-
15
- .cloudflare_ip_check_success {
16
- color: #009900;
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Extension_CloudFlare_View_Comments.js DELETED
@@ -1,65 +0,0 @@
1
- jQuery(function($) {
2
- $('.w3tc_cloudflare_ip_check').click(function(e) {
3
- var href = $(this).attr('href');
4
- if (href.substr(0, 4) != '#ip=')
5
- return;
6
-
7
- e.preventDefault();
8
-
9
- var ip = unescape(href.substr(4));
10
- var tr = $(this).parent().closest('tr');
11
- var ip_span = tr.find('.cloudflare_ip_check');
12
- if (ip_span.length <= 0) {
13
- tr.find('.column-author').append(
14
- '<span class="cloudflare_ip_check"></span>');
15
- ip_span = tr.find('.cloudflare_ip_check');
16
- }
17
-
18
- ip_span.empty();
19
- $('<img>')
20
- .attr('class', 'cloudflare_ip_check_img')
21
- .attr('src', 'images/wpspin_light.gif')
22
- .attr('alt', 'Resolving IP ' + ip)
23
- .appendTo(ip_span);
24
-
25
- jQuery.post(ajaxurl, {
26
- action:'w3tc_cloudflare_ip_check',
27
- ip: ip
28
- }, null, 'json')
29
- .done(function(data) {
30
- ip_span.empty();
31
- var className = (data.error ? 'cloudflare_ip_check_error' :
32
- 'cloudflare_ip_check_success');
33
- ip_span.html('<span class="' + className + '">' +
34
- data.message + '</span>');
35
- })
36
- .fail(function() {
37
- ip_span.html('<span class="cloudflare_ip_check_error">check failed</span>');
38
- });
39
- });
40
- });
41
-
42
- function w3tc_cloudflare_api_request(action, value, nonce) {
43
- var email = jQuery('input[id="cloudflare.email"]');
44
- var key = jQuery('input[id="cloudflare.key"]');
45
- var zone = jQuery('input[id="cloudflare.zone"]');
46
-
47
- if (!email.val()) {
48
- alert('Please enter CloudFlare E-Mail.');
49
- email.focus();
50
- return false;
51
- }
52
-
53
- if (!key.val()) {
54
- alert('Please enter CloudFlare API key.');
55
- key.focus();
56
- return false;
57
- }
58
-
59
- if (!zone.val()) {
60
- alert('Please enter CloudFlare zone.');
61
- zone.focus();
62
- return false;
63
- }
64
-
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Extension_ImageService_Api.php CHANGED
@@ -109,6 +109,14 @@ class Extension_ImageService_Api {
109
  * @return array
110
  */
111
  public function convert( $filepath, array $options = array() ) {
 
 
 
 
 
 
 
 
112
  $config = Dispatcher::config();
113
  $settings = $config->get_array( 'imageservice' );
114
  $options = array_merge(
@@ -137,6 +145,7 @@ class Extension_ImageService_Api {
137
  $body .= 'Content-Disposition: form-data; name="image"; filename="' . basename( $filepath ) . '"' . "\r\n\r\n";
138
  $body .= file_get_contents( $filepath ) . "\r\n" . '--' . $boundary . '--'; // phpcs:ignore WordPress.WP.AlternativeFunctions
139
 
 
140
  $response = wp_remote_request(
141
  $this->get_base_url() . $this->endpoints['convert']['uri'],
142
  array(
@@ -151,6 +160,7 @@ class Extension_ImageService_Api {
151
  )
152
  );
153
 
 
154
  if ( is_wp_error( $response ) ) {
155
  return array(
156
  'error' => __( 'WP Error: ', 'w3-total-cache' ) . $response->get_error_message(),
@@ -178,8 +188,10 @@ class Extension_ImageService_Api {
178
  // Handle non-200 response codes.
179
  if ( 200 !== $response['response']['code'] ) {
180
  $result = array(
181
- 'code' => $response['response']['code'],
182
- 'error' => esc_html__( 'Error: Received a non-200 response code: ', 'w3-total-cache' ) . $response['response']['code'],
 
 
183
  );
184
 
185
  if ( isset( $response_body['error']['id'] ) && 'exceeded-hourly' === $response_body['error']['id'] ) {
@@ -195,6 +207,7 @@ class Extension_ImageService_Api {
195
  '</a>'
196
  )
197
  );
 
198
  } elseif ( isset( $response_body['error']['id'] ) && 'exceeded-monthly' === $response_body['error']['id'] ) {
199
  $result['message'] = sprintf(
200
  // translators: 1: Monthly request limit, 2: HTML anchor open tag, 3: HTML anchor close tag.
@@ -203,6 +216,7 @@ class Extension_ImageService_Api {
203
  '<a href="#" class="button-buy-plugin" data-src="imageservice_api_limit">',
204
  '</a>'
205
  );
 
206
  } elseif ( isset( $response_body['error']['id'] ) && 'invalid-output-mime' === $response_body['error']['id'] ) {
207
  $result['message'] = esc_html__( 'Invalid output image MIME type.', 'w3-total-cache' );
208
  } elseif ( isset( $response_body['error']['id'] ) && 'missing-image' === $response_body['error']['id'] ) {
109
  * @return array
110
  */
111
  public function convert( $filepath, array $options = array() ) {
112
+ // Abort if rate-limit exceeded.
113
+ $result = get_transient( 'w3tc_imageservice_limited' );
114
+
115
+ if ( ! empty( $result ) ) {
116
+ return $result;
117
+ }
118
+
119
+ // Prepare request.
120
  $config = Dispatcher::config();
121
  $settings = $config->get_array( 'imageservice' );
122
  $options = array_merge(
145
  $body .= 'Content-Disposition: form-data; name="image"; filename="' . basename( $filepath ) . '"' . "\r\n\r\n";
146
  $body .= file_get_contents( $filepath ) . "\r\n" . '--' . $boundary . '--'; // phpcs:ignore WordPress.WP.AlternativeFunctions
147
 
148
+ // Send request.
149
  $response = wp_remote_request(
150
  $this->get_base_url() . $this->endpoints['convert']['uri'],
151
  array(
160
  )
161
  );
162
 
163
+ // Examine response.
164
  if ( is_wp_error( $response ) ) {
165
  return array(
166
  'error' => __( 'WP Error: ', 'w3-total-cache' ) . $response->get_error_message(),
188
  // Handle non-200 response codes.
189
  if ( 200 !== $response['response']['code'] ) {
190
  $result = array(
191
+ 'code' => $response['response']['code'],
192
+ 'error' => esc_html__( 'Error: Received a non-200 response code: ', 'w3-total-cache' ) . $response['response']['code'],
193
+ 'status' => 'error',
194
+ 'time' => time(),
195
  );
196
 
197
  if ( isset( $response_body['error']['id'] ) && 'exceeded-hourly' === $response_body['error']['id'] ) {
207
  '</a>'
208
  )
209
  );
210
+ set_transient( 'w3tc_imageservice_limited', $result, 5 * MINUTE_IN_SECONDS );
211
  } elseif ( isset( $response_body['error']['id'] ) && 'exceeded-monthly' === $response_body['error']['id'] ) {
212
  $result['message'] = sprintf(
213
  // translators: 1: Monthly request limit, 2: HTML anchor open tag, 3: HTML anchor close tag.
216
  '<a href="#" class="button-buy-plugin" data-src="imageservice_api_limit">',
217
  '</a>'
218
  );
219
+ set_transient( 'w3tc_imageservice_limited', $result, DAY_IN_SECONDS );
220
  } elseif ( isset( $response_body['error']['id'] ) && 'invalid-output-mime' === $response_body['error']['id'] ) {
221
  $result['message'] = esc_html__( 'Invalid output image MIME type.', 'w3-total-cache' );
222
  } elseif ( isset( $response_body['error']['id'] ) && 'missing-image' === $response_body['error']['id'] ) {
Extension_ImageService_Plugin_Admin.js CHANGED
@@ -572,7 +572,12 @@
572
  })
573
  .done( function( response ) {
574
  if ( response.success ) {
575
- $this.text( w3tcData.lang.processing );
 
 
 
 
 
576
  refreshStats();
577
  refreshUsage();
578
  } else if ( response.data && response.data.hasOwnProperty( 'error' ) ) {
572
  })
573
  .done( function( response ) {
574
  if ( response.success ) {
575
+ $this.text( w3tcData.lang.submitted );
576
+ $parent.append(
577
+ '<div class="notice notice-info inline">' +
578
+ w3tcData.lang.submittedAllDesc +
579
+ '</div>'
580
+ );
581
  refreshStats();
582
  refreshUsage();
583
  } else if ( response.data && response.data.hasOwnProperty( 'error' ) ) {
Extension_ImageService_Plugin_Admin.php CHANGED
@@ -529,6 +529,7 @@ class Extension_ImageService_Plugin_Admin {
529
  'lang' => array(
530
  'convert' => __( 'Convert', 'w3-total_cache' ),
531
  'sending' => __( 'Sending...', 'w3-total_cache' ),
 
532
  'processing' => __( 'Processing...', 'w3-total_cache' ),
533
  'converted' => __( 'Converted', 'w3-total_cache' ),
534
  'notConverted' => __( 'Not converted', 'w3-total_cache' ),
@@ -541,6 +542,12 @@ class Extension_ImageService_Plugin_Admin {
541
  'refresh' => __( 'Refresh', 'w3-total_cache' ),
542
  'refreshing' => __( 'Refreshing...', 'w3-total_cache' ),
543
  'settings' => __( 'Settings', 'w3-total_cache' ),
 
 
 
 
 
 
544
  'notConvertedDesc' => sprintf(
545
  // translators: 1: HTML anchor open tag, 2: HTML anchor close tag.
546
  __( 'The converted image would be larger than the original; conversion canceled. %1$sLearn more%2$s.', 'w3-total_cache' ),
@@ -913,7 +920,18 @@ class Extension_ImageService_Plugin_Admin {
913
  * @return array
914
  */
915
  public function submit_images( array $post_ids ) {
916
- WP_Filesystem();
 
 
 
 
 
 
 
 
 
 
 
917
  global $wp_filesystem;
918
 
919
  $stats = array(
@@ -1108,8 +1126,17 @@ class Extension_ImageService_Plugin_Admin {
1108
  public function ajax_submit() {
1109
  check_ajax_referer( 'w3tc_imageservice_submit' );
1110
 
1111
- WP_Filesystem();
1112
- global $wp_filesystem;
 
 
 
 
 
 
 
 
 
1113
 
1114
  // Check for post id.
1115
  $post_id = isset( $_POST['post_id'] ) ? (int) sanitize_key( $_POST['post_id'] ) : null;
@@ -1123,6 +1150,8 @@ class Extension_ImageService_Plugin_Admin {
1123
  );
1124
  }
1125
 
 
 
1126
  // Verify the image file exists.
1127
  $filepath = get_attached_file( $post_id );
1128
 
529
  'lang' => array(
530
  'convert' => __( 'Convert', 'w3-total_cache' ),
531
  'sending' => __( 'Sending...', 'w3-total_cache' ),
532
+ 'submitted' => __( 'Submitted', 'w3-total_cache' ),
533
  'processing' => __( 'Processing...', 'w3-total_cache' ),
534
  'converted' => __( 'Converted', 'w3-total_cache' ),
535
  'notConverted' => __( 'Not converted', 'w3-total_cache' ),
542
  'refresh' => __( 'Refresh', 'w3-total_cache' ),
543
  'refreshing' => __( 'Refreshing...', 'w3-total_cache' ),
544
  'settings' => __( 'Settings', 'w3-total_cache' ),
545
+ 'submittedAllDesc' => sprintf(
546
+ // translators: 1: HTML anchor open tag, 2: HTML anchor close tag.
547
+ __( 'Images queued for conversion. Progress can be seen in the %1$sMedia Library%2$s.', 'w3-total_cache' ),
548
+ '<a href="' . esc_url( Util_Ui::admin_url( 'upload.php?mode=list' ) ) . '">',
549
+ '</a>'
550
+ ),
551
  'notConvertedDesc' => sprintf(
552
  // translators: 1: HTML anchor open tag, 2: HTML anchor close tag.
553
  __( 'The converted image would be larger than the original; conversion canceled. %1$sLearn more%2$s.', 'w3-total_cache' ),
920
  * @return array
921
  */
922
  public function submit_images( array $post_ids ) {
923
+ // Check WP_Filesystem credentials.
924
+ Util_WpFile::ajax_check_credentials(
925
+ sprintf(
926
+ // translators: 1: HTML achor open tag, 2: HTML anchor close tag.
927
+ __( '%1$sLearn more%2$s.', 'w3-total-cache' ),
928
+ '<a target="_blank" href="' . esc_url(
929
+ 'https://www.boldgrid.com/support/w3-total-cache/image-service/?utm_source=w3tc&utm_medium=conversion_error&utm_campaign=imageservice#unable-to-connect-to-the-filesystem-error'
930
+ ) . '">',
931
+ '</a>'
932
+ )
933
+ );
934
+
935
  global $wp_filesystem;
936
 
937
  $stats = array(
1126
  public function ajax_submit() {
1127
  check_ajax_referer( 'w3tc_imageservice_submit' );
1128
 
1129
+ // Check WP_Filesystem credentials.
1130
+ Util_WpFile::ajax_check_credentials(
1131
+ sprintf(
1132
+ // translators: 1: HTML achor open tag, 2: HTML anchor close tag.
1133
+ __( '%1$sLearn more%2$s.', 'w3-total-cache' ),
1134
+ '<a target="_blank" href="' . esc_url(
1135
+ 'https://www.boldgrid.com/support/w3-total-cache/image-service/?utm_source=w3tc&utm_medium=conversion_error&utm_campaign=imageservice#unable-to-connect-to-the-filesystem-error'
1136
+ ) . '">',
1137
+ '</a>'
1138
+ )
1139
+ );
1140
 
1141
  // Check for post id.
1142
  $post_id = isset( $_POST['post_id'] ) ? (int) sanitize_key( $_POST['post_id'] ) : null;
1150
  );
1151
  }
1152
 
1153
+ global $wp_filesystem;
1154
+
1155
  // Verify the image file exists.
1156
  $filepath = get_attached_file( $post_id );
1157
 
Licensing_Plugin_Admin.php CHANGED
@@ -107,6 +107,8 @@ class Licensing_Plugin_Admin {
107
  $state = Dispatcher::config_state();
108
  $state->set( 'license.next_check', 0 );
109
  $state->save();
 
 
110
  }
111
  }
112
 
107
  $state = Dispatcher::config_state();
108
  $state->set( 'license.next_check', 0 );
109
  $state->save();
110
+
111
+ delete_transient( 'w3tc_imageservice_limited' );
112
  }
113
  }
114
 
Minify_Plugin.php CHANGED
@@ -1093,8 +1093,13 @@ class _W3_MinifyHelpers {
1093
  function generate_script_tag( $url, $embed_type = 'blocking' ) {
1094
  static $non_blocking_function = false;
1095
 
 
 
 
 
 
1096
  if ( $embed_type == 'blocking' ) {
1097
- $script = '<script src="' .
1098
  str_replace( '&', '&amp;', $url ) . '"></script>';
1099
  } else {
1100
  $script = '';
@@ -1109,19 +1114,19 @@ class _W3_MinifyHelpers {
1109
  $url . "');</script>";
1110
 
1111
  } elseif ( $embed_type == 'nb-async' ) {
1112
- $script = '<script async src="' .
1113
  str_replace( '&', '&amp;', $url ) . '"></script>';
1114
  } elseif ( $embed_type == 'nb-defer' ) {
1115
- $script = '<script defer src="' .
1116
  str_replace( '&', '&amp;', $url ) . '"></script>';
1117
  } elseif ( $embed_type == 'extsrc' ) {
1118
- $script = '<script extsrc="' .
1119
  str_replace( '&', '&amp;', $url ) . '"></script>';
1120
  } elseif ( $embed_type == 'asyncsrc' ) {
1121
- $script = '<script asyncsrc="' .
1122
  str_replace( '&', '&amp;', $url ) . '"></script>';
1123
  } else {
1124
- $script = '<script src="' .
1125
  str_replace( '&', '&amp;', $url ) . '"></script>';
1126
  }
1127
  }
1093
  function generate_script_tag( $url, $embed_type = 'blocking' ) {
1094
  static $non_blocking_function = false;
1095
 
1096
+ $rocket_loader_ignore = "";
1097
+ if( $this->config->get_boolean( array( 'cloudflare', 'minify_js_rl_exclude' ) ) ){
1098
+ $rocket_loader_ignore = 'data-cfasync="false"';
1099
+ }
1100
+
1101
  if ( $embed_type == 'blocking' ) {
1102
+ $script = '<script ' . $rocket_loader_ignore . ' src="' .
1103
  str_replace( '&', '&amp;', $url ) . '"></script>';
1104
  } else {
1105
  $script = '';
1114
  $url . "');</script>";
1115
 
1116
  } elseif ( $embed_type == 'nb-async' ) {
1117
+ $script = '<script ' . $rocket_loader_ignore . ' async src="' .
1118
  str_replace( '&', '&amp;', $url ) . '"></script>';
1119
  } elseif ( $embed_type == 'nb-defer' ) {
1120
+ $script = '<script ' . $rocket_loader_ignore . ' defer src="' .
1121
  str_replace( '&', '&amp;', $url ) . '"></script>';
1122
  } elseif ( $embed_type == 'extsrc' ) {
1123
+ $script = '<script ' . $rocket_loader_ignore . ' extsrc="' .
1124
  str_replace( '&', '&amp;', $url ) . '"></script>';
1125
  } elseif ( $embed_type == 'asyncsrc' ) {
1126
+ $script = '<script ' . $rocket_loader_ignore . ' asyncsrc="' .
1127
  str_replace( '&', '&amp;', $url ) . '"></script>';
1128
  } else {
1129
+ $script = '<script ' . $rocket_loader_ignore . ' src="' .
1130
  str_replace( '&', '&amp;', $url ) . '"></script>';
1131
  }
1132
  }
Util_File.php CHANGED
@@ -22,7 +22,7 @@ class Util_File {
22
 
23
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
24
 
25
- if ( !@is_dir( $curr_path ) ) {
26
  if ( !@mkdir( $curr_path, $mask ) ) {
27
  return false;
28
  }
@@ -61,7 +61,7 @@ class Util_File {
61
 
62
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
63
 
64
- if ( !@is_dir( $curr_path ) ) {
65
  if ( !@mkdir( $curr_path, $mask ) )
66
  return false;
67
  }
@@ -103,7 +103,7 @@ class Util_File {
103
 
104
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
105
 
106
- if ( !@is_dir( $curr_path ) ) {
107
  if ( !@mkdir( $curr_path, $mask ) )
108
  return false;
109
  }
22
 
23
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
24
 
25
+ if ( !@file_exists( $curr_path ) ) {
26
  if ( !@mkdir( $curr_path, $mask ) ) {
27
  return false;
28
  }
61
 
62
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
63
 
64
+ if ( !@file_exists( $curr_path ) ) {
65
  if ( !@mkdir( $curr_path, $mask ) )
66
  return false;
67
  }
103
 
104
  $curr_path .= ( $curr_path == '' ? '' : '/' ) . $dir;
105
 
106
+ if ( !@file_exists( $curr_path ) ) {
107
  if ( !@mkdir( $curr_path, $mask ) )
108
  return false;
109
  }
Util_WpFile.php CHANGED
@@ -1,7 +1,55 @@
1
  <?php
 
 
 
 
 
 
2
  namespace W3TC;
3
 
 
 
 
4
  class Util_WpFile {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  /**
6
  * Tries to write file content
7
  *
1
  <?php
2
+ /**
3
+ * File: Util_WpFile.php
4
+ *
5
+ * @package W3TC
6
+ */
7
+
8
  namespace W3TC;
9
 
10
+ /**
11
+ * Class: Util_WpFile
12
+ */
13
  class Util_WpFile {
14
+ /**
15
+ * Check WP_Filesystem credentials when running ajax.
16
+ *
17
+ * @since 2.2.1
18
+ *
19
+ * @param string $extra Extra markup for an error message.
20
+ */
21
+ public static function ajax_check_credentials( $extra = null ) {
22
+ $access_type = get_filesystem_method();
23
+ ob_start();
24
+ $credentials = request_filesystem_credentials(
25
+ site_url() . '/wp-admin/',
26
+ $access_type
27
+ );
28
+ ob_end_clean();
29
+
30
+ if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
31
+ global $wp_filesystem;
32
+
33
+ $status['error'] = sprintf(
34
+ // translators: 1: Filesystem access method: "direct", "ssh2", "ftpext" or "ftpsockets".
35
+ __(
36
+ 'Unable to connect to the filesystem (using %1$s). Please confirm your credentials. %2$s',
37
+ 'w3-total-cache'
38
+ ),
39
+ $access_type,
40
+ $extra
41
+ );
42
+
43
+ // Pass through the error from WP_Filesystem if one was raised.
44
+ if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) &&
45
+ $wp_filesystem->errors->has_errors() ) {
46
+ $status['error'] = esc_html( $wp_filesystem->errors->get_error_message() );
47
+ }
48
+
49
+ wp_send_json_error( $status );
50
+ }
51
+ }
52
+
53
  /**
54
  * Tries to write file content
55
  *
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Plugin Name ===
2
  Contributors: boldgrid, fredericktownes, maxicusc, gidomanders, bwmarkle, harryjackson1221, joemoto, vmarko, jacobd91
3
- Tags: seo, cache, CDN, pagespeed, caching, performance, compression, optimize, cloudflare, nginx, apache, varnish, redis, aws, amazon web services, s3, cloudfront, azure
4
  Requires at least: 3.8
5
- Tested up to: 5.8
6
- Stable tag: 2.2.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -63,7 +63,7 @@ https://youtu.be/7AsNSSrZq4Y
63
  * Reverse proxy integration via Nginx or Varnish
64
  * Image Service API extension provides WebP image format conversion from common image formats (on upload and on demand)
65
 
66
- Speed up your site tremendously, improve core web vitals and the overall user experience for your visitors without having to change your WordPress host, theme, plugins or your content production workflow.
67
 
68
  == Frequently Asked Questions ==
69
 
@@ -157,7 +157,7 @@ Use the "Help" button available on the Minify settings tab. Once open, the tool
157
 
158
  = I don't understand what a CDN has to do with caching, that's completely different, no? =
159
 
160
- Technically no, a CDN is a high performance cache that stores static assets (your theme files, media library etc) in various locations throughout the world in order to provide low latency access to them by readers in those regions. Use Total Cache to accelerate your site by putting your content closer to your users with our many CDN integrations including Cloudflare, StackPath, AWS and more.
161
 
162
  = How do I use an Origin Pull (Mirror) CDN? =
163
  Login to your CDN providers control panel or account management area. Following any set up steps they provide, create a new "pull zone" or "bucket" for your site's domain name. If there's a set up wizard or any troubleshooting tips your provider offers, be sure to review them. In the CDN tab of the plugin, enter the hostname your CDN provider provided in the "replace site's hostname with" field. You should always do a quick check by opening a test file from the CDN hostname, e.g. http://cdn.domain.com/favicon.ico. Troubleshoot with your CDN provider until this test is successful.
@@ -216,7 +216,7 @@ First, make sure the plugin is not active (disabled) network-wide. Then make sur
216
 
217
  = A notification about file owner appears along with an FTP form, how can I resolve this? =
218
 
219
- The plugin uses WordPress FileSystem functionality to write to files. It checks if the file owner, file owner group of created files match process owner. If this is not the case it cannot write or modify files.
220
 
221
  Typically, you should tell your web host about the permission issue and they should be able to resolve it.
222
 
@@ -285,6 +285,14 @@ Please reach out to all of these people and support their projects if you're so
285
 
286
  == Changelog ==
287
 
 
 
 
 
 
 
 
 
288
  = 2.2.0 =
289
  * Feature: Image Service API extension: WebP conversion options
290
 
1
  === Plugin Name ===
2
  Contributors: boldgrid, fredericktownes, maxicusc, gidomanders, bwmarkle, harryjackson1221, joemoto, vmarko, jacobd91
3
+ Tags: seo, cache, CDN, pagespeed, caching, performance, compression, optimize, cloudflare, nginx, apache, varnish, redis, aws, amazon web services, s3, cloudfront, azure
4
  Requires at least: 3.8
5
+ Tested up to: 6.0
6
+ Stable tag: 2.2.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
63
  * Reverse proxy integration via Nginx or Varnish
64
  * Image Service API extension provides WebP image format conversion from common image formats (on upload and on demand)
65
 
66
+ Speed up your site tremendously, improve core web vitals and the overall user experience for your visitors without having to change your WordPress host, theme, plugins or your content production workflow.
67
 
68
  == Frequently Asked Questions ==
69
 
157
 
158
  = I don't understand what a CDN has to do with caching, that's completely different, no? =
159
 
160
+ Technically no, a CDN is a high performance cache that stores static assets (your theme files, media library etc) in various locations throughout the world in order to provide low latency access to them by readers in those regions. Use Total Cache to accelerate your site by putting your content closer to your users with our many CDN integrations including Cloudflare, StackPath, AWS and more.
161
 
162
  = How do I use an Origin Pull (Mirror) CDN? =
163
  Login to your CDN providers control panel or account management area. Following any set up steps they provide, create a new "pull zone" or "bucket" for your site's domain name. If there's a set up wizard or any troubleshooting tips your provider offers, be sure to review them. In the CDN tab of the plugin, enter the hostname your CDN provider provided in the "replace site's hostname with" field. You should always do a quick check by opening a test file from the CDN hostname, e.g. http://cdn.domain.com/favicon.ico. Troubleshoot with your CDN provider until this test is successful.
216
 
217
  = A notification about file owner appears along with an FTP form, how can I resolve this? =
218
 
219
+ The plugin uses WordPress FileSystem functionality to write to files. It checks if the file owner, file owner group of created files match process owner. If this is not the case it cannot write or modify files.
220
 
221
  Typically, you should tell your web host about the permission issue and they should be able to resolve it.
222
 
285
 
286
  == Changelog ==
287
 
288
+ = 2.2.1=
289
+ * Fix: Cloudflare: Removed use of the retired ip_lkup V1 endpoint
290
+ * Fix: Prevent error in some environments using non-direct filesystems
291
+ * Fix: Added better checking for some filesystem actions
292
+ * Fix: AWS CloudFront: Reverted async change for cache invalidation to honor promises
293
+ * Enhancement: Added option to exclude minified JS files from being processed by Rocket Loader
294
+ * Enhancement: Improved handling of Image Service rate-limiting and error messages
295
+
296
  = 2.2.0 =
297
  * Feature: Image Service API extension: WebP conversion options
298
 
w3-total-cache-api.php CHANGED
@@ -1,11 +1,18 @@
1
  <?php
 
 
 
 
 
 
 
2
 
3
- if ( !defined( 'ABSPATH' ) ) {
4
  die();
5
  }
6
 
7
  define( 'W3TC', true );
8
- define( 'W3TC_VERSION', '2.2.0' );
9
  define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
10
  define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
11
  define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
@@ -32,25 +39,26 @@ define( 'W3TC_STACKPATH_AUTHORIZE_URL', 'https://api.w3-edge.com/v1/redirects/st
32
  define( 'W3TC_STACKPATH2_AUTHORIZE_URL', 'https://api.w3-edge.com/v1/redirects/stackpath2/authorize' );
33
  define( 'W3TC_GOOGLE_DRIVE_AUTHORIZE_URL', 'https://api.w3-edge.com/v1/googledrive/authorize' );
34
 
35
- // this is the URL our updater / license checker pings. This should be the URL of the site with EDD installed
36
- if ( !defined( 'W3TC_LICENSE_API_URL' ) ) {
37
  define( 'W3TC_LICENSE_API_URL', 'https://www.w3-edge.com/' );
38
  }
39
- if ( !defined( 'W3TC_PURCHASE_URL' ) ) {
40
  define( 'W3TC_PURCHASE_URL', 'https://www.w3-edge.com/checkout/' );
41
  }
42
 
43
- // the name of your product. This should match the download name in EDD exactly
44
  define( 'W3TC_PURCHASE_PRODUCT_NAME', 'W3 Total Cache Pro: Annual Subscription' );
45
 
46
  define( 'W3TC_WIN', ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) );
47
 
48
- if ( !defined( 'W3TC_DIR' ) )
49
  define( 'W3TC_DIR', realpath( dirname( __FILE__ ) ) );
 
50
 
51
  define( 'W3TC_FILE', 'w3-total-cache/w3-total-cache.php' );
52
  define( 'W3TC_INC_DIR', W3TC_DIR . '/inc' );
53
- define( 'W3TC_INC_WIDGET_DIR', W3TC_INC_DIR. '/widget' );
54
  define( 'W3TC_INC_OPTIONS_DIR', W3TC_INC_DIR . '/options' );
55
  define( 'W3TC_INC_LIGHTBOX_DIR', W3TC_INC_DIR . '/lightbox' );
56
  define( 'W3TC_INC_POPUP_DIR', W3TC_INC_DIR . '/popup' );
@@ -61,23 +69,37 @@ define( 'W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content' );
61
  define( 'W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min' );
62
  define( 'W3TC_LANGUAGES_DIR', W3TC_DIR . '/languages' );
63
 
64
- if ( !defined( 'WP_CONTENT_DIR' ) )
65
  define( 'WP_CONTENT_DIR', realpath( W3TC_DIR . '/../..' ) );
 
66
 
67
- if ( !defined( 'W3TC_CACHE_DIR' ) )
68
  define( 'W3TC_CACHE_DIR', WP_CONTENT_DIR . '/cache' );
69
- if ( !defined( 'W3TC_CONFIG_DIR' ) )
 
 
70
  define( 'W3TC_CONFIG_DIR', WP_CONTENT_DIR . '/w3tc-config' );
71
- if ( !defined( 'W3TC_CACHE_MINIFY_DIR' ) )
72
- define( 'W3TC_CACHE_MINIFY_DIR', W3TC_CACHE_DIR . '/minify' );
73
- if ( !defined( 'W3TC_CACHE_PAGE_ENHANCED_DIR' ) )
74
- define( 'W3TC_CACHE_PAGE_ENHANCED_DIR', W3TC_CACHE_DIR . '/page_enhanced' );
75
- if ( !defined( 'W3TC_CACHE_TMP_DIR' ) )
 
 
 
 
 
 
76
  define( 'W3TC_CACHE_TMP_DIR', W3TC_CACHE_DIR . '/tmp' );
77
- if ( !defined( 'W3TC_CACHE_BLOGMAP_FILENAME' ) )
 
 
78
  define( 'W3TC_CACHE_BLOGMAP_FILENAME', W3TC_CACHE_DIR . '/blogs.php' );
79
- if ( !defined( 'W3TC_CACHE_FILE_EXPIRE_MAX' ) )
 
 
80
  define( 'W3TC_CACHE_FILE_EXPIRE_MAX', 2592000 );
 
81
 
82
  define( 'W3TC_CDN_COMMAND_UPLOAD', 1 );
83
  define( 'W3TC_CDN_COMMAND_DELETE', 2 );
@@ -120,14 +142,14 @@ define( 'W3TC_MARKER_END_CDN', '# END W3TC CDN' );
120
  define( 'W3TC_MARKER_END_NEW_RELIC_CORE', '# END W3TC New Relic core' );
121
  define( 'W3TC_MARKER_END_WEBP', '# END W3TC WEBP' );
122
 
123
- if ( !defined( 'W3TC_EXTENSION_DIR' ) ) {
124
  define( 'W3TC_EXTENSION_DIR', ( defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins' ) );
125
  }
126
 
127
- if ( !defined( 'W3TC_WP_JSON_URI' ) ) {
128
  define( 'W3TC_WP_JSON_URI', '/wp-json/' );
129
  }
130
- if ( !defined( 'W3TC_FEED_REGEXP' ) ) {
131
  define( 'W3TC_FEED_REGEXP', '~/feed(/|$)~' );
132
  }
133
 
@@ -138,17 +160,17 @@ global $w3_late_init;
138
  $w3_late_init = false;
139
 
140
  /**
141
- * Class autoloader
142
  *
143
- * @param string $class Classname
144
  */
145
  function w3tc_class_autoload( $class ) {
146
- // some php pass classes with slash
147
- if ( substr( $class, 0, 1 ) == "\\" ) {
148
  $class = substr( $class, 1 );
149
  }
150
 
151
- // try core w3tc classes first
152
  if ( substr( $class, 0, 5 ) == 'W3TC\\' ) {
153
  $filename = W3TC_DIR . DIRECTORY_SEPARATOR . substr( $class, 5 ) . '.php';
154
 
@@ -166,8 +188,8 @@ function w3tc_class_autoload( $class ) {
166
  }
167
 
168
  if ( substr( $class, 0, 13 ) == 'W3TCG_Google_' &&
169
- ( !defined( 'W3TC_GOOGLE_LIBRARY' ) || W3TC_GOOGLE_LIBRARY ) ) {
170
- // Google library
171
  $classPath = explode( '_', substr( $class, 6 ) );
172
  if ( count( $classPath ) > 3 ) {
173
  // Maximum class file path depth in this project is 3.
@@ -186,11 +208,12 @@ function w3tc_class_autoload( $class ) {
186
  $base = W3TC_LIB_DIR . DIRECTORY_SEPARATOR;
187
  $class = substr( $class, 6 );
188
 
189
- // psr loader
190
- $file = $base . strtr( $class, "\\_",
191
- DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) . '.php';
192
- if ( file_exists( $file ) )
193
  require_once $file;
 
194
  }
195
  }
196
 
@@ -217,15 +240,18 @@ function w3tc_config() {
217
  * adds notices on each wp-admin page without ability to remove it.
218
  * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like.
219
  */
220
- if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE )
221
  return new W3_Config();
 
222
 
223
  $config = \W3TC\Dispatcher::config();
224
  return $config;
225
  }
226
 
227
  /**
228
- * Purges/Flushes everything
 
 
229
  */
230
  function w3tc_flush_all( $extras = null ) {
231
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -233,7 +259,10 @@ function w3tc_flush_all( $extras = null ) {
233
  }
234
 
235
  /**
236
- * Purges/Flushes post page
 
 
 
237
  */
238
  function w3tc_flush_post( $post_id, $extras = null ) {
239
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -241,7 +270,9 @@ function w3tc_flush_post( $post_id, $extras = null ) {
241
  }
242
 
243
  /**
244
- * Purges/Flushes all posts
 
 
245
  */
246
  function w3tc_flush_posts( $extras = null ) {
247
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -249,7 +280,10 @@ function w3tc_flush_posts( $extras = null ) {
249
  }
250
 
251
  /**
252
- * Purges/Flushes url
 
 
 
253
  */
254
  function w3tc_flush_url( $url, $extras = null ) {
255
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -257,7 +291,10 @@ function w3tc_flush_url( $url, $extras = null ) {
257
  }
258
 
259
  /**
260
- * Purges/Flushes separate cache group
 
 
 
261
  */
262
  function w3tc_flush_group( $group, $extras = null ) {
263
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -267,40 +304,38 @@ function w3tc_flush_group( $group, $extras = null ) {
267
 
268
 
269
  /**
270
- * deprecated
271
- * Shortcut for page cache flush
272
  *
273
- * @return boolean
274
  */
275
  function w3tc_pgcache_flush() {
276
  return w3tc_flush_posts();
277
  }
278
 
279
  /**
280
- * deprecated
281
- * Shortcut for page post cache flush
282
  *
283
- * @param integer $post_id
284
- * @return boolean
285
  */
286
  function w3tc_pgcache_flush_post( $post_id ) {
287
  return w3tc_flush_post( $post_id );
288
  }
289
 
290
  /**
291
- * deprecated
292
- * Shortcut for page post cache flush by url
293
  *
294
- * @param integer $url
295
- * @return boolean
296
  */
297
  function w3tc_pgcache_flush_url( $url ) {
298
  return w3tc_flush_url( $url );
299
  }
300
 
301
  /**
302
- * deprecated
303
- * Shortcut for refreshing the media query string.
 
304
  */
305
  function w3tc_browsercache_flush() {
306
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -308,9 +343,7 @@ function w3tc_browsercache_flush() {
308
  }
309
 
310
  /**
311
- * deprecated
312
- * Shortcut for database cache flush
313
- *
314
  */
315
  function w3tc_dbcache_flush() {
316
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -318,20 +351,16 @@ function w3tc_dbcache_flush() {
318
  }
319
 
320
  /**
321
- * deprecated
322
- * Shortcut for minify cache flush
323
  *
324
  */
325
  function w3tc_minify_flush() {
326
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
327
  $o->minifycache_flush();
328
-
329
  }
330
 
331
  /**
332
- * deprecated
333
- * Shortcut for objectcache cache flush
334
- *
335
  */
336
  function w3tc_objectcache_flush() {
337
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
@@ -339,10 +368,9 @@ function w3tc_objectcache_flush() {
339
  }
340
 
341
  /**
342
- * deprecated
343
- * Shortcut for CDN purge files
344
  *
345
- * @param array $files Array consisting of uri paths (i.e wp-content/uploads/image.pnp)
346
  * @return mixed
347
  */
348
  function w3tc_cdn_purge_files( $files ) {
@@ -351,14 +379,13 @@ function w3tc_cdn_purge_files( $files ) {
351
  }
352
 
353
  /**
354
- * deprecated
355
- * Prints script tag for scripts group
356
  *
357
- * @param string $location
358
- * @retun void
359
  */
360
  function w3tc_minify_script_group( $location ) {
361
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
 
362
  $o->printed_scripts[] = $location;
363
 
364
  $r = $o->get_script_group( $location );
@@ -366,14 +393,13 @@ function w3tc_minify_script_group( $location ) {
366
  }
367
 
368
  /**
369
- * deprecated
370
- * Prints style tag for styles group
371
  *
372
- * @param string $location
373
- * @retun void
374
  */
375
  function w3tc_minify_style_group( $location ) {
376
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
 
377
  $o->printed_styles[] = $location;
378
 
379
  $r = $o->get_style_group( $location );
@@ -381,12 +407,10 @@ function w3tc_minify_style_group( $location ) {
381
  }
382
 
383
  /**
384
- * deprecated
385
- * Prints script tag for custom scripts
386
  *
387
- * @param string|array $files
388
- * @param boolean $blocking
389
- * @return void
390
  */
391
  function w3tc_minify_script_custom( $files, $blocking = true ) {
392
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
@@ -394,11 +418,9 @@ function w3tc_minify_script_custom( $files, $blocking = true ) {
394
  }
395
 
396
  /**
397
- * deprecated
398
- * Prints style tag for custom styles
399
  *
400
- * @param string|array $files
401
- * @return void
402
  */
403
  function w3tc_minify_style_custom( $files ) {
404
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
@@ -407,14 +429,13 @@ function w3tc_minify_style_custom( $files ) {
407
  }
408
 
409
  /**
410
- * deprecated
411
- * Use Util_Theme::get_themes() to get a list themenames to use with user agent groups
412
  *
413
- * @param unknown $group_name
414
- * @param string $theme the themename default is default theme. For childtheme it should be parentthemename/childthemename
415
- * @param string $redirect
416
- * @param array $agents Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported.
417
- * @param bool $enabled
418
  */
419
  function w3tc_save_user_agent_group( $group_name, $theme = 'default', $redirect = '', $agents = array(), $enabled = false ) {
420
  $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' );
@@ -422,20 +443,19 @@ function w3tc_save_user_agent_group( $group_name, $theme = 'default', $redirect
422
  }
423
 
424
  /**
425
- * deprecated
426
  *
427
- * @param unknown $group
428
  */
429
  function w3tc_delete_user_agent_group( $group ) {
430
  $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' );
431
  $o->delete_group( $group );
432
-
433
  }
434
 
435
  /**
436
- * deprecated
437
  *
438
- * @param unknown $group
439
  * @return mixed
440
  */
441
  function w3tc_get_user_agent_group( $group ) {
@@ -444,14 +464,13 @@ function w3tc_get_user_agent_group( $group ) {
444
  }
445
 
446
  /**
447
- * deprecated
448
- * Use Util_Theme::get_themes() to get a list themenames to use with referrer groups
449
  *
450
- * @param unknown $group_name
451
- * @param string $theme the themename default is default theme. For childtheme it should be parentthemename/childthemename
452
- * @param string $redirect
453
- * @param array $referrers Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported.
454
- * @param bool $enabled
455
  */
456
  function w3tc_save_referrer_group( $group_name, $theme = 'default', $redirect = '', $referrers = array(), $enabled = false ) {
457
  $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' );
@@ -459,9 +478,9 @@ function w3tc_save_referrer_group( $group_name, $theme = 'default', $redirect =
459
  }
460
 
461
  /**
462
- * deprecated
463
  *
464
- * @param unknown $group
465
  */
466
  function w3tc_delete_referrer_group( $group ) {
467
  $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' );
@@ -469,9 +488,9 @@ function w3tc_delete_referrer_group( $group ) {
469
  }
470
 
471
  /**
472
- * deprecated
473
  *
474
- * @param unknown $group
475
  * @return mixed
476
  */
477
  function w3tc_get_referrer_group( $group ) {
@@ -481,33 +500,34 @@ function w3tc_get_referrer_group( $group ) {
481
 
482
 
483
  /**
484
- * deprecated
485
- * Flushes files from opcache.
486
  *
487
- * @param bool $http if delete request should be made over http to current site. Default false.
488
  * @return mixed
489
  */
490
  function w3tc_opcache_flush( $http = false ) {
491
- if ( !$http ) {
492
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
493
  return $o->opcache_flush();
494
  } else {
495
- $url = WP_PLUGIN_URL . '/' . dirname( W3TC_FILE ) . '/pub/opcache.php';
496
- $path = parse_url( $url, PHP_URL_PATH );
497
- $post = array(
498
- 'method' => 'POST',
499
- 'timeout' => 45,
500
  'redirection' => 5,
501
  'httpversion' => '1.0',
502
- 'blocking' => true,
503
- 'body' => array(
504
- 'nonce' => wp_hash( $path ),
505
- 'command' => 'flush' ),
 
506
  );
507
  $result = wp_remote_post( $url, $post );
 
508
  if ( is_wp_error( $result ) ) {
509
  return $result;
510
- } elseif ( $result['response']['code'] != '200' ) {
511
  return $result['response']['code'];
512
  }
513
 
@@ -516,7 +536,7 @@ function w3tc_opcache_flush( $http = false ) {
516
  }
517
 
518
  /**
519
- * Deprecated. Retained for 3rd parties that used it. see w3tc_config()
520
  *
521
  * Some plugins make incorrect decisions based on configuration
522
  * and force to disable modules working otherwise or
@@ -524,85 +544,168 @@ function w3tc_opcache_flush( $http = false ) {
524
  * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like.
525
  */
526
  if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) {
 
 
 
527
  class W3_Config {
 
 
 
 
 
 
528
  public function __construct( $master = false, $blog_id = null ) {
529
  }
530
 
 
 
 
 
 
 
 
 
531
  public function get_string( $key, $default = '', $trim = true ) {
532
  return '';
533
  }
534
 
 
 
 
 
 
 
535
  public function get_integer( $key, $default = 0 ) {
536
  return 0;
537
  }
538
 
 
 
 
 
 
 
 
539
  public function get_boolean( $key, $default = false ) {
540
  return false;
541
  }
542
  }
543
  } else {
 
 
 
544
  class W3_Config extends \W3TC\Config {
 
 
 
 
 
 
545
  public function __construct( $master = false, $blog_id = null ) {
546
- if ( $master )
547
  $blog_id = 0;
 
548
 
549
- return parent::__construct($blog_id);
550
  }
551
  }
552
  }
553
 
554
  /**
555
- * Deprecated. Retained for 3rd parties that use it. see w3tc_config()
 
 
556
  */
557
  class W3_ConfigWriter {
 
 
 
 
 
 
558
  public function __construct( $p1 = 0, $p2 = 0 ) {
559
  }
 
 
 
 
 
 
 
560
  public function set( $p1 = 0, $p2 = 0 ) {
561
  }
 
 
 
 
 
 
 
562
  public function save( $p1 = 0, $p2 = 0 ) {
563
  }
 
 
 
 
564
  public function refresh_w3tc() {
565
  }
566
  }
567
 
568
  /**
569
- * Deprecated. Retained for 3rd parties that use it. see w3tc_config().
 
 
570
  */
571
  function w3_instance( $class ) {
572
  $legacy_class_name = null;
573
 
574
- if ( $class == 'W3_Config' ) {
575
- if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE )
576
- return new W3_Config();
 
 
577
 
578
- $legacy_class_name = 'Config';
 
 
 
 
 
 
 
 
 
 
 
 
579
  }
580
- elseif ( $class == 'W3_ObjectCacheBridge' )
581
- $legacy_class_name = 'ObjectCache_WpObjectCache';
582
- elseif ( $class == 'W3_PgCache' )
583
- $legacy_class_name = 'PgCache_ContentGrabber';
584
- elseif ( $class == 'W3_Redirect' )
585
- $legacy_class_name = 'Mobile_Redirect';
586
- else
587
- return null;
588
 
589
  return \W3TC\Dispatcher::component( $legacy_class_name );
590
  }
591
 
592
-
593
-
 
 
 
 
594
  function w3tc_e( $key, $default_value ) {
595
  echo w3tc_er( $key, $default_value);
596
  }
597
 
598
-
599
-
 
 
 
 
600
  function w3tc_er( $key, $default_value ) {
601
  $default_value = __( $default_value , 'w3-total-cache' );
602
- $v = get_site_option( 'w3tc_generic_widgetservices' );
 
603
  try {
604
  $v = json_decode( $v, true );
605
- if ( !isset( $v['content'] ) ) {
606
  return $default_value;
607
  }
608
 
@@ -612,6 +715,7 @@ function w3tc_er( $key, $default_value ) {
612
  }
613
 
614
  global $w3tc_locale;
 
615
  if ( null === $w3tc_locale ) {
616
  if ( function_exists( 'get_user_locale' ) ) {
617
  $w3tc_locale = get_user_locale();
@@ -620,61 +724,61 @@ function w3tc_er( $key, $default_value ) {
620
  }
621
  }
622
 
623
- if ( isset( $v["ui_strings.$w3tc_locale"][$key] ) ) {
624
- return $v["ui_strings.$w3tc_locale"][$key];
625
  }
626
- if ( isset( $v["ui_strings"][$key] ) ) {
627
- return $v["ui_strings"][$key];
628
  }
629
 
630
  return $default_value;
631
  }
632
 
633
-
634
-
635
  $w3tc_actions = array();
636
 
637
-
638
-
639
  /**
640
- * add_action alternative used by W3TC when WP core is not available
 
 
 
641
  */
642
  function w3tc_add_action( $hook, $callback ) {
643
  global $w3tc_actions;
644
- if ( !isset( $w3tc_actions[$hook] ) ) {
645
- $w3tc_actions[$hook] = array();
646
  }
647
 
648
- $w3tc_actions[$hook][] = $callback;
649
  }
650
 
651
-
652
-
653
  /**
654
- * do_action alternative used by W3TC when WP core is not available
 
 
655
  */
656
  function w3tc_do_action( $hook ) {
657
  global $w3tc_actions;
658
- if (!empty($w3tc_actions[$hook])) {
659
- foreach ( $w3tc_actions[$hook] as $callback ) {
660
  call_user_func_array( $callback, array() );
661
  }
662
  }
663
  }
664
 
665
-
666
-
667
  /**
668
- * do_action alternative used by W3TC when WP core is not available
 
 
 
669
  */
670
  function w3tc_apply_filters( $hook, $value ) {
671
  $args = func_get_args();
672
  array_shift( $args );
673
 
674
  global $w3tc_actions;
675
- if (!empty($w3tc_actions[$hook])) {
676
- foreach ( $w3tc_actions[$hook] as $callback ) {
677
- $value = call_user_func_array( $callback, $args );
678
  $args[0] = $value;
679
  }
680
  }
1
  <?php
2
+ /**
3
+ * File: w3-total-cache-api.php
4
+ *
5
+ * @package W3TC
6
+ *
7
+ * phpcs:disable WordPress.PHP
8
+ */
9
 
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
  die();
12
  }
13
 
14
  define( 'W3TC', true );
15
+ define( 'W3TC_VERSION', '2.2.1' );
16
  define( 'W3TC_POWERED_BY', 'W3 Total Cache' );
17
  define( 'W3TC_EMAIL', 'w3tc@w3-edge.com' );
18
  define( 'W3TC_TEXT_DOMAIN', 'w3-total-cache' );
39
  define( 'W3TC_STACKPATH2_AUTHORIZE_URL', 'https://api.w3-edge.com/v1/redirects/stackpath2/authorize' );
40
  define( 'W3TC_GOOGLE_DRIVE_AUTHORIZE_URL', 'https://api.w3-edge.com/v1/googledrive/authorize' );
41
 
42
+ // this is the URL our updater / license checker pings. This should be the URL of the site with EDD installed.
43
+ if ( ! defined( 'W3TC_LICENSE_API_URL' ) ) {
44
  define( 'W3TC_LICENSE_API_URL', 'https://www.w3-edge.com/' );
45
  }
46
+ if ( ! defined( 'W3TC_PURCHASE_URL' ) ) {
47
  define( 'W3TC_PURCHASE_URL', 'https://www.w3-edge.com/checkout/' );
48
  }
49
 
50
+ // the name of your product. This should match the download name in EDD exactly.
51
  define( 'W3TC_PURCHASE_PRODUCT_NAME', 'W3 Total Cache Pro: Annual Subscription' );
52
 
53
  define( 'W3TC_WIN', ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) );
54
 
55
+ if ( ! defined( 'W3TC_DIR' ) ) {
56
  define( 'W3TC_DIR', realpath( dirname( __FILE__ ) ) );
57
+ }
58
 
59
  define( 'W3TC_FILE', 'w3-total-cache/w3-total-cache.php' );
60
  define( 'W3TC_INC_DIR', W3TC_DIR . '/inc' );
61
+ define( 'W3TC_INC_WIDGET_DIR', W3TC_INC_DIR . '/widget' );
62
  define( 'W3TC_INC_OPTIONS_DIR', W3TC_INC_DIR . '/options' );
63
  define( 'W3TC_INC_LIGHTBOX_DIR', W3TC_INC_DIR . '/lightbox' );
64
  define( 'W3TC_INC_POPUP_DIR', W3TC_INC_DIR . '/popup' );
69
  define( 'W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min' );
70
  define( 'W3TC_LANGUAGES_DIR', W3TC_DIR . '/languages' );
71
 
72
+ if ( ! defined( 'WP_CONTENT_DIR' ) ) {
73
  define( 'WP_CONTENT_DIR', realpath( W3TC_DIR . '/../..' ) );
74
+ }
75
 
76
+ if ( ! defined( 'W3TC_CACHE_DIR' ) ) {
77
  define( 'W3TC_CACHE_DIR', WP_CONTENT_DIR . '/cache' );
78
+ }
79
+
80
+ if ( ! defined( 'W3TC_CONFIG_DIR' ) ) {
81
  define( 'W3TC_CONFIG_DIR', WP_CONTENT_DIR . '/w3tc-config' );
82
+ }
83
+
84
+ if ( ! defined( 'W3TC_CACHE_MINIFY_DIR' ) ) {
85
+ define( 'W3TC_CACHE_MINIFY_DIR', W3TC_CACHE_DIR . '/minify' );
86
+ }
87
+
88
+ if ( ! defined( 'W3TC_CACHE_PAGE_ENHANCED_DIR' ) ) {
89
+ define( 'W3TC_CACHE_PAGE_ENHANCED_DIR', W3TC_CACHE_DIR . '/page_enhanced' );
90
+ }
91
+
92
+ if ( ! defined( 'W3TC_CACHE_TMP_DIR' ) ) {
93
  define( 'W3TC_CACHE_TMP_DIR', W3TC_CACHE_DIR . '/tmp' );
94
+ }
95
+
96
+ if ( ! defined( 'W3TC_CACHE_BLOGMAP_FILENAME' ) ) {
97
  define( 'W3TC_CACHE_BLOGMAP_FILENAME', W3TC_CACHE_DIR . '/blogs.php' );
98
+ }
99
+
100
+ if ( ! defined( 'W3TC_CACHE_FILE_EXPIRE_MAX' ) ) {
101
  define( 'W3TC_CACHE_FILE_EXPIRE_MAX', 2592000 );
102
+ }
103
 
104
  define( 'W3TC_CDN_COMMAND_UPLOAD', 1 );
105
  define( 'W3TC_CDN_COMMAND_DELETE', 2 );
142
  define( 'W3TC_MARKER_END_NEW_RELIC_CORE', '# END W3TC New Relic core' );
143
  define( 'W3TC_MARKER_END_WEBP', '# END W3TC WEBP' );
144
 
145
+ if ( ! defined( 'W3TC_EXTENSION_DIR' ) ) {
146
  define( 'W3TC_EXTENSION_DIR', ( defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins' ) );
147
  }
148
 
149
+ if ( ! defined( 'W3TC_WP_JSON_URI' ) ) {
150
  define( 'W3TC_WP_JSON_URI', '/wp-json/' );
151
  }
152
+ if ( ! defined( 'W3TC_FEED_REGEXP' ) ) {
153
  define( 'W3TC_FEED_REGEXP', '~/feed(/|$)~' );
154
  }
155
 
160
  $w3_late_init = false;
161
 
162
  /**
163
+ * Class autoloader.
164
  *
165
+ * @param string $class Classname.
166
  */
167
  function w3tc_class_autoload( $class ) {
168
+ // Some php pass classes with slash.
169
+ if ( substr( $class, 0, 1 ) == '\\' ) {
170
  $class = substr( $class, 1 );
171
  }
172
 
173
+ // Try core w3tc classes first.
174
  if ( substr( $class, 0, 5 ) == 'W3TC\\' ) {
175
  $filename = W3TC_DIR . DIRECTORY_SEPARATOR . substr( $class, 5 ) . '.php';
176
 
188
  }
189
 
190
  if ( substr( $class, 0, 13 ) == 'W3TCG_Google_' &&
191
+ ( ! defined( 'W3TC_GOOGLE_LIBRARY' ) || W3TC_GOOGLE_LIBRARY ) ) {
192
+ // Google library.
193
  $classPath = explode( '_', substr( $class, 6 ) );
194
  if ( count( $classPath ) > 3 ) {
195
  // Maximum class file path depth in this project is 3.
208
  $base = W3TC_LIB_DIR . DIRECTORY_SEPARATOR;
209
  $class = substr( $class, 6 );
210
 
211
+ // PSR loader.
212
+ $file = $base . strtr( $class, '\\_', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) . '.php';
213
+
214
+ if ( file_exists( $file ) ) {
215
  require_once $file;
216
+ }
217
  }
218
  }
219
 
240
  * adds notices on each wp-admin page without ability to remove it.
241
  * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like.
242
  */
243
+ if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) {
244
  return new W3_Config();
245
+ }
246
 
247
  $config = \W3TC\Dispatcher::config();
248
  return $config;
249
  }
250
 
251
  /**
252
+ * Purges/Flushes everything.
253
+ *
254
+ * @param array $extras Extras.
255
  */
256
  function w3tc_flush_all( $extras = null ) {
257
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
259
  }
260
 
261
  /**
262
+ * Purges/Flushes post page.
263
+ *
264
+ * @param int $post_id Post id.
265
+ * @param array $extras Exteas.
266
  */
267
  function w3tc_flush_post( $post_id, $extras = null ) {
268
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
270
  }
271
 
272
  /**
273
+ * Purges/Flushes all posts.
274
+ *
275
+ * @param array $extras Extras.
276
  */
277
  function w3tc_flush_posts( $extras = null ) {
278
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
280
  }
281
 
282
  /**
283
+ * Purges/Flushes url.
284
+ *
285
+ * @param string $url URL.
286
+ * @param array $extras Extras.
287
  */
288
  function w3tc_flush_url( $url, $extras = null ) {
289
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
291
  }
292
 
293
  /**
294
+ * Purges/Flushes separate cache group.
295
+ *
296
+ * @param string $group Group.
297
+ * @param array $extras Extras.
298
  */
299
  function w3tc_flush_group( $group, $extras = null ) {
300
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
304
 
305
 
306
  /**
307
+ * Deprecated. Shortcut for page cache flush.
 
308
  *
309
+ * @return bool
310
  */
311
  function w3tc_pgcache_flush() {
312
  return w3tc_flush_posts();
313
  }
314
 
315
  /**
316
+ * Deprecated. Shortcut for page post cache flush.
 
317
  *
318
+ * @param int $post_id Post id.
319
+ * @return bool
320
  */
321
  function w3tc_pgcache_flush_post( $post_id ) {
322
  return w3tc_flush_post( $post_id );
323
  }
324
 
325
  /**
326
+ * Deprecated. Shortcut for page post cache flush by url.
 
327
  *
328
+ * @param int $url URL.
329
+ * @return bool
330
  */
331
  function w3tc_pgcache_flush_url( $url ) {
332
  return w3tc_flush_url( $url );
333
  }
334
 
335
  /**
336
+ * Deprecated. Shortcut for refreshing the media query string.
337
+ *
338
+ * @return null
339
  */
340
  function w3tc_browsercache_flush() {
341
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
343
  }
344
 
345
  /**
346
+ * Deprecated. Shortcut for database cache flush.
 
 
347
  */
348
  function w3tc_dbcache_flush() {
349
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
351
  }
352
 
353
  /**
354
+ * Deprecated. Shortcut for minify cache flush.
 
355
  *
356
  */
357
  function w3tc_minify_flush() {
358
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
359
  $o->minifycache_flush();
 
360
  }
361
 
362
  /**
363
+ * Deprecated. Shortcut for objectcache cache flush.
 
 
364
  */
365
  function w3tc_objectcache_flush() {
366
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
368
  }
369
 
370
  /**
371
+ * Deprecated. Shortcut for CDN purge files.
 
372
  *
373
+ * @param array $files Array consisting of uri paths (i.e wp-content/uploads/image.pnp).
374
  * @return mixed
375
  */
376
  function w3tc_cdn_purge_files( $files ) {
379
  }
380
 
381
  /**
382
+ * Deprecated. Prints script tag for scripts group.
 
383
  *
384
+ * @param string $location Location.
 
385
  */
386
  function w3tc_minify_script_group( $location ) {
387
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
388
+
389
  $o->printed_scripts[] = $location;
390
 
391
  $r = $o->get_script_group( $location );
393
  }
394
 
395
  /**
396
+ * Deprecated. Prints style tag for styles group.
 
397
  *
398
+ * @param string $location Location.
 
399
  */
400
  function w3tc_minify_style_group( $location ) {
401
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
402
+
403
  $o->printed_styles[] = $location;
404
 
405
  $r = $o->get_style_group( $location );
407
  }
408
 
409
  /**
410
+ * Deprecated. Prints script tag for custom scripts.
 
411
  *
412
+ * @param string|array $files Files.
413
+ * @param bool $blocking Blocking.
 
414
  */
415
  function w3tc_minify_script_custom( $files, $blocking = true ) {
416
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
418
  }
419
 
420
  /**
421
+ * Deprecated. Prints style tag for custom styles.
 
422
  *
423
+ * @param string|array $files Files.
 
424
  */
425
  function w3tc_minify_style_custom( $files ) {
426
  $o = \W3TC\Dispatcher::component( 'Minify_Plugin' );
429
  }
430
 
431
  /**
432
+ * Deprecated. Use Util_Theme::get_themes() to get a list themenames to use with user agent groups.
 
433
  *
434
+ * @param string $group_name Group name.
435
+ * @param string $theme The themename default is default theme. For childtheme it should be parentthemename/childthemename.
436
+ * @param string $redirect Redirect.
437
+ * @param array $agents Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported.
438
+ * @param bool $enabled Enabled.
439
  */
440
  function w3tc_save_user_agent_group( $group_name, $theme = 'default', $redirect = '', $agents = array(), $enabled = false ) {
441
  $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' );
443
  }
444
 
445
  /**
446
+ * Deprecated.
447
  *
448
+ * @param string $group Group.
449
  */
450
  function w3tc_delete_user_agent_group( $group ) {
451
  $o = \W3TC\Dispatcher::component( 'Mobile_UserAgent' );
452
  $o->delete_group( $group );
 
453
  }
454
 
455
  /**
456
+ * Deprecated.
457
  *
458
+ * @param string $group Group.
459
  * @return mixed
460
  */
461
  function w3tc_get_user_agent_group( $group ) {
464
  }
465
 
466
  /**
467
+ * Deprecated. Use Util_Theme::get_themes() to get a list themenames to use with referrer groups.
 
468
  *
469
+ * @param string $group_name Group name.
470
+ * @param string $theme The themename default is default theme. For childtheme it should be parentthemename/childthemename.
471
+ * @param string $redirect Redirect.
472
+ * @param array $referrers Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported.
473
+ * @param bool $enabled Enabled.
474
  */
475
  function w3tc_save_referrer_group( $group_name, $theme = 'default', $redirect = '', $referrers = array(), $enabled = false ) {
476
  $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' );
478
  }
479
 
480
  /**
481
+ * Deprecated.
482
  *
483
+ * @param string $group Group.
484
  */
485
  function w3tc_delete_referrer_group( $group ) {
486
  $o = \W3TC\Dispatcher::component( 'Mobile_Referrer' );
488
  }
489
 
490
  /**
491
+ * Deprecated.
492
  *
493
+ * @param string $group Group.
494
  * @return mixed
495
  */
496
  function w3tc_get_referrer_group( $group ) {
500
 
501
 
502
  /**
503
+ * Deprecated. Flushes files from opcache.
 
504
  *
505
+ * @param bool $http If delete request should be made over http to current site. Default false.
506
  * @return mixed
507
  */
508
  function w3tc_opcache_flush( $http = false ) {
509
+ if ( ! $http ) {
510
  $o = \W3TC\Dispatcher::component( 'CacheFlush' );
511
  return $o->opcache_flush();
512
  } else {
513
+ $url = WP_PLUGIN_URL . '/' . dirname( W3TC_FILE ) . '/pub/opcache.php';
514
+ $path = parse_url( $url, PHP_URL_PATH );
515
+ $post = array(
516
+ 'method' => 'POST',
517
+ 'timeout' => 45,
518
  'redirection' => 5,
519
  'httpversion' => '1.0',
520
+ 'blocking' => true,
521
+ 'body' => array(
522
+ 'nonce' => wp_hash( $path ),
523
+ 'command' => 'flush',
524
+ ),
525
  );
526
  $result = wp_remote_post( $url, $post );
527
+
528
  if ( is_wp_error( $result ) ) {
529
  return $result;
530
+ } elseif ( '200' != $result['response']['code'] ) {
531
  return $result['response']['code'];
532
  }
533
 
536
  }
537
 
538
  /**
539
+ * Deprecated. Retained for 3rd parties that used it. see w3tc_config().
540
  *
541
  * Some plugins make incorrect decisions based on configuration
542
  * and force to disable modules working otherwise or
544
  * By defining W3TC_CONFIG_HIDE you may still use w3tc configuration you like.
545
  */
546
  if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) {
547
+ /**
548
+ * Class: W3_Config
549
+ */
550
  class W3_Config {
551
+ /**
552
+ * Constructor.
553
+ *
554
+ * @param bool $master Master.
555
+ * @param int $blog_id Blog id.
556
+ */
557
  public function __construct( $master = false, $blog_id = null ) {
558
  }
559
 
560
+ /**
561
+ * Get string.
562
+ *
563
+ * @param string $key Key.
564
+ * @param string $default Default.
565
+ * @param boolean $trim Trim.
566
+ * @return string
567
+ */
568
  public function get_string( $key, $default = '', $trim = true ) {
569
  return '';
570
  }
571
 
572
+ /**
573
+ * Get integer.
574
+ *
575
+ * @param string $key Key.
576
+ * @param int $default Default.
577
+ */
578
  public function get_integer( $key, $default = 0 ) {
579
  return 0;
580
  }
581
 
582
+ /**
583
+ * Get boolean.
584
+ *
585
+ * @param string $key Key.
586
+ * @param bool $default Default.
587
+ * @return bool
588
+ */
589
  public function get_boolean( $key, $default = false ) {
590
  return false;
591
  }
592
  }
593
  } else {
594
+ /**
595
+ * Class: W3_Config.
596
+ */
597
  class W3_Config extends \W3TC\Config {
598
+ /**
599
+ * Constructor.
600
+ *
601
+ * @param bool $master Master.
602
+ * @param int $blog_id Blog id.
603
+ */
604
  public function __construct( $master = false, $blog_id = null ) {
605
+ if ( $master ) {
606
  $blog_id = 0;
607
+ }
608
 
609
+ return parent::__construct( $blog_id );
610
  }
611
  }
612
  }
613
 
614
  /**
615
+ * Class: W3_ConfigWriter.
616
+ *
617
+ * Deprecated. Retained for 3rd parties that use it. see w3tc_config().
618
  */
619
  class W3_ConfigWriter {
620
+ /**
621
+ * Constructor.
622
+ *
623
+ * @param int $p1 P1.
624
+ * @param int $p2 P2.
625
+ */
626
  public function __construct( $p1 = 0, $p2 = 0 ) {
627
  }
628
+
629
+ /**
630
+ * Set.
631
+ *
632
+ * @param int $p1 P1.
633
+ * @param int $p2 P2.
634
+ */
635
  public function set( $p1 = 0, $p2 = 0 ) {
636
  }
637
+
638
+ /**
639
+ * Save.
640
+ *
641
+ * @param int $p1 P1.
642
+ * @param int $p2 P2.
643
+ */
644
  public function save( $p1 = 0, $p2 = 0 ) {
645
  }
646
+
647
+ /**
648
+ * Refresh W3TC.
649
+ */
650
  public function refresh_w3tc() {
651
  }
652
  }
653
 
654
  /**
655
+ * Deprecated. Retained for 3rd parties that use it. see w3tc_config().
656
+ *
657
+ * @param string $class Class name.
658
  */
659
  function w3_instance( $class ) {
660
  $legacy_class_name = null;
661
 
662
+ switch ( $class ) {
663
+ case 'W3_Config':
664
+ if ( defined( 'W3TC_CONFIG_HIDE' ) && W3TC_CONFIG_HIDE ) {
665
+ return new W3_Config();
666
+ }
667
 
668
+ $legacy_class_name = 'Config';
669
+ break;
670
+ case 'W3_ObjectCacheBridge':
671
+ $legacy_class_name = 'ObjectCache_WpObjectCache';
672
+ break;
673
+ case 'W3_PgCache':
674
+ $legacy_class_name = 'PgCache_ContentGrabber';
675
+ break;
676
+ case 'W3_Redirect':
677
+ $legacy_class_name = 'Mobile_Redirect';
678
+ break;
679
+ default:
680
+ return null;
681
  }
 
 
 
 
 
 
 
 
682
 
683
  return \W3TC\Dispatcher::component( $legacy_class_name );
684
  }
685
 
686
+ /**
687
+ * Print a localized string.
688
+ *
689
+ * @param string $key Key name.
690
+ * @param mixed $default_value Default value.
691
+ */
692
  function w3tc_e( $key, $default_value ) {
693
  echo w3tc_er( $key, $default_value);
694
  }
695
 
696
+ /**
697
+ * Get a localized string.
698
+ *
699
+ * @param string $key Key name.
700
+ * @param mixed $default_value Default value.
701
+ */
702
  function w3tc_er( $key, $default_value ) {
703
  $default_value = __( $default_value , 'w3-total-cache' );
704
+ $v = get_site_option( 'w3tc_generic_widgetservices' );
705
+
706
  try {
707
  $v = json_decode( $v, true );
708
+ if ( ! isset( $v['content'] ) ) {
709
  return $default_value;
710
  }
711
 
715
  }
716
 
717
  global $w3tc_locale;
718
+
719
  if ( null === $w3tc_locale ) {
720
  if ( function_exists( 'get_user_locale' ) ) {
721
  $w3tc_locale = get_user_locale();
724
  }
725
  }
726
 
727
+ if ( isset( $v[ "ui_strings.$w3tc_locale" ][ $key ] ) ) {
728
+ return $v[ "ui_strings.$w3tc_locale" ][ $key ];
729
  }
730
+ if ( isset( $v['ui_strings'][ $key ] ) ) {
731
+ return $v['ui_strings'][ $key ];
732
  }
733
 
734
  return $default_value;
735
  }
736
 
 
 
737
  $w3tc_actions = array();
738
 
 
 
739
  /**
740
+ * An add_action alternative used by W3TC when WP core is not available.
741
+ *
742
+ * @param string $hook Hook/action name.
743
+ * @param Callable $callback Callback function.
744
  */
745
  function w3tc_add_action( $hook, $callback ) {
746
  global $w3tc_actions;
747
+ if ( ! isset( $w3tc_actions[ $hook ] ) ) {
748
+ $w3tc_actions[ $hook ] = array();
749
  }
750
 
751
+ $w3tc_actions[ $hook ][] = $callback;
752
  }
753
 
 
 
754
  /**
755
+ * A do_action alternative used by W3TC when WP core is not available.
756
+ *
757
+ * @param string $hook Hook/action name.
758
  */
759
  function w3tc_do_action( $hook ) {
760
  global $w3tc_actions;
761
+ if ( ! empty( $w3tc_actions[ $hook ] ) ) {
762
+ foreach ( $w3tc_actions[ $hook ] as $callback ) {
763
  call_user_func_array( $callback, array() );
764
  }
765
  }
766
  }
767
 
 
 
768
  /**
769
+ * An apply_filters alternative used by W3TC when WP core is not available.
770
+ *
771
+ * @param string $hook Hook/filter name.
772
+ * @param mixed $value Value.
773
  */
774
  function w3tc_apply_filters( $hook, $value ) {
775
  $args = func_get_args();
776
  array_shift( $args );
777
 
778
  global $w3tc_actions;
779
+ if ( ! empty($w3tc_actions[ $hook ] ) ) {
780
+ foreach ( $w3tc_actions[ $hook ] as $callback ) {
781
+ $value = call_user_func_array( $callback, $args );
782
  $args[0] = $value;
783
  }
784
  }
w3-total-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: W3 Total Cache
4
  * Plugin URI: https://www.boldgrid.com/totalcache/
5
  * Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
6
- * Version: 2.2.0
7
  * Requires at least: 3.8
8
  * Requires PHP: 5.6
9
  * Author: BoldGrid
3
  * Plugin Name: W3 Total Cache
4
  * Plugin URI: https://www.boldgrid.com/totalcache/
5
  * Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
6
+ * Version: 2.2.1
7
  * Requires at least: 3.8
8
  * Requires PHP: 5.6
9
  * Author: BoldGrid