PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | optimizations/transient.php +35 -27 3.2.5 → 4.7.0 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -if (!defined('WPO_VERSION')) die('No direct access allowed');
3 +if (!defined('ABSPATH')) die('No direct access allowed');
4 4
5 5 class WP_Optimization_transient extends WP_Optimization {
6 6
7 7 public $available_for_auto = true;
@@ -27,9 +27,9 @@
27 27 */
28 28 public function preview($params) {
29 29
30 30 // get type of data for return single site or multisite.
31 - $type = isset($params['type']) && 'multisite' == $params['type'] ? 'multisite' : 'single';
31 + $type = isset($params['type']) && 'multisite' === $params['type'] ? 'multisite' : 'single';
32 32
33 33 // set remove_all_transients for correctly handling "all" checkbox for preview transients.
34 34 if (isset($params['remove_all_transients'])) {
35 35 $this->data['remove_all_transients'] = $params['remove_all_transients'];
@@ -35,9 +35,11 @@
35 35 $this->data['remove_all_transients'] = $params['remove_all_transients'];
36 36 }
37 37
38 38 // get data requested for preview.
39 - if ('single' == $type) {
39 + // `$this->wpdb->prepare` is global `$wpdb->prepare`
40 + // phpcs:disable
41 + if ('single' === $type) {
40 42 $sql = $this->wpdb->prepare("
41 43 SELECT
42 44 a.option_id,
43 45 a.option_name,
@@ -134,11 +136,12 @@
134 136
135 137 $posts = $this->wpdb->get_results($sql, ARRAY_A);
136 138
137 139 $total = $this->wpdb->get_var($sql_count);
140 + // phpcs:enable
138 141
139 142 // define columns array depends on source type of request.
140 - if ('single' == $type) {
143 + if ('single' === $type) {
141 144 $columns = array(
142 145 'option_id' => __('ID', 'wp-optimize'),
143 146 'option_name' => __('Name', 'wp-optimize'),
144 147 'option_value' => __('Value', 'wp-optimize'),
@@ -145,15 +148,15 @@
145 148 );
146 149 } else {
147 150 $columns = array(
148 151 'meta_id' => __('ID', 'wp-optimize'),
149 - 'meta_key' => __('Name', 'wp-optimize'),
150 - 'meta_value' => __('Value', 'wp-optimize'),
152 + 'meta_key' => __('Name', 'wp-optimize'), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- This is not a query
153 + 'meta_value' => __('Value', 'wp-optimize'), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- This is not a query
151 154 );
152 155 }
153 156
154 157 return array(
155 - 'id_key' => ('single' == $type) ? 'option_id' : 'meta_id',
158 + 'id_key' => ('single' === $type) ? 'option_id' : 'meta_id',
156 159 'columns' => $columns,
157 160 'offset' => $params['offset'],
158 161 'limit' => $params['limit'],
159 162 'total' => $total,
@@ -173,11 +176,13 @@
173 176 * Do actions after optimize() function.
174 177 */
175 178 public function after_optimize() {
176 179
180 + // translators: %s is the number of transient options deleted
177 181 $message = sprintf(_n('%s transient option deleted', '%s transient options deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
178 182
179 183 if ($this->is_multisite_mode()) {
184 + // translators: %s is the number of sites
180 185 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
181 186 }
182 187
183 188 $this->logger->info($message);
@@ -248,10 +253,11 @@
248 253 ".($this->remove_only_expired() ? " AND b.option_value < UNIX_TIMESTAMP()" : "");
249 254 }
250 255
251 256 $sitemeta_table_transients_deleted = $this->query($clean2);
252 - if ('' != $clean2_timeouts) $this->query($clean2_timeouts);
257 + if ('' !== $clean2_timeouts) $this->query($clean2_timeouts);
253 258
259 + // translators: %s is the number of transient options deleted across network
254 260 $message2 = sprintf(_n('%s network-wide transient option deleted', '%s network-wide transient options deleted', $sitemeta_table_transients_deleted, 'wp-optimize'), number_format_i18n($sitemeta_table_transients_deleted));
255 261
256 262 $this->logger->info($message2);
257 263 $this->register_output($message2);
@@ -334,9 +340,9 @@
334 340 // run clean transients query and get count of deleted rows.
335 341 $options_table_transients_deleted = $this->query($clean);
336 342 $this->processed_count += $options_table_transients_deleted;
337 343
338 - if ('' != $clean_timeouts) $this->query($clean_timeouts);
344 + if ('' !== $clean_timeouts) $this->query($clean_timeouts);
339 345 }
340 346
341 347 /**
342 348 * Do actions before get_info() function.
@@ -357,9 +363,9 @@
357 363 COUNT(*)
358 364 FROM
359 365 ".$this->wpdb->sitemeta." a
360 366 LEFT JOIN
361 - ".$this->wpdb->sitemeta." b
367 + ".$this->wpdb->sitemeta." b
362 368 ON
363 369 b.meta_key = CONCAT(
364 370 '_site_transient_timeout_',
365 371 SUBSTRING(
@@ -368,16 +374,17 @@
368 374 )
369 375 )
370 376 WHERE
371 377 a.meta_key LIKE '_site_transient_%' AND
372 - a.meta_key NOT LIKE '_site_transient_timeout_%'";
378 + a.meta_key NOT LIKE '_site_transient_timeout_%' AND
379 + b.meta_key IS NOT NULL";
373 380
374 381 $expired_suffix_sql = " AND b.meta_value < UNIX_TIMESTAMP()";
375 382
376 383 // get count of expired transients.
377 - $sitemeta_table_transients = $this->wpdb->get_var($sitemeta_table_sql . $expired_suffix_sql);
384 + $sitemeta_table_transients = $this->wpdb->get_var($sitemeta_table_sql . $expired_suffix_sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe, no user input used
378 385 // get count of all transients.
379 - $sitemeta_table_transients_all = $this->wpdb->get_var($sitemeta_table_sql);
386 + $sitemeta_table_transients_all = $this->wpdb->get_var($sitemeta_table_sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe, no user input used
380 387 } else {
381 388 $sitemeta_table_transients = 0;
382 389 $sitemeta_table_transients_all = 0;
383 390 }
@@ -382,14 +389,20 @@
382 389 $sitemeta_table_transients_all = 0;
383 390 }
384 391
385 392 if ($this->found_count_all > 0) {
386 - $message = sprintf(_n('%1$d of %2$d transient option expired', '%1$d of %2$d transient options expired', $this->found_count_all, 'wp-optimize'), number_format_i18n($this->found_count), number_format_i18n($this->found_count_all));
393 + $message = sprintf(
394 + // translators: %1$s is the number of expired transient options, %2$s is the number of all transient options
395 + _n('%1$s of %2$s transient option expired', '%1$s of %2$s transient options expired', $this->found_count, 'wp-optimize'),
396 + number_format_i18n($this->found_count),
397 + number_format_i18n($this->found_count_all)
398 + );
387 399 } else {
388 400 $message = __('No transient options found', 'wp-optimize');
389 401 }
390 402
391 403 if ($this->is_multisite_mode()) {
404 + // translators: %d is the number of sites
392 405 $message .= ' ' . sprintf(_n('across %d site', 'across %d sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
393 406 }
394 407
395 408 // add preview link to $message.
@@ -400,8 +413,9 @@
400 413 $this->register_output($message);
401 414
402 415 if ($this->is_multisite_mode()) {
403 416 if ($sitemeta_table_transients_all > 0) {
417 + // translators: %1$d is the number of expired transient options, %2$d is the number of all transient options across network
404 418 $message2 = sprintf(_n('%1$d of %2$d network-wide transient option found', '%1$d of %2$d network-wide transient options found', $sitemeta_table_transients_all, 'wp-optimize'), number_format_i18n($sitemeta_table_transients), number_format_i18n($sitemeta_table_transients_all));
405 419 $message2 = $this->get_preview_link($message2, array('data-type' => 'multisite'));
406 420 } else {
407 421 $message2 = __('No site-wide transient options found', 'wp-optimize');
@@ -421,13 +435,8 @@
421 435 * Returns info about possibility to optimize transient options.
422 436 */
423 437 public function get_info() {
424 438
425 - $blogs = $this->get_optimization_blogs();
426 -
427 - foreach ($blogs as $blog_id) {
428 - $this->switch_to_blog($blog_id);
429 -
430 439 $options_table_sql = "
431 440 SELECT
432 441 COUNT(*)
433 442 FROM
@@ -449,24 +458,23 @@
449 458
450 459 $expired_suffix_sql = " AND b.option_value < UNIX_TIMESTAMP()";
451 460
452 461 // get count of expired transients.
453 - $options_table_transients = $this->wpdb->get_var($options_table_sql . $expired_suffix_sql);
462 + $options_table_transients = $this->wpdb->get_var($options_table_sql . $expired_suffix_sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe, no user input used
454 463 $this->found_count += $options_table_transients;
455 464
456 465 // get count of all transients.
457 - $options_table_transients = $this->wpdb->get_var($options_table_sql);
466 + $options_table_transients = $this->wpdb->get_var($options_table_sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe, no user input used
458 467 $this->found_count_all += $options_table_transients;
459 - $this->restore_current_blog();
460 - }
461 468
462 469 }
463 470
471 + /**
472 + * Returns settings label
473 + *
474 + * @return string
475 + */
464 476 public function settings_label() {
465 - return __('Remove expired transient options', 'wp-optimize');
466 - }
467 -
468 - public function get_auto_option_description() {
469 477 return __('Remove expired transient options', 'wp-optimize');
470 478 }
471 479
472 480 /**