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/autodraft.php +19 -20 3.2.21 → 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_autodraft extends WP_Optimization {
6 6
7 7 public $available_for_auto = true;
@@ -30,12 +30,14 @@
30 30 // get data requested for preview.
31 31
32 32 $retention_subquery = '';
33 33
34 - if ('true' == $this->retention_enabled) {
34 + if ('true' === $this->retention_enabled) {
35 35 $retention_subquery = ' and post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
36 36 }
37 37
38 + // Suppress WordPress.DB.PreparedSQL.NotPrepared errors, these are safe and prepared. `$this->wpdb` is $wpdb`
39 + // phpcs:disable
38 40 $sql = $this->wpdb->prepare(
39 41 "SELECT `ID`, `post_title`, `post_date` FROM `" . $this->wpdb->posts . "`".
40 42 " WHERE post_status = 'auto-draft'".
41 43 $retention_subquery.
@@ -46,13 +48,14 @@
46 48 )
47 49 );
48 50
49 51 $posts = $this->wpdb->get_results($sql, ARRAY_A);
52 + // phpcs:enable
50 53
51 54 // fix empty revision titles.
52 55 if (!empty($posts)) {
53 56 foreach ($posts as $key => $post) {
54 - $posts[$key]['post_title'] = '' == $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'];
57 + $posts[$key]['post_title'] = '' === $post['post_title'] ? '('.__('no title', 'wp-optimize').')' : $post['post_title'];
55 58 }
56 59 }
57 60
58 61 // get total count auto-draft for optimization.
@@ -57,9 +60,9 @@
57 60
58 61 // get total count auto-draft for optimization.
59 62 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->posts . "` WHERE post_status = 'auto-draft' ".$retention_subquery.";";
60 63
61 - $total = $this->wpdb->get_var($sql);
64 + $total = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- SQL is safe, no user input used
62 65
63 66 return array(
64 67 'id_key' => 'ID',
65 68 'columns' => array(
@@ -78,11 +81,13 @@
78 81 /**
79 82 * Do actions after optimize() function.
80 83 */
81 84 public function after_optimize() {
85 + // translators: %s is the number of auto-drafts deleted
82 86 $info_message = sprintf(_n('%s auto draft deleted', '%s auto drafts deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
83 87
84 88 if ($this->is_multisite_mode()) {
89 + // translators: %s is the number of sites
85 90 $info_message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
86 91 }
87 92
88 93 $this->logger->info($info_message);
@@ -95,9 +100,9 @@
95 100 */
96 101 public function optimize() {
97 102 $clean = "DELETE FROM `" . $this->wpdb->posts . "` WHERE post_status = 'auto-draft'";
98 103
99 - if ('true' == $this->retention_enabled) {
104 + if ('true' === $this->retention_enabled) {
100 105 $clean .= ' AND post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
101 106 }
102 107
103 108 // if posted ids in params, then remove only selected items. used by preview widget.
@@ -119,9 +124,10 @@
119 124 * Do actions after get_info() function.
120 125 */
121 126 public function after_get_info() {
122 127
123 - if (0 != $this->found_count && null != $this->found_count) {
128 + if (0 !== $this->found_count && null !== $this->found_count) {
129 + // translators: %s is the number of auto-drafts
124 130 $message = sprintf(_n('%s auto draft post in your database', '%s auto draft posts in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
125 131 } else {
126 132 $message = __('No auto draft posts found', 'wp-optimize');
127 133 }
@@ -126,13 +132,14 @@
126 132 $message = __('No auto draft posts found', 'wp-optimize');
127 133 }
128 134
129 135 if ($this->is_multisite_mode()) {
136 + // translators: %s is the number of sites
130 137 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
131 138 }
132 139
133 140 // add preview link for output.
134 - if (0 != $this->found_count && null != $this->found_count) {
141 + if (0 !== $this->found_count && null !== $this->found_count) {
135 142 $message = $this->get_preview_link($message);
136 143 }
137 144
138 145 $this->register_output($message);
@@ -144,36 +151,28 @@
144 151 */
145 152 public function get_info() {
146 153 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->posts . "` WHERE post_status = 'auto-draft'";
147 154
148 - if ('true' == $this->retention_enabled) {
155 + if ('true' === $this->retention_enabled) {
149 156 $sql .= ' and post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
150 157 }
151 158 $sql .= ';';
152 159
153 - $this->found_count += $this->wpdb->get_var($sql);
160 + $this->found_count += $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- SQL is safe, no user input used
154 161 }
155 162
156 163 /**
157 164 * Return settings label
158 165 *
159 - * @return string|void
166 + * @return string
160 167 */
161 168 public function settings_label() {
162 169
163 - if ('true' == $this->retention_enabled) {
170 + if ('true' === $this->retention_enabled) {
171 + // translators: %s is the retention period in weeks
164 172 return sprintf(__('Clean auto draft posts which are older than %s weeks', 'wp-optimize'), $this->retention_period);
165 173 } else {
166 174 return __('Clean all auto-draft posts', 'wp-optimize');
167 175 }
168 176
169 - }
170 -
171 - /**
172 - * Return description
173 - *
174 - * @return string|void
175 - */
176 - public function get_auto_option_description() {
177 - return __('Remove auto-draft posts', 'wp-optimize');
178 177 }
179 178 }