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/spam.php +21 -13 3.2.22 → 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_spam extends WP_Optimization {
6 6
7 7 public $available_for_auto = true;
@@ -37,17 +37,19 @@
37 37 */
38 38 public function preview($params) {
39 39
40 40 // get clicked comment type link.
41 - $type = isset($params['type']) && 'spam' == $params['type'] ? 'spam' : 'trash';
41 + $type = isset($params['type']) && 'spam' === $params['type'] ? 'spam' : 'trash';
42 42
43 43 $retention_subquery = '';
44 44
45 - if ('true' == $this->retention_enabled) {
45 + if ('true' === $this->retention_enabled) {
46 46 $retention_subquery = ' and comment_date < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
47 47 }
48 48
49 49 // get data requested for preview.
50 + // `$this->wpdb->prepare` is global `$wpdb->prepare`
51 + // phpcs:disable
50 52 $sql = $this->wpdb->prepare(
51 53 "SELECT comment_ID, comment_author, SUBSTR(comment_content, 1, 128) AS comment_content FROM".
52 54 " `" . $this->wpdb->comments . "`".
53 55 " WHERE comment_approved = '{$type}'".
@@ -59,8 +61,9 @@
59 61 )
60 62 );
61 63
62 64 $comments = $this->wpdb->get_results($sql, ARRAY_A);
65 + // phpcs:enable
63 66
64 67 // fix empty revision titles.
65 68 if (!empty($comments)) {
66 69 foreach ($comments as $key => $comment) {
@@ -76,9 +79,9 @@
76 79
77 80 // get total count comments for optimization.
78 81 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_approved = '{$type}' ".$retention_subquery.";";
79 82
80 - $total = $this->wpdb->get_var($sql);
83 + $total = $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe no user input used
81 84
82 85 return array(
83 86 'id_key' => 'comment_ID',
84 87 'columns' => array(
@@ -105,13 +108,16 @@
105 108 /**
106 109 * Do actions after optimize() function.
107 110 */
108 111 public function after_optimize() {
112 + // translators: %s: number of spam comments deleted
109 113 $message = sprintf(_n('%s spam comment deleted', '%s spam comments deleted', $this->processed_spam_count, 'wp-optimize'), number_format_i18n($this->processed_spam_count));
114 + // translators: %s: number of comments removed from Trash
110 115 $message1 = sprintf(_n('%s comment removed from Trash', '%s comments removed from Trash', $this->processed_trash_count, 'wp-optimize'), number_format_i18n($this->processed_trash_count));
111 116
112 117
113 118 if ($this->is_multisite_mode()) {
119 + // translators: %s: number of sites
114 120 $blogs_count_text = sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
115 121
116 122 $message .= ' '.$blogs_count_text;
117 123 $message1 .= ' '.$blogs_count_text;
@@ -140,14 +146,14 @@
140 146 /**
141 147 * Delete comments by $type along with comments meta from database.
142 148 *
143 149 * @param string $type comment type.
144 - * @return array
150 + * @return mixed
145 151 */
146 152 public function delete_comments_by_type($type) {
147 153 $clean = "DELETE c, cm FROM `" . $this->wpdb->comments . "` c LEFT JOIN `" . $this->wpdb->commentmeta . "` cm ON c.comment_ID = cm.comment_id WHERE c.comment_approved = '{$type}'";
148 154
149 - if ('true' == $this->retention_enabled) {
155 + if ('true' === $this->retention_enabled) {
150 156 $clean .= ' and c.comment_date < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
151 157 }
152 158
153 159 // if posted ids in params, then remove only selected items. used by preview widget.
@@ -172,8 +178,9 @@
172 178 */
173 179 public function after_get_info() {
174 180
175 181 if ($this->found_spam_count > 0) {
182 + // translators: %s: number of spam comments
176 183 $message = sprintf(_n('%s spam comment found', '%s spam comments found', $this->found_spam_count, 'wp-optimize'), number_format_i18n($this->found_spam_count));
177 184
178 185 // if current version is not premium and Preview feature not supported then
179 186 // add to message Review link to comments page
@@ -185,8 +192,9 @@
185 192 $message = __('No spam comments found', 'wp-optimize');
186 193 }
187 194
188 195 if ($this->found_trash_count > 0) {
196 + // translators: %s is the number of trashed comments
189 197 $message1 = sprintf(_n('%s trashed comment found', '%s trashed comments found', $this->found_trash_count, 'wp-optimize'), number_format_i18n($this->found_trash_count));
190 198
191 199 // if current version is not premium and Preview feature not supported then
192 200 // add to message Review link to comments page
@@ -197,8 +205,9 @@
197 205 $message1 = __('No trashed comments found', 'wp-optimize');
198 206 }
199 207
200 208 if ($this->is_multisite_mode()) {
209 + // translators: %s is the number of sites
201 210 $blogs_count_text = sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
202 211
203 212 $message .= ' '.$blogs_count_text;
204 213 $message1 .= ' '.$blogs_count_text;
@@ -233,28 +242,27 @@
233 242 * @return mixed
234 243 */
235 244 public function get_count_comments($type) {
236 245 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_approved = '{$type}'";
237 - if ('true' == $this->retention_enabled) {
246 + if ('true' === $this->retention_enabled) {
238 247 $sql .= ' and comment_date < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
239 248 }
240 249 $sql .= ';';
241 250
242 - return $this->wpdb->get_var($sql);
251 + return $this->wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- safe
243 252 }
244 253
245 254 /**
246 255 * Do actions after get_info() function.
256 + *
257 + * @return string
247 258 */
248 259 public function settings_label() {
249 260
250 - if ('true' == $this->retention_enabled) {
261 + if ('true' === $this->retention_enabled) {
262 + // translators: %s is the number of weeks
251 263 return sprintf(__('Remove spam and trashed comments which are older than %d weeks', 'wp-optimize'), $this->retention_period);
252 264 } else {
253 265 return __('Remove spam and trashed comments', 'wp-optimize');
254 266 }
255 - }
256 -
257 - public function get_auto_option_description() {
258 - return __('Remove spam and trashed comments', 'wp-optimize');
259 267 }
260 268 }