PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.2
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 3.8.0 All 110 releases
wp-optimize / optimizations / revisions.php

revisions.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 2.2.2, at optimizations/revisions.php

91 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_VERSION')) die('No direct access allowed');
4
5 class WP_Optimization_revisions extends WP_Optimization {
6
7 public $ui_sort_order = 1000;
8
9 public $available_for_auto = true;
10
11 public $auto_default = true;
12
13 public $setting_default = true;
14
15 public $available_for_saving = true;
16
17 /**
18 * Do actions after optimize() function.
19 */
20 public function after_optimize() {
21 $message = sprintf(_n('%s post revision deleted', '%s post revisions deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
22
23 if ($this->is_multisite_mode()) {
24 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
25 }
26
27 $this->logger->info($message);
28 $this->register_output($message);
29 }
30
31
32 /**
33 * Do optimization.
34 */
35 public function optimize() {
36 $clean = "DELETE FROM `" . $this->wpdb->posts . "` WHERE post_type = 'revision'";
37
38 if ('true' == $this->retention_enabled) {
39 $clean .= '
40 AND post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
41 }
42 $clean .= ';';
43
44 $revisions = $this->query($clean);
45 $this->processed_count += $revisions;
46 }
47
48 /**
49 * Do actions after get_info() function.
50 */
51 public function after_get_info() {
52 if ($this->found_count > 0) {
53 $message = sprintf(_n('%s post revision in your database', '%s post revisions in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
54 } else {
55 $message = __('No post revisions found', 'wp-optimize');
56 }
57
58 if ($this->is_multisite_mode()) {
59 $message .= ' '.sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
60 }
61
62 $this->register_output($message);
63 }
64
65 public function get_info() {
66 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->posts . "` WHERE post_type = 'revision'";
67
68 if ('true' == $this->retention_enabled) {
69 $sql .= ' and post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
70 }
71 $sql .= ';';
72
73 $revisions = $this->wpdb->get_var($sql);
74
75 $this->found_count += $revisions;
76 }
77
78 public function settings_label() {
79
80 if ('true' == $this->retention_enabled) {
81 return sprintf(__('Clean post revisions which are older than %d weeks', 'wp-optimize'), $this->retention_period);
82 } else {
83 return __('Clean all post revisions', 'wp-optimize');
84 }
85 }
86
87 public function get_auto_option_description() {
88 return __('Remove auto revisions', 'wp-optimize');
89 }
90 }
91