| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | * Check if cache table exist |
| 53 | 53 | */ |
| 54 | 54 | private function is_cache_table_not_exist() { |
| 55 | 55 | global $wpdb; |
| 56 | - return ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $this->cache_table_name ) ) ) != $this->cache_table_name ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 56 | + return ( $wpdb->get_var( "SHOW TABLES LIKE '{$this->cache_table_name}'" ) != $this->cache_table_name ); | |
| 57 | 57 | } |
| 58 | 58 | /* |
| 59 | 59 | * Create cache table |
| 60 | 60 | */ |
| @@ -71,37 +71,38 @@ | ||
| 71 | 71 | /* |
| 72 | 72 | * Insert data into cache table |
| 73 | 73 | */ |
| 74 | 74 | public function insert_into_cache_table( $cache_option_name, $result_array ) { |
| 75 | - | |
| 76 | 75 | global $wpdb; |
| 77 | - | |
| 78 | - $query = $wpdb->prepare("INSERT IGNORE INTO {$this->cache_table_name} | |
| 76 | + $values = $wpdb->prepare( | |
| 77 | + "(%s, %s)", | |
| 78 | + $cache_option_name, json_encode( $result_array ) | |
| 79 | + ); | |
| 80 | + $query = "INSERT IGNORE INTO {$this->cache_table_name} | |
| 79 | 81 | (`name`, `value`) |
| 80 | - VALUES (%s, %s)", $cache_option_name, json_encode( $result_array )); | |
| 81 | - | |
| 82 | - $wpdb->query( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 83 | - | |
| 82 | + VALUES $values | |
| 83 | + "; | |
| 84 | + $wpdb->query( $query ); | |
| 84 | 85 | if ( $wpdb->last_error ) { |
| 85 | 86 | if ( $this->is_cache_table_not_exist() ) { |
| 86 | 87 | $this->create_cache_table(); |
| 87 | 88 | } |
| 88 | 89 | } |
| 89 | - | |
| 90 | 90 | } |
| 91 | 91 | /* |
| 92 | 92 | * Get data from cache table |
| 93 | 93 | */ |
| 94 | 94 | public function get_from_cache_table( $cache_option_name ) { |
| 95 | - | |
| 96 | 95 | global $wpdb; |
| 97 | - | |
| 98 | 96 | $result = ''; |
| 99 | - | |
| 100 | - $safe_sql = $wpdb->prepare("SELECT * FROM {$this->cache_table_name} WHERE `name` LIKE %s", $cache_option_name); | |
| 101 | - | |
| 102 | - $cache_content = $wpdb->get_results( $safe_sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 103 | - | |
| 97 | + $where = $wpdb->prepare( " name LIKE %s", $cache_option_name ); | |
| 98 | + $sql = "SELECT * | |
| 99 | + FROM | |
| 100 | + {$this->cache_table_name} | |
| 101 | + WHERE | |
| 102 | + {$where} | |
| 103 | + "; | |
| 104 | + $cache_content = $wpdb->get_results( $sql, ARRAY_A ); | |
| 104 | 105 | if ( ! $wpdb->last_error ) { |
| 105 | 106 | if (!empty($cache_content) && !is_wp_error($cache_content) && is_array($cache_content)) { |
| 106 | 107 | $result = $cache_content[0]['value']; |
| 107 | 108 | } |