PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
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
← All changes | optimizations/orphanedtables.php +25 -20 3.2.20 → 4.7.0 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -if (!defined('WPO_VERSION')) die('No direct access allowed');
3 +if (!defined('ABSPATH')) die('No direct access allowed');
4 4
5 5 class WP_Optimization_orphanedtables extends WP_Optimization {
6 6
7 7 public $available_for_auto = false;
@@ -27,12 +27,13 @@
27 27 * Run optimization.
28 28 */
29 29 public function optimize() {
30 30 // check if the data contain action attribute then lead to innoDb conversion.
31 - if (isset($this->data['optimization_action']) && 'toinnodb' == $this->data['optimization_action']) {
31 + if (isset($this->data['optimization_action']) && 'toinnodb' === $this->data['optimization_action']) {
32 32 $table = $this->optimizer->get_table($this->data['optimization_table']);
33 33 if (false === $table) {
34 34 $this->register_meta('error', 1);
35 + // translators: %s is the table name
35 36 $this->register_meta('message', sprintf(__('The table "%s" does not exist.', 'wp-optimize'), $this->data['optimization_table']));
36 37 return false;
37 38 }
38 39 $result = $this->convert_table($table);
@@ -45,13 +46,14 @@
45 46 return true;
46 47 }
47 48
48 49 // check if single table name posted or optimize all tables.
49 - if (isset($this->data['optimization_table']) && '' != $this->data['optimization_table']) {
50 + if (isset($this->data['optimization_table']) && '' !== $this->data['optimization_table']) {
50 51 $table = $this->optimizer->get_table($this->data['optimization_table']);
51 52
52 53 if (false === $table) {
53 54 $this->register_meta('error', 1);
55 + // translators: %s is the table name
54 56 $this->register_meta('message', sprintf(__('The table "%s" does not exist.', 'wp-optimize'), $this->data['optimization_table']));
55 57 return false;
56 58 }
57 59
@@ -74,12 +76,14 @@
74 76 $deleted++;
75 77 }
76 78 }
77 79
78 - $this->register_output(sprintf(_n('%s orphaned table deleted', '%s orphaned tables deleted', $deleted), $deleted));
80 + // translators: %s is the number of deleted orphaned tables
81 + $this->register_output(sprintf(_n('%s orphaned table deleted', '%s orphaned tables deleted', $deleted, 'wp-optimize'), $deleted));
79 82
80 83 if ($deleted > 0) {
81 - $this->register_output(sprintf(_n('Deleting %s orphaned table was unsuccessful', 'Repairing %s orphaned tables were unsuccessful', $deleted), $deleted));
84 + // translators: %s is the number of tables
85 + $this->register_output(sprintf(_n('Deleting %s orphaned table was unsuccessful', 'Repairing %s orphaned tables were unsuccessful', $deleted, 'wp-optimize'), $deleted));
82 86 }
83 87 }
84 88 }
85 89
@@ -97,29 +101,29 @@
97 101
98 102 // check InnoDB is Active
99 103 $mysql_engine = $wpdb->get_results('SHOW ENGINES');
100 104 foreach ($mysql_engine as $check) {
101 - if ('InnoDB' == $check->Engine && ('DEFAULT' == $check->Support || 'YES' == $check->Support)) {
105 + if ('InnoDB' === $check->Engine && ('DEFAULT' === $check->Support || 'YES' === $check->Support)) {
102 106 $inno_db=1;
103 107 }
104 108 }
105 109
106 110
107 - if (0 == $inno_db) return false;
111 + if (0 === $inno_db) return false;
108 112 // If InnoDB is active then convert MyISAM to InnoDB.
109 113 else {
110 - $table_name = sanitize_text_field($table_obj->Name);
111 - $sql_query = $wpdb->prepare("ALTER TABLE `%1s` ENGINE=InnoDB", $table_name);
114 + $table_name = esc_sql($table_obj->Name);
115 + $sql_query = "ALTER TABLE `{$table_name}` ENGINE=InnoDB";
112 116 $this->logger->info($sql_query);
113 - $result = $wpdb->query($sql_query);
117 + $result = $wpdb->query($sql_query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Statement is safe, not using user input
114 118 }
115 119 // check if alter query finished successfully.
116 - if ('' != $wpdb->last_error) {
120 + if ('' !== $wpdb->last_error) {
117 121 $this->last_message = $wpdb->last_error;
118 122 $this->logger->info($wpdb->last_error);
119 123 }
120 124
121 - return $result;
125 + return (bool) $result;
122 126 }
123 127
124 128 /**
125 129 * Drop table from database.
@@ -133,22 +137,22 @@
133 137
134 138 // don't delete table if it in use and plugin active.
135 139 if (!$table_obj->can_be_removed) return true;
136 140
137 - $table_name = sanitize_text_field($table_obj->Name);
138 - $sql_query = $wpdb->prepare("DROP TABLE `%1s`", $table_name);
141 + $table_name = esc_sql($table_obj->Name);
142 + $sql_query = "DROP TABLE `{$table_name}`";
139 143
140 144 $this->logger->info($sql_query);
141 145
142 - $result = $wpdb->query($sql_query);
146 + $result = $wpdb->query($sql_query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Statement is safe, not using user input
143 147
144 148 // check if drop query finished successfully.
145 - if ('' != $wpdb->last_error) {
149 + if ('' !== $wpdb->last_error) {
146 150 $this->last_message = $wpdb->last_error;
147 151 $this->logger->info($wpdb->last_error);
148 152 }
149 153
150 - return $result;
154 + return (bool) $result;
151 155 }
152 156
153 157 /**
154 158 * Get count of unused database tables, i.e. not using by any of installed plugin.
@@ -161,9 +165,9 @@
161 165 $unused_tables = 0;
162 166
163 167 if (!empty($tablesinfo)) {
164 168 foreach ($tablesinfo as $tableinfo) {
165 - if (false == $tableinfo->is_using) {
169 + if (!$tableinfo->is_using) {
166 170 $unused_tables++;
167 171 }
168 172 }
169 173 }
@@ -177,12 +181,13 @@
177 181 public function get_info() {
178 182
179 183 $corrupted_tables = $this->get_unused_tables_count();
180 184
181 - if (0 == $corrupted_tables) {
185 + if (0 === $corrupted_tables) {
182 186 $this->register_output(__('No corrupted tables found', 'wp-optimize'));
183 187 } else {
184 - $this->register_output(sprintf(_n('%s corrupted table found', '%s corrupted tables found', $corrupted_tables), $corrupted_tables));
188 + // translators: %s is the number of corrupted tables
189 + $this->register_output(sprintf(_n('%s corrupted table found', '%s corrupted tables found', $corrupted_tables, 'wp-optimize'), $corrupted_tables));
185 190 }
186 191 }
187 192
188 193 /**