| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WPO_VERSION')) die('No direct access allowed'); |
| 4 |
|
| 5 |
class WP_Optimization_orphandata extends WP_Optimization { |
| 6 |
|
| 7 |
public $ui_sort_order = 10000; |
| 8 |
|
| 9 |
public $available_for_saving = true; |
| 10 |
|
| 11 |
public $support_preview = false; |
| 12 |
|
| 13 |
/** |
| 14 |
* Do actions after optimize() function. |
| 15 |
*/ |
| 16 |
public function after_optimize() { |
| 17 |
$message = sprintf(_n('%s orphaned meta data deleted', '%s orphaned 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 FROM `" . $this->wpdb->term_relationships . "` WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM `" . $this->wpdb->posts . "`);"; |
| 32 |
|
| 33 |
$orphandata = $this->query($clean); |
| 34 |
$this->processed_count += $orphandata; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Do actions after get_info() function. |
| 39 |
*/ |
| 40 |
public function after_get_info() { |
| 41 |
if ($this->found_count > 0) { |
| 42 |
$message = sprintf(_n('%s orphaned relationship data in your database', '%s orphaned relationship data in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count)); |
| 43 |
} else { |
| 44 |
$message = __('No orphaned relationship 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->term_relationships . "` WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM `" . $this->wpdb->posts . "`);"; |
| 59 |
$orphandata = $this->wpdb->get_var($sql); |
| 60 |
|
| 61 |
$this->found_count += $orphandata; |
| 62 |
} |
| 63 |
|
| 64 |
public function settings_label() { |
| 65 |
return __('Clean orphaned relationship data', 'wp-optimize'); |
| 66 |
} |
| 67 |
} |
| 68 |
|