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 / unapproved.php

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

98 lines 2.9 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_unapproved extends WP_Optimization {
6
7 public $available_for_auto = true;
8
9 public $auto_default = false;
10
11 public $setting_default = true;
12
13 public $available_for_saving = true;
14
15 public $ui_sort_order = 4000;
16
17 /**
18 * Do actions after optimize() function.
19 */
20 public function after_optimize() {
21 $message = sprintf(_n('%s unapproved comment deleted', '%s unapproved comments 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 $awaiting_mod = wp_count_comments();
31 $awaiting_mod = $awaiting_mod->moderated;
32
33 $this->register_meta('awaiting_mod', $awaiting_mod);
34 }
35
36 /**
37 * Unapproved-comments / unapproved
38 * need to check what IDs were previously used before (dom ID, settings ID),
39 * as there was a note about unapproved-comments in the source, which isn't in use now here.
40 */
41 public function optimize() {
42 $clean = "DELETE c, cm FROM `" . $this->wpdb->comments . "` c LEFT JOIN `" . $this->wpdb->commentmeta . "` cm ON c.comment_ID = cm.comment_id WHERE comment_approved = '0' ";
43
44 if ('true' == $this->retention_enabled) {
45 $clean .= ' and c.comment_date < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
46 }
47
48 $clean .= ';';
49
50 $comments = $this->query($clean);
51 $this->processed_count += $comments;
52 }
53
54 /**
55 * Do actions after get_info() function.
56 */
57 public function after_get_info() {
58 if ($this->found_count) {
59 $message = sprintf(_n('%s unapproved comment found', '%s unapproved comments found', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
60 } else {
61 $message = __('No unapproved comments found', 'wp-optimize');
62 }
63
64 if ($this->is_multisite_mode()) {
65 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
66 }
67
68 $this->register_output($message);
69 }
70
71 /**
72 * Get count of unoptimized items.
73 */
74 public function get_info() {
75 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->comments . "` WHERE comment_approved = '0'";
76
77 if ('true' == $this->retention_enabled) {
78 $sql .= ' and comment_date < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
79 }
80 $sql .= ';';
81
82 $comments = $this->wpdb->get_var($sql);
83 $this->found_count += $comments;
84 }
85
86 public function settings_label() {
87 if ('true' == $this->retention_enabled) {
88 return sprintf(__('Remove unapproved comments which are older than %d weeks', 'wp-optimize'), $this->retention_period);
89 } else {
90 return __('Remove unapproved comments', 'wp-optimize');
91 }
92 }
93
94 public function get_auto_option_description() {
95 return __('Remove unapproved comments', 'wp-optimize');
96 }
97 }
98