| @@ -121,14 +121,21 @@ | ||
| 121 | 121 | */ |
| 122 | 122 | public function clear_all(): bool { |
| 123 | 123 | global $wpdb; |
| 124 | 124 | |
| 125 | - // Clear memory cache (if using object cache) | |
| 126 | - wp_cache_flush_group(self::CACHE_GROUP); | |
| 125 | + // Clear memory cache (if using object cache). | |
| 126 | + // wp_cache_flush_group() is WP 6.1+ and the plugin supports 6.0; see | |
| 127 | + // Schema_Cache_Manager::clear_all() for the reasoning behind the | |
| 128 | + // fallback rather than a skip. | |
| 129 | + if (function_exists('wp_cache_flush_group')) { | |
| 130 | + wp_cache_flush_group(self::CACHE_GROUP); | |
| 131 | + } else { | |
| 132 | + wp_cache_flush(); | |
| 133 | + } | |
| 127 | 134 | |
| 128 | 135 | // Clear database cache |
| 129 | 136 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 130 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name is properly constructed from controlled prefix, cache clearing requires direct database access | |
| 137 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix, cache clearing requires direct database access | |
| 131 | 138 | $result = $wpdb->query("DELETE FROM {$table_name}"); |
| 132 | 139 | |
| 133 | 140 | return $result !== false; |
| 134 | 141 | } |
| @@ -143,12 +150,12 @@ | ||
| 143 | 150 | |
| 144 | 151 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 145 | 152 | $current_time = time(); |
| 146 | 153 | |
| 147 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache cleanup requires direct database access | |
| 154 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache cleanup requires direct database access | |
| 148 | 155 | $result = $wpdb->query( |
| 149 | 156 | $wpdb->prepare( |
| 150 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is properly constructed from controlled prefix | |
| 157 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix | |
| 151 | 158 | "DELETE FROM {$table_name} WHERE expires_at < %d", |
| 152 | 159 | $current_time |
| 153 | 160 | ) |
| 154 | 161 | ); |
| @@ -166,22 +173,22 @@ | ||
| 166 | 173 | |
| 167 | 174 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 168 | 175 | $current_time = time(); |
| 169 | 176 | |
| 170 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name is properly constructed from controlled prefix, cache stats require direct database access | |
| 177 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix, cache stats require direct database access | |
| 171 | 178 | $total_entries = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name}"); |
| 172 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache stats require direct database access | |
| 179 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache stats require direct database access | |
| 173 | 180 | $expired_entries = $wpdb->get_var( |
| 174 | 181 | $wpdb->prepare( |
| 175 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is properly constructed from controlled prefix | |
| 182 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix | |
| 176 | 183 | "SELECT COUNT(*) FROM {$table_name} WHERE expires_at < %d", |
| 177 | 184 | $current_time |
| 178 | 185 | ) |
| 179 | 186 | ); |
| 180 | 187 | |
| 181 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache stats require direct database access | |
| 188 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache stats require direct database access | |
| 182 | 189 | $cache_size = $wpdb->get_var( |
| 183 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is properly constructed from controlled prefix | |
| 190 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix | |
| 184 | 191 | "SELECT SUM(LENGTH(cache_data)) FROM {$table_name}" |
| 185 | 192 | ); |
| 186 | 193 | |
| 187 | 194 | return [ |
| @@ -231,12 +238,12 @@ | ||
| 231 | 238 | |
| 232 | 239 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 233 | 240 | $current_time = time(); |
| 234 | 241 | |
| 235 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache retrieval requires direct database access | |
| 242 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache retrieval requires direct database access | |
| 236 | 243 | $cached_row = $wpdb->get_row( |
| 237 | 244 | $wpdb->prepare( |
| 238 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is properly constructed from controlled prefix | |
| 245 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table name is properly constructed from controlled prefix | |
| 239 | 246 | "SELECT cache_data, expires_at FROM {$table_name} |
| 240 | 247 | WHERE cache_key = %s AND expires_at > %d", |
| 241 | 248 | $cache_key, |
| 242 | 249 | $current_time |
| @@ -264,9 +271,9 @@ | ||
| 264 | 271 | global $wpdb; |
| 265 | 272 | |
| 266 | 273 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 267 | 274 | |
| 268 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache storage requires direct database access | |
| 275 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache storage requires direct database access | |
| 269 | 276 | $result = $wpdb->replace( |
| 270 | 277 | $table_name, |
| 271 | 278 | [ |
| 272 | 279 | 'cache_key' => $cache_key, |
| @@ -290,9 +297,9 @@ | ||
| 290 | 297 | global $wpdb; |
| 291 | 298 | |
| 292 | 299 | $table_name = $wpdb->prefix . 'thinkrank_ai_cache'; |
| 293 | 300 | |
| 294 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache deletion requires direct database access | |
| 301 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Cache deletion requires direct database access | |
| 295 | 302 | $result = $wpdb->delete( |
| 296 | 303 | $table_name, |
| 297 | 304 | ['cache_key' => $cache_key], |
| 298 | 305 | ['%s'] |