PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.11
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.11
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 / orphandata.php

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

68 lines 2.1 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_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