PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.5.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.5.2
4.7.0 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 All 111 releases
wp-optimize / optimizations / orphandata.php

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

77 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) 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 // translators: %s - number of deleted orphaned relationship data
18 $message = sprintf(_n('%s orphaned relationship data deleted', '%s orphaned relationship data deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
19
20 if ($this->is_multisite_mode()) {
21 // translators: %s - number of sites
22 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
23 }
24
25 $this->logger->info($message);
26 $this->register_output($message);
27 }
28
29 /**
30 * Do optimization.
31 */
32 public function optimize() {
33 $clean = "DELETE FROM `" . $this->wpdb->term_relationships . "` WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM `" . $this->wpdb->posts . "`);";
34
35 $orphandata = $this->query($clean);
36 $this->processed_count += $orphandata;
37 }
38
39 /**
40 * Do actions after get_info() function.
41 */
42 public function after_get_info() {
43 if ($this->found_count > 0) {
44 // translators: %s - number of orphaned relationship data
45 $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));
46 } else {
47 $message = __('No orphaned relationship data in your database', 'wp-optimize');
48 }
49
50 if ($this->is_multisite_mode()) {
51 // translators: %s - number of sites
52 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
53 }
54
55 $this->register_output($message);
56 }
57
58 /**
59 * Get count of unoptimized items.
60 */
61 public function get_info() {
62 $sql = "SELECT COUNT(*) FROM `{$this->wpdb->term_relationships}` WHERE term_taxonomy_id=%d AND object_id NOT IN (SELECT id FROM `{$this->wpdb->posts}`);";
63 $orphandata = $this->wpdb->get_var($this->wpdb->prepare($sql, 1)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- `$this->wpdb` is `$wpdb`
64
65 $this->found_count += $orphandata;
66 }
67
68 /**
69 * Returns settings label
70 *
71 * @return string
72 */
73 public function settings_label() {
74 return __('Clean orphaned relationship data', 'wp-optimize');
75 }
76 }
77