PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.19
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.19
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 / usermeta.php

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

135 lines 3.8 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_usermeta extends WP_Optimization {
6
7 public $ui_sort_order = 8001;
8
9 public $available_for_auto = true;
10
11 public $available_for_saving = true;
12
13 public $auto_default = false;
14
15 /**
16 * Prepare data for preview widget.
17 *
18 * @param array $params
19 *
20 * @return array
21 */
22 public function preview($params) {
23 // get data requested for preview.
24 $sql = $this->wpdb->prepare(
25 "SELECT um.* FROM `" . $this->wpdb->usermeta . "` um".
26 " LEFT JOIN `" . $this->wpdb->users . "` wu ON wu.ID = um.user_id".
27 " WHERE wu.ID IS NULL".
28 " ORDER BY um.umeta_id LIMIT %d, %d;",
29 array(
30 $params['offset'],
31 $params['limit'],
32 )
33 );
34
35 $users = $this->wpdb->get_results($sql, ARRAY_A);
36
37 // get total count user meta for optimization.
38 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->usermeta . "` um LEFT JOIN `" . $this->wpdb->users . "` wu ON wu.ID = um.user_id WHERE wu.ID IS NULL;";
39
40 $total = $this->wpdb->get_var($sql);
41
42 return array(
43 'id_key' => 'umeta_id',
44 'columns' => array(
45 'umeta_id' => __('ID', 'wp-optimize'),
46 'user_id' => __('User ID', 'wp-optimize'),
47 'meta_key' => __('Meta Key', 'wp-optimize'),
48 'meta_value' => __('Meta Value', 'wp-optimize'),
49 ),
50 'offset' => $params['offset'],
51 'limit' => $params['limit'],
52 'total' => $total,
53 'data' => $this->htmlentities_array($users, array('ID')),
54 'message' => $total > 0 ? '' : __('No orphaned user meta data in your database', 'wp-optimize'),
55 );
56 }
57
58 /**
59 * Do actions after optimize() function.
60 */
61 public function after_optimize() {
62 $message = sprintf(_n('%s orphaned user meta data deleted', '%s orphaned user meta data deleted', $this->processed_count, 'wp-optimize'), number_format_i18n($this->processed_count));
63
64 if ($this->is_multisite_mode()) {
65 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
66 }
67
68 $this->logger->info($message);
69 $this->register_output($message);
70 }
71
72 /**
73 * Do optimization.
74 */
75 public function optimize() {
76 $clean = "DELETE um FROM `" . $this->wpdb->usermeta . "` um LEFT JOIN `" . $this->wpdb->users . "` wu ON wu.ID = um.user_id WHERE wu.ID IS NULL";
77
78 // if posted ids in params, then remove only selected items. used by preview widget.
79 if (isset($this->data['ids'])) {
80 $clean .= ' AND um.umeta_id in ('.join(',', $this->data['ids']).')';
81 }
82
83 $clean .= ";";
84
85 $usermeta = $this->query($clean);
86 $this->processed_count += $usermeta;
87 }
88
89 /**
90 * Do actions after get_info() function.
91 */
92 public function after_get_info() {
93 if ($this->found_count) {
94 $message = sprintf(_n('%s orphaned user meta data in your database', '%s orphaned user meta data in your database', $this->found_count, 'wp-optimize'), number_format_i18n($this->found_count));
95 } else {
96 $message = __('No orphaned user meta data in your database', 'wp-optimize');
97 }
98
99 if ($this->is_multisite_mode()) {
100 $message .= ' ' . sprintf(_n('across %s site', 'across %s sites', count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
101 }
102
103 // add preview link to message.
104 if ($this->found_count > 0) {
105 $message = $this->get_preview_link($message);
106 }
107
108 $this->register_output($message);
109 }
110
111 /**
112 * Get count of unoptimized items.
113 */
114 public function get_info() {
115 $sql = "SELECT COUNT(*) FROM `" . $this->wpdb->usermeta . "` um LEFT JOIN `" . $this->wpdb->users . "` wu ON wu.ID = um.user_id WHERE wu.ID IS NULL;";
116 $usermeta = $this->wpdb->get_var($sql);
117
118 $this->found_count += $usermeta;
119 }
120
121 /**
122 * Get settings label.
123 */
124 public function settings_label() {
125 return __('Clean user meta data', 'wp-optimize');
126 }
127
128 /**
129 * Get auto option description.
130 */
131 public function get_auto_option_description() {
132 return __('Remove orphaned user meta', 'wp-optimize');
133 }
134 }
135