| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function reset(array $tables) |
| 26 | 26 | { |
| 27 | - if (wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['submit_reset_form'] ?? '')), 'reset_nounce') && current_user_can('administrator')) { | |
| 27 | + if (wp_verify_nonce(@$_REQUEST['submit_reset_form'], 'reset_nounce') && current_user_can('administrator')) { | |
| 28 | 28 | // Check if current user is Admin and check the nonce |
| 29 | 29 | |
| 30 | 30 | if (in_array('users', $tables)) { |
| 31 | 31 | $this->reset_users = true; |
| @@ -35,9 +35,9 @@ | ||
| 35 | 35 | $this->set_backup(); |
| 36 | 36 | $this->reinstall(); |
| 37 | 37 | $this->restore_backup(); |
| 38 | 38 | } else { |
| 39 | - throw new Exception(esc_html__('Please reload the page and try again. Double check your security code.', 'wordpress-database-reset')); | |
| 39 | + throw new Exception(__('Please reload the page and try again. Double check your security code.', 'wordpress-database-reset')); | |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | private function validate_selected(array $tables) |
| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | $this->selected = array_flip($tables); |
| 47 | 47 | return; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - throw new Exception(esc_html__('You did not select any database tables', 'wordpress-database-reset')); | |
| 50 | + throw new Exception(__('You did not select any database tables', 'wordpress-database-reset')); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | private function set_backup() |
| 54 | 54 | { |
| @@ -72,10 +72,9 @@ | ||
| 72 | 72 | global $wpdb; |
| 73 | 73 | $this->backup = array(); |
| 74 | 74 | |
| 75 | 75 | foreach ($tables as $table) { |
| 76 | - $wpdb->wp_database_reset_table = $table; | |
| 77 | - $this->backup[$table] = $wpdb->get_results("SELECT * FROM {$wpdb->wp_database_reset_table}"); //phpcs:ignore | |
| 76 | + $this->backup[$table] = $wpdb->get_results("SELECT * FROM {$table}"); | |
| 78 | 77 | } |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | private function set_user_session_tokens() |
| @@ -122,9 +121,9 @@ | ||
| 122 | 121 | { |
| 123 | 122 | global $wpdb; |
| 124 | 123 | |
| 125 | 124 | foreach ($this->wp_tables as $wp_table) { |
| 126 | - $wpdb->query("DROP TABLE {$wp_table}"); //phpcs:ignore | |
| 125 | + $wpdb->query("DROP TABLE {$wp_table}"); | |
| 127 | 126 | } |
| 128 | 127 | } |
| 129 | 128 | |
| 130 | 129 | private function install_wp() |
| @@ -144,13 +143,13 @@ | ||
| 144 | 143 | $current_user = $this->user; |
| 145 | 144 | |
| 146 | 145 | $user_id = $this->reset_users ? 1 : $this->user->ID; |
| 147 | 146 | |
| 148 | - $wpdb->query( //phpcs:ignore | |
| 147 | + $wpdb->query( | |
| 149 | 148 | $wpdb->prepare( |
| 150 | 149 | "UPDATE $wpdb->users |
| 151 | - SET user_pass = %s, user_activation_key = '' | |
| 152 | - WHERE ID = %d", | |
| 150 | + SET user_pass = '%s', user_activation_key = '' | |
| 151 | + WHERE ID = '%d'", | |
| 153 | 152 | $this->user->user_pass, |
| 154 | 153 | $user_id |
| 155 | 154 | ) |
| 156 | 155 | ); |
| @@ -181,10 +180,9 @@ | ||
| 181 | 180 | { |
| 182 | 181 | global $wpdb; |
| 183 | 182 | |
| 184 | 183 | foreach ($tables as $table) { |
| 185 | - $wpdb->wp_database_reset_table = $table; | |
| 186 | - $wpdb->query("DELETE FROM {$wpdb->wp_database_reset_table}");//phpcs:ignore | |
| 184 | + $wpdb->query("DELETE FROM {$table}"); | |
| 187 | 185 | } |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | 188 | private function restore_backup_tables(array $tables) |
| @@ -192,15 +190,16 @@ | ||
| 192 | 190 | global $wpdb; |
| 193 | 191 | |
| 194 | 192 | foreach ($tables as $table => $data) { |
| 195 | 193 | foreach ($data as $row) { |
| 196 | - $data = array(); | |
| 194 | + $columns = $values = array(); | |
| 197 | 195 | |
| 198 | 196 | foreach ($row as $column => $value) { |
| 199 | - $data[$column] = $value; | |
| 197 | + $columns[] = $column; | |
| 198 | + $values[] = esc_sql($value); | |
| 200 | 199 | } |
| 201 | 200 | |
| 202 | - $wpdb->insert( $table, $data ); //phpcs:ignore | |
| 201 | + $wpdb->query("INSERT INTO $table (" . implode(', ', $columns) . ") VALUES ('" . implode("', '", $values) . "')"); | |
| 203 | 202 | } |
| 204 | 203 | } |
| 205 | 204 | } |
| 206 | 205 | |