| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WPO_VERSION')) die('No direct access allowed'); |
| 4 |
|
| 5 |
class WP_Optimization_postmeta extends WP_Optimization { |
| 6 |
|
| 7 |
public $ui_sort_order = 8000; |
| 8 |
|
| 9 |
public $available_for_auto = false; |
| 10 |
|
| 11 |
public $auto_default = false; |
| 12 |
|
| 13 |
/** |
| 14 |
* Do actions after optimize() function. |
| 15 |
*/ |
| 16 |
public function after_optimize() { |
| 17 |
$message = sprintf(_n('%s orphaned post meta data deleted', '%s orphaned post meta data deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count)); |
| 18 |
|
| 19 |
if ($this->is_multisite_mode()) { |
| 20 |
$message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 21 |
} |
| 22 |
|
| 23 |
$this->logger->info($message); |
| 24 |
$this->register_output($message); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Do optimization. |
| 29 |
*/ |
| 30 |
public function optimize() { |
| 31 |
$clean = "DELETE pm FROM `" . $this->wpdb->postmeta . "` pm LEFT JOIN `" . $this->wpdb->posts . "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;"; |
| 32 |
|
| 33 |
$postmeta = $this->query($clean); |
| 34 |
$this->processed_count += $postmeta; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Do actions after get_info() function. |
| 39 |
*/ |
| 40 |
public function after_get_info() { |
| 41 |
if ($this->found_count) { |
| 42 |
$message = sprintf(_n('%s orphaned post meta data in your database', '%s orphaned post meta data in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); |
| 43 |
} else { |
| 44 |
$message = __('No orphaned post meta data in your database', 'wp-optimize'); |
| 45 |
} |
| 46 |
|
| 47 |
if ($this->is_multisite_mode()) { |
| 48 |
$message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids)); |
| 49 |
} |
| 50 |
|
| 51 |
$this->register_output($message); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get count of unoptimized items. |
| 56 |
*/ |
| 57 |
public function get_info() { |
| 58 |
$sql = "SELECT COUNT(*) FROM `" . $this->wpdb->postmeta . "` pm LEFT JOIN `" . $this->wpdb->posts . "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;"; |
| 59 |
$postmeta = $this->wpdb->get_var($sql); |
| 60 |
|
| 61 |
$this->found_count += $postmeta; |
| 62 |
} |
| 63 |
|
| 64 |
public function settings_label() { |
| 65 |
return __('Clean post meta data', 'wp-optimize'); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* N.B. This is not currently used; it was commented out in 1.9.1 |
| 70 |
* |
| 71 |
* @return string Returns the description once auto remove option has ran |
| 72 |
*/ |
| 73 |
public function get_auto_option_description() { |
| 74 |
return __('Remove orphaned post meta', 'wp-optimize'); |
| 75 |
} |
| 76 |
} |
| 77 |
|