| 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 |
|