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

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

108 lines 2.7 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_autodraft extends WP_Optimization {
6
7 public $available_for_auto = true;
8
9 public $auto_default = true;
10
11 public $setting_default = true;
12
13 public $available_for_saving = true;
14
15 public $ui_sort_order = 3000;
16
17 protected $setting_id = 'drafts';
18
19 protected $auto_id = 'drafts';
20
21 /**
22 * Do actions after optimize() function.
23 */
24 public function after_optimize() {
25 $info_message = sprintf(_n('%s auto draft deleted', '%s auto drafts deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
26
27 if ($this->is_multisite_mode()) {
28 $info_message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
29 }
30
31 $this->logger->info($info_message);
32 $this->register_output($info_message);
33
34 }
35
36 /**
37 * Do optimization.
38 */
39 public function optimize() {
40 $clean = "DELETE FROM `" . $this->wpdb->posts . "` WHERE post_status = 'auto-draft'";
41
42 if ('true' == $this->retention_enabled) {
43 $clean .= ' AND post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
44 }
45
46 $clean .= ';';
47
48 $this->processed_count += $this->query($clean);
49 }
50
51 /**
52 * Do actions after get_info() function.
53 */
54 public function after_get_info() {
55
56 if (0 != $this->found_count && null != $this->found_count) {
57 $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));
58 } else {
59 $message = __('No auto draft posts found', 'wp-optimize');
60 }
61
62 if ($this->is_multisite_mode()) {
63 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
64 }
65
66 $this->register_output($message);
67
68 }
69
70 /**
71 * Get count of unoptimized items.
72 */
73 public function get_info() {
74 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->posts . "` WHERE post_status = 'auto-draft'";
75
76 if ('true' == $this->retention_enabled) {
77 $sql .= ' and post_modified < NOW() - INTERVAL ' . $this->retention_period . ' WEEK';
78 }
79 $sql .= ';';
80
81 $this->found_count += $this->wpdb->get_var($sql);
82 }
83
84 /**
85 * Return settings label
86 *
87 * @return string|void
88 */
89 public function settings_label() {
90
91 if ('true' == $this->retention_enabled) {
92 return sprintf(__('Clean auto draft posts which are older than %s weeks', 'wp-optimize'), $this->retention_period);
93 } else {
94 return __('Clean all auto-draft posts', 'wp-optimize');
95 }
96
97 }
98
99 /**
100 * Return description
101 *
102 * @return string|void
103 */
104 public function get_auto_option_description() {
105 return __('Remove auto-draft posts', 'wp-optimize');
106 }
107 }
108