| @@ -33,11 +33,11 @@ | ||
| 33 | 33 | /* |
| 34 | 34 | * Reindex plugin table |
| 35 | 35 | */ |
| 36 | 36 | public function reindex_table( $return) { |
| 37 | - $nonce = sanitize_text_field(wp_unslash($_POST['nonce'])); | |
| 38 | - if (! wp_verify_nonce($nonce,'wp_chatbot') || ! current_user_can('manage_options')) { | |
| 39 | - wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'chatbot'))); | |
| 37 | + $nonce = sanitize_text_field($_POST['nonce']); | |
| 38 | + if (! wp_verify_nonce($nonce,'wp_chatbot')) { | |
| 39 | + wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'sm'))); | |
| 40 | 40 | wp_die(); |
| 41 | 41 | |
| 42 | 42 | }else{ |
| 43 | 43 | global $wpdb; |
| @@ -49,14 +49,10 @@ | ||
| 49 | 49 | $index_meta = array( |
| 50 | 50 | 'offset' => 0, |
| 51 | 51 | 'start' => true, |
| 52 | 52 | ); |
| 53 | - | |
| 54 | - // phpcs:ignore | |
| 55 | - $wpdb->query("DROP TABLE IF EXISTS {$this->table_name}"); //DB Call OK | |
| 56 | - | |
| 53 | + $wpdb->query("DROP TABLE IF EXISTS {$this->table_name}"); | |
| 57 | 54 | $this->create_table(); |
| 58 | - | |
| 59 | 55 | $index_meta['found_posts'] = $this->get_number_of_products(); |
| 60 | 56 | } else if ( ! empty( $index_meta['site_stack'] ) && $index_meta['offset'] >= $index_meta['found_posts'] ) { |
| 61 | 57 | $status = 'start'; |
| 62 | 58 | $index_meta['start'] = true; |
| @@ -135,9 +131,9 @@ | ||
| 135 | 131 | * Check if index table exist |
| 136 | 132 | */ |
| 137 | 133 | private function is_table_not_exist() { |
| 138 | 134 | global $wpdb; |
| 139 | - return ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $this->table_name ) ) ) != $this->table_name ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 135 | + return ( $wpdb->get_var( "SHOW TABLES LIKE '{$this->table_name}'" ) != $this->table_name ); | |
| 140 | 136 | } |
| 141 | 137 | /* |
| 142 | 138 | * Create index table |
| 143 | 139 | */ |
| @@ -155,30 +151,8 @@ | ||
| 155 | 151 | lang VARCHAR(20) NOT NULL DEFAULT 0 |
| 156 | 152 | ) $charset_collate;"; |
| 157 | 153 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 158 | 154 | dbDelta( $sql ); |
| 159 | - | |
| 160 | - $table_report = $wpdb->prefix . 'wpbot_chat_report'; | |
| 161 | - | |
| 162 | - if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_report ) ) ) != $table_report ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange | |
| 163 | - // phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange | |
| 164 | - $sql_report = " | |
| 165 | - CREATE TABLE `$table_report` ( | |
| 166 | - `id` int(11) NOT NULL AUTO_INCREMENT, | |
| 167 | - `user_id` int(11) NOT NULL, | |
| 168 | - `conversation_id` int(11) DEFAULT NULL, | |
| 169 | - `message` longtext NOT NULL, | |
| 170 | - `feedback` varchar(20) DEFAULT NULL, | |
| 171 | - `meta_info` text DEFAULT NULL, | |
| 172 | - `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 173 | - PRIMARY KEY (`id`) | |
| 174 | - ) $charset_collate AUTO_INCREMENT=1; | |
| 175 | - "; | |
| 176 | - // phpcs:enable WordPress.DB.DirectDatabaseQuery.SchemaChange | |
| 177 | - | |
| 178 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 179 | - dbDelta( $sql_report ); | |
| 180 | - } | |
| 181 | 155 | } |
| 182 | 156 | /* |
| 183 | 157 | * Insert data into the index table |
| 184 | 158 | */ |
| @@ -208,9 +182,9 @@ | ||
| 208 | 182 | $query = "INSERT IGNORE INTO {$this->table_name} |
| 209 | 183 | (`id`, `term`, `term_source`, `type`, `count`, `in_stock`, `visibility`, `lang`) |
| 210 | 184 | VALUES $values |
| 211 | 185 | "; |
| 212 | - $wpdb->query( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 186 | + $wpdb->query( $query ); | |
| 213 | 187 | } |
| 214 | 188 | } |
| 215 | 189 | /* |
| 216 | 190 | * Update index table |
| @@ -223,9 +197,9 @@ | ||
| 223 | 197 | $slug = 'product'; |
| 224 | 198 | if ( $slug != $post->post_type ) { |
| 225 | 199 | return; |
| 226 | 200 | } |
| 227 | - $wpdb->delete( $this->table_name, array( 'id' => $post_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 201 | + $wpdb->delete( $this->table_name, array( 'id' => $post_id ) ); | |
| 228 | 202 | $posts = get_posts( array( |
| 229 | 203 | 'posts_per_page' => -1, |
| 230 | 204 | 'fields' => 'ids', |
| 231 | 205 | 'post_type' => 'product', |
| @@ -258,11 +232,9 @@ | ||
| 258 | 232 | $product_id = $product->get_id(); |
| 259 | 233 | } else { |
| 260 | 234 | $product_id = $product; |
| 261 | 235 | } |
| 262 | - | |
| 263 | - $wpdb->delete( $this->table_name, array( 'id' => $product_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 264 | - | |
| 236 | + $wpdb->delete( $this->table_name, array( 'id' => $product_id ) ); | |
| 265 | 237 | $posts = get_posts( array( |
| 266 | 238 | 'posts_per_page' => -1, |
| 267 | 239 | 'fields' => 'ids', |
| 268 | 240 | 'post_type' => 'product', |
| @@ -276,11 +248,11 @@ | ||
| 276 | 248 | /* |
| 277 | 249 | * Cancel index |
| 278 | 250 | */ |
| 279 | 251 | public function cancel_reindex() { |
| 280 | - $nonce = sanitize_text_field(wp_unslash($_POST['nonce'])); | |
| 281 | - if (! wp_verify_nonce($nonce,'wp_chatbot') || ! current_user_can('manage_options')) { | |
| 282 | - wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'chatbot'))); | |
| 252 | + $nonce = sanitize_text_field($_POST['nonce']); | |
| 253 | + if (! wp_verify_nonce($nonce,'wp_chatbot')) { | |
| 254 | + wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'sm'))); | |
| 283 | 255 | wp_die(); |
| 284 | 256 | |
| 285 | 257 | }else{ |
| 286 | 258 | delete_option( 'wp_chatbot_index_meta' ); |