PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmDb.php +76 -187 6.286.19 View file →
@@ -3,35 +3,11 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmDb {
7 -
8 - /**
9 - * The table name for Formidable Fields.
10 - *
11 - * @var string
12 - */
13 7 public $fields;
14 -
15 - /**
16 - * The table name for Formidable Forms.
17 - *
18 - * @var string
19 - */
20 8 public $forms;
21 -
22 - /**
23 - * The table name for Formidable Entries.
24 - *
25 - * @var string
26 - */
27 9 public $entries;
28 -
29 - /**
30 - * The table name for Formidable Entry Metas.
31 - *
32 - * @var string
33 - */
34 10 public $entry_metas;
35 11
36 12 public function __construct() {
37 13 if ( ! defined( 'ABSPATH' ) ) {
@@ -50,14 +26,13 @@
50 26 * Change array into format $wpdb->prepare can use
51 27 *
52 28 * @param array $args
53 29 * @param string $starts_with
54 - *
55 30 * @return void
56 31 */
57 32 public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
58 - if ( ! $args ) {
59 - // Add an arg to prevent prepare from failing
33 + if ( empty( $args ) ) {
34 + // add an arg to prevent prepare from failing
60 35 $args = array(
61 36 'where' => $starts_with . '1=%d',
62 37 'values' => array( 1 ),
63 38 );
@@ -80,14 +55,11 @@
80 55 * @param array $args
81 56 * @param string $base_where
82 57 * @param string $where
83 58 * @param array $values
84 - *
85 - * @return void
86 59 */
87 60 public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
88 61 $condition = ' AND';
89 -
90 62 if ( isset( $args['or'] ) ) {
91 63 $condition = ' OR';
92 64 unset( $args['or'] );
93 65 }
@@ -92,16 +64,13 @@
92 64 unset( $args['or'] );
93 65 }
94 66
95 67 foreach ( $args as $key => $value ) {
96 - $where .= $where ? $condition : $base_where;
97 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
98 - $array_inc_null = ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value );
99 -
68 + $where .= empty( $where ) ? $base_where : $condition;
69 + $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
100 70 if ( is_numeric( $key ) || $array_inc_null ) {
101 71 $where .= ' ( ';
102 72 $nested_where = '';
103 -
104 73 if ( $array_inc_null ) {
105 74 foreach ( $value as $val ) {
106 75 $parse_where = array(
107 76 $key => $val,
@@ -111,29 +80,27 @@
111 80 }
112 81 } else {
113 82 self::parse_where_from_array( $value, '', $nested_where, $values );
114 83 }
115 -
116 84 $where .= $nested_where;
117 85 $where .= ' ) ';
118 86 } else {
119 87 self::interpret_array_to_sql( $key, $value, $where, $values );
120 - }//end if
88 + }
121 89 }//end foreach
122 90 }
123 91
124 92 /**
125 - * @param string $key
126 - * @param array|string|null $value
127 - * @param string $where
128 - * @param array $values
129 - *
93 + * @param string $key
94 + * @param array|string $value
95 + * @param string $where
96 + * @param array $values
130 97 * @return void
131 98 */
132 99 private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
133 100 $key = trim( $key );
134 101
135 - if ( str_contains( $key, 'created_at' ) || str_contains( $key, 'updated_at' ) ) {
102 + if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
136 103 $k = explode( ' ', $key );
137 104 $where .= ' CAST(' . reset( $k ) . ' as CHAR) ' . str_replace( reset( $k ), '', $key );
138 105 } else {
139 106 $where .= ' ' . $key;
@@ -142,30 +109,27 @@
142 109 $lowercase_key = explode( ' ', strtolower( $key ) );
143 110 $lowercase_key = end( $lowercase_key );
144 111
145 112 if ( is_array( $value ) ) {
146 - // Translate array of values to "in"
147 - if ( str_contains( $lowercase_key, 'like' ) ) {
113 + // translate array of values to "in"
114 + if ( strpos( $lowercase_key, 'like' ) !== false ) {
148 115 $where = preg_replace( '/' . $key . '$/', '', $where );
149 116 $where .= '(';
150 117 $start = true;
151 -
152 118 foreach ( $value as $v ) {
153 119 if ( ! $start ) {
154 120 $where .= ' OR ';
155 121 }
156 -
157 122 $start = false;
158 123 $where .= $key . ' %s';
159 124 $values[] = '%' . self::esc_like( $v ) . '%';
160 125 }
161 -
162 126 $where .= ')';
163 - } elseif ( $value ) {
127 + } elseif ( ! empty( $value ) ) {
164 128 $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
165 129 $values = array_merge( $values, $value );
166 130 }
167 - } elseif ( str_contains( $lowercase_key, 'like' ) ) {
131 + } elseif ( strpos( $lowercase_key, 'like' ) !== false ) {
168 132 /**
169 133 * Allow string to start or end with the value
170 134 * If the key is like% then skip the first % for starts with
171 135 * If the key is %like then skip the last % for ends with
@@ -171,13 +135,12 @@
171 135 * If the key is %like then skip the last % for ends with
172 136 */
173 137 $start = '%';
174 138 $end = '%';
175 -
176 139 if ( $lowercase_key === 'like%' ) {
177 140 $start = '';
178 141 $where = rtrim( $where, '%' );
179 - } elseif ( $lowercase_key === '%like' ) {
142 + } elseif ( $lowercase_key == '%like' ) {
180 143 $end = '';
181 144 $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
182 145 $where .= 'like';
183 146 }
@@ -183,13 +146,14 @@
183 146 }
184 147
185 148 $where .= ' %s';
186 149 $values[] = $start . self::esc_like( $value ) . $end;
150 +
187 151 } elseif ( $value === null ) {
188 152 $where .= ' IS NULL';
189 153 } else {
190 154 // allow a - to prevent = from being added
191 - if ( str_ends_with( $key, '-' ) ) {
155 + if ( substr( $key, - 1 ) === '-' ) {
192 156 $where = rtrim( $where, '-' );
193 157 } else {
194 158 $where .= '=';
195 159 }
@@ -207,13 +171,11 @@
207 171 *
208 172 * @param string $key
209 173 * @param int|string $value
210 174 * @param string $where
211 - *
212 - * @return void
213 175 */
214 176 private static function add_query_placeholder( $key, $value, &$where ) {
215 - if ( is_numeric( $value ) && ( ! str_contains( $key, 'meta_value' ) || str_contains( $key, '+0' ) ) ) {
177 + if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
216 178 // Switch string to number.
217 179 $value = $value + 0;
218 180 $where .= is_float( $value ) ? '%f' : '%d';
219 181 } else {
@@ -229,8 +191,9 @@
229 191 * @return int
230 192 */
231 193 public static function get_count( $table, $where = array(), $args = array() ) {
232 194 $count = self::get_var( $table, $where, 'COUNT(*)', $args );
195 +
233 196 return (int) $count;
234 197 }
235 198
236 199 /**
@@ -246,17 +209,18 @@
246 209 public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
247 210 $group = '';
248 211 self::get_group_and_table_name( $table, $group );
249 212 self::convert_options_to_array( $args, '', $limit );
250 -
251 213 if ( $type === 'var' && ! isset( $args['limit'] ) ) {
252 214 $args['limit'] = 1;
253 215 }
254 216
255 - $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
217 + $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
218 +
256 219 $cache_key = self::generate_cache_key( $where, $args, $field, $type );
220 + $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
257 221
258 - return self::check_cache( $cache_key, $group, $query, 'get_' . $type );
222 + return $results;
259 223 }
260 224
261 225 /**
262 226 * Generate a cache key from the where query, field, type, and other arguments
@@ -272,16 +236,15 @@
272 236 */
273 237 public static function generate_cache_key( $where, $args, $field, $type ) {
274 238 $cache_key = '';
275 239 $where = FrmAppHelper::array_flatten( $where );
276 -
277 240 foreach ( $where as $key => $value ) {
278 241 $cache_key .= $key . '_' . $value;
279 242 }
280 -
281 243 $cache_key .= implode( '_', $args ) . $field . '_' . $type;
244 + $cache_key = str_replace( array( ' ', ',' ), '_', $cache_key );
282 245
283 - return str_replace( array( ' ', ',' ), '_', $cache_key );
246 + return $cache_key;
284 247 }
285 248
286 249 /**
287 250 * @param string $table
@@ -289,9 +252,9 @@
289 252 * @param string $field
290 253 * @param array $args
291 254 * @param string $limit
292 255 *
293 - * @return array
256 + * @return mixed
294 257 */
295 258 public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
296 259 return self::get_var( $table, $where, $field, $args, $limit, 'col' );
297 260 }
@@ -307,8 +270,9 @@
307 270 * @return mixed
308 271 */
309 272 public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
310 273 $args['limit'] = 1;
274 +
311 275 return self::get_var( $table, $where, $fields, $args, '', 'row' );
312 276 }
313 277
314 278 /**
@@ -320,9 +284,9 @@
320 284 * @param array $where
321 285 * @param string $fields
322 286 * @param array $args
323 287 *
324 - * @return array
288 + * @return mixed
325 289 */
326 290 public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
327 291 return self::get_var( $table, $where, $fields, $args, '', 'results' );
328 292 }
@@ -349,9 +313,8 @@
349 313 '%like' => '%like',
350 314 );
351 315
352 316 $where_is = strtolower( $where_is );
353 -
354 317 if ( isset( $switch_to[ $where_is ] ) ) {
355 318 return ' ' . $switch_to[ $where_is ];
356 319 }
357 320
@@ -370,26 +333,24 @@
370 333 * Also add the wpdb->prefix to the table if it's missing
371 334 *
372 335 * @param string $table
373 336 * @param string $group
374 - *
375 - * @return void
376 337 */
377 338 private static function get_group_and_table_name( &$table, &$group ) {
378 - global $wpdb;
339 + global $wpdb, $wpmuBaseTablePrefix;
379 340
380 341 $table_parts = explode( ' ', $table );
381 342 $group = reset( $table_parts );
382 343 self::maybe_remove_prefix( $wpdb->prefix, $group );
383 344
384 - $prefix = $wpdb->base_prefix;
345 + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
385 346 self::maybe_remove_prefix( $prefix, $group );
386 347
387 - if ( $group === $table ) {
348 + if ( $group == $table ) {
388 349 $table = $wpdb->prefix . $table;
389 350 }
390 351
391 - // Switch to singular group name
352 + // switch to singular group name
392 353 $group = rtrim( $group, 's' );
393 354 }
394 355
395 356 /**
@@ -395,44 +356,30 @@
395 356 /**
396 357 * Only remove the db prefix when at the beginning.
397 358 *
398 359 * @since 4.04.02
399 - *
400 - * @param string $prefix Prefix to remove.
401 - * @param string $name Name to strip prefix from, passed by reference.
402 - *
403 - * @return void
404 360 */
405 361 private static function maybe_remove_prefix( $prefix, &$name ) {
406 - if ( str_starts_with( $name, $prefix ) ) {
362 + if ( substr( $name, 0, strlen( $prefix ) ) === $prefix ) {
407 363 $name = substr( $name, strlen( $prefix ) );
408 364 }
409 365 }
410 366
411 - /**
412 - * @param array|string $args
413 - * @param string $order_by
414 - * @param int|string $limit
415 - *
416 - * @return void
417 - */
418 367 private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
419 368 if ( ! is_array( $args ) ) {
420 369 $args = array( 'order_by' => $args );
421 370 }
422 371
423 - if ( $order_by ) {
372 + if ( ! empty( $order_by ) ) {
424 373 $args['order_by'] = $order_by;
425 374 }
426 375
427 - if ( $limit ) {
376 + if ( ! empty( $limit ) ) {
428 377 $args['limit'] = $limit;
429 378 }
430 379
431 380 $temp_args = $args;
432 -
433 381 foreach ( $temp_args as $k => $v ) {
434 - // phpcs:ignore Universal.Operators.StrictComparisons
435 382 if ( $v == '' ) {
436 383 unset( $args[ $k ] );
437 384 continue;
438 385 }
@@ -437,22 +384,19 @@
437 384 continue;
438 385 }
439 386
440 387 $db_name = strtoupper( str_replace( '_', ' ', $k ) );
441 -
442 - if ( ! str_contains( $v, $db_name ) ) {
388 + if ( strpos( $v, $db_name ) === false ) {
443 389 $args[ $k ] = $db_name . ' ' . $v;
444 390 }
445 391 }
446 392
447 393 // Make sure LIMIT is the last argument
448 - if ( ! isset( $args['order_by'] ) || ! isset( $args['limit'] ) ) {
449 - return;
394 + if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
395 + $temp_limit = $args['limit'];
396 + unset( $args['limit'] );
397 + $args['limit'] = $temp_limit;
450 398 }
451 -
452 - $temp_limit = $args['limit'];
453 - unset( $args['limit'] );
454 - $args['limit'] = $temp_limit;
455 399 }
456 400
457 401 /**
458 402 * Get the associative array results for the given columns, table, and where query
@@ -468,12 +412,14 @@
468 412 public static function get_associative_array_results( $columns, $table, $where ) {
469 413 $group = '';
470 414 self::get_group_and_table_name( $table, $group );
471 415
472 - $query = self::generate_query_string_from_pieces( $columns, $table, $where );
416 + $query = self::generate_query_string_from_pieces( $columns, $table, $where );
417 +
473 418 $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
419 + $results = self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
474 420
475 - return self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
421 + return $results;
476 422 }
477 423
478 424 /**
479 425 * Combine the pieces of a query to form a full, prepared query
@@ -491,25 +437,19 @@
491 437 $query = 'SELECT ' . $columns . ' FROM ' . $table;
492 438
493 439 self::esc_query_args( $args );
494 440
495 - if ( ! is_array( $where ) && $where ) {
496 - return $query;
441 + if ( is_array( $where ) || empty( $where ) ) {
442 + self::get_where_clause_and_values( $where );
443 + global $wpdb;
444 + $query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
497 445 }
498 446
499 - self::get_where_clause_and_values( $where );
500 - global $wpdb;
501 -
502 - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
503 - return $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
447 + return $query;
504 448 }
505 449
506 450 /**
507 451 * @since 2.05.07
508 - *
509 - * @param array $args Query arguments, passed by reference.
510 - *
511 - * @return void
512 452 */
513 453 private static function esc_query_args( &$args ) {
514 454 foreach ( $args as $param => $value ) {
515 455 if ( $param === 'order_by' ) {
@@ -517,9 +457,8 @@
517 457 } elseif ( $param === 'limit' ) {
518 458 $args[ $param ] = self::esc_limit( $value );
519 459 }
520 460
521 - // phpcs:ignore Universal.Operators.StrictComparisons
522 461 if ( $args[ $param ] == '' ) {
523 462 unset( $args[ $param ] );
524 463 }
525 464 }
@@ -535,8 +474,9 @@
535 474 * @return string The escaped value
536 475 */
537 476 public static function esc_like( $term ) {
538 477 global $wpdb;
478 +
539 479 return $wpdb->esc_like( $term );
540 480 }
541 481
542 482 /**
@@ -542,33 +482,29 @@
542 482 /**
543 483 * @since 2.05.06
544 484 *
545 485 * @param string $order_query
546 - *
547 - * @return string
548 486 */
549 487 public static function esc_order( $order_query ) {
550 - if ( ! $order_query ) {
488 + if ( empty( $order_query ) ) {
551 489 return '';
552 490 }
553 491
554 492 // Remove ORDER BY before sanitizing.
555 493 $order_query = strtolower( $order_query );
556 -
557 - if ( str_contains( $order_query, 'order by' ) ) {
494 + if ( strpos( $order_query, 'order by' ) !== false ) {
558 495 $order_query = str_replace( 'order by', '', $order_query );
559 496 }
560 497
561 498 $order_query = explode( ' ', trim( $order_query ) );
562 - $order = trim( reset( $order_query ) );
563 - $safe_order = array( 'count(*)' );
564 499
565 - if ( ! in_array( strtolower( $order ), $safe_order, true ) ) {
500 + $order = trim( reset( $order_query ) );
501 + $safe_order = array( 'count(*)' );
502 + if ( ! in_array( strtolower( $order ), $safe_order ) ) {
566 503 $order = preg_replace( '/[^a-zA-Z0-9\-\_\.\+]/', '', $order );
567 504 }
568 505
569 506 $order_by = '';
570 -
571 507 if ( count( $order_query ) > 1 ) {
572 508 $order_by = end( $order_query );
573 509 self::esc_order_by( $order_by );
574 510 }
@@ -579,16 +515,11 @@
579 515 /**
580 516 * Make sure this is ordering by either ASC or DESC
581 517 *
582 518 * @since 2.05.06
583 - *
584 - * @param string $order_by Sort direction, passed by reference.
585 - *
586 - * @return void
587 519 */
588 520 public static function esc_order_by( &$order_by ) {
589 521 $sort_options = array( 'asc', 'desc' );
590 -
591 522 if ( ! in_array( strtolower( $order_by ), $sort_options, true ) ) {
592 523 $order_by = 'asc';
593 524 }
594 525 }
@@ -594,26 +525,21 @@
594 525 }
595 526
596 527 /**
597 528 * @since 2.05.06
598 - *
599 529 * @param string $limit
600 - *
601 - * @return string
602 530 */
603 531 public static function esc_limit( $limit ) {
604 - if ( ! $limit ) {
532 + if ( empty( $limit ) ) {
605 533 return '';
606 534 }
607 535
608 536 $limit = trim( str_replace( 'limit ', '', strtolower( $limit ) ) );
609 -
610 537 if ( is_numeric( $limit ) ) {
611 538 return ' LIMIT ' . $limit;
612 539 }
613 540
614 541 $limit = explode( ',', trim( $limit ) );
615 -
616 542 foreach ( $limit as $k => $l ) {
617 543 if ( is_numeric( $l ) ) {
618 544 $limit[ $k ] = $l;
619 545 }
@@ -627,16 +553,12 @@
627 553 /**
628 554 * Get an array of values ready to go through $wpdb->prepare
629 555 *
630 556 * @since 2.05.06
631 - *
632 - * @param array $array Array of values.
633 - * @param string $type Placeholder type.
634 - *
635 - * @return string
636 557 */
637 558 public static function prepare_array_values( $array, $type = '%s' ) {
638 559 $placeholders = array_fill( 0, count( $array ), $type );
560 +
639 561 return implode( ', ', $placeholders );
640 562 }
641 563
642 564 /**
@@ -643,18 +565,17 @@
643 565 * @since 2.05.06
644 566 *
645 567 * @param string $starts_with
646 568 * @param array|string $where
647 - *
648 569 * @return string
649 570 */
650 571 public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
651 - if ( ! $where ) {
572 + if ( empty( $where ) ) {
652 573 $where = '';
653 574 } elseif ( is_array( $where ) ) {
654 - global $wpdb;
655 - self::get_where_clause_and_values( $where, $starts_with );
656 - $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
575 + global $wpdb;
576 + self::get_where_clause_and_values( $where, $starts_with );
577 + $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
657 578 } else {
658 579 $where = $starts_with . $where;
659 580 }
660 581
@@ -672,12 +593,10 @@
672 593 /**
673 594 * Prepare and save settings in styles and actions
674 595 *
675 596 * @since 2.05.06
676 - *
677 - * @param array|object $settings
678 - * @param string $group
679 - *
597 + * @param array $settings
598 + * @param string $group
680 599 * @return int|WP_Error
681 600 */
682 601 public static function save_settings( $settings, $group ) {
683 602 $settings = (array) $settings;
@@ -686,9 +605,9 @@
686 605 if ( empty( $settings['ID'] ) ) {
687 606 unset( $settings['ID'] );
688 607 }
689 608
690 - // Delete all caches for this group
609 + // delete all caches for this group
691 610 self::cache_delete_group( $group );
692 611
693 612 return self::save_json_post( $settings );
694 613 }
@@ -702,14 +621,12 @@
702 621 *
703 622 * @since 2.05.06
704 623 *
705 624 * @param array $settings
706 - *
707 625 * @return int|WP_Error
708 626 */
709 627 public static function save_json_post( $settings ) {
710 628 global $wp_filter;
711 -
712 629 if ( isset( $wp_filter['content_save_pre'] ) ) {
713 630 $filters = $wp_filter['content_save_pre'];
714 631 }
715 632
@@ -717,9 +634,9 @@
717 634 remove_all_filters( 'content_save_pre' );
718 635
719 636 $post = wp_insert_post( $settings );
720 637
721 - // Add the content filters back for views or posts
638 + // add the content filters back for views or posts
722 639 if ( isset( $filters ) ) {
723 640 $wp_filter['content_save_pre'] = $filters;
724 641 }
725 642
@@ -734,23 +651,20 @@
734 651 * @param string $cache_key The unique name for this cache.
735 652 * @param string $group The name of the cache group.
736 653 * @param string $query If blank, don't run a db call.
737 654 * @param string $type The wpdb function to use with this query.
738 - * @param int $time Cache expiration time in seconds.
739 655 *
740 656 * @return mixed $results The cache or query results
741 657 */
742 658 public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
743 - $found = null;
744 - $results = wp_cache_get( $cache_key, $group, false, $found );
745 -
746 - if ( ( $found === true && $results !== false ) || ! $query ) {
659 + $results = wp_cache_get( $cache_key, $group );
660 + if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
747 661 return $results;
748 662 }
749 663
750 - if ( 'get_posts' === $type ) {
664 + if ( 'get_posts' == $type ) {
751 665 $results = get_posts( $query );
752 - } elseif ( 'get_associative_results' === $type ) {
666 + } elseif ( 'get_associative_results' == $type ) {
753 667 global $wpdb;
754 668 $results = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
755 669 } else {
756 670 global $wpdb;
@@ -763,15 +677,8 @@
763 677 }
764 678
765 679 /**
766 680 * @since 2.05.06
767 - *
768 - * @param string $cache_key The unique name for this cache.
769 - * @param mixed $results Cached results.
770 - * @param string $group The name of the cache group.
771 - * @param int $time Cache expiration time in seconds.
772 - *
773 - * @return void
774 681 */
775 682 public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
776 683 if ( ! FrmAppHelper::prevent_caching() ) {
777 684 self::add_key_to_group_cache( $cache_key, $group );
@@ -783,13 +690,8 @@
783 690 * Keep track of the keys cached in each group so they can be deleted
784 691 * in Redis and Memcache
785 692 *
786 693 * @since 2.05.06
787 - *
788 - * @param string $key Cache key.
789 - * @param string $group Cache group name.
790 - *
791 - * @return void
792 694 */
793 695 public static function add_key_to_group_cache( $key, $group ) {
794 696 $cached = self::get_group_cached_keys( $group );
795 697 $cached[ $key ] = $key;
@@ -797,18 +699,13 @@
797 699 }
798 700
799 701 /**
800 702 * @since 2.05.06
801 - *
802 - * @param string $group Cache group name.
803 - *
804 - * @return array
805 703 */
806 704 public static function get_group_cached_keys( $group ) {
807 705 $cached = wp_cache_get( 'cached_keys', $group );
808 -
809 706 if ( ! $cached || ! is_array( $cached ) ) {
810 - return array();
707 + $cached = array();
811 708 }
812 709
813 710 return $cached;
814 711 }
@@ -815,12 +712,9 @@
815 712
816 713 /**
817 714 * @since 2.05.06
818 715 *
819 - * @param string $cache_key Cache key to delete.
820 - * @param string $group Cache group name.
821 - *
822 - * @return void
716 + * @param string $cache_key
823 717 */
824 718 public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
825 719 delete_transient( $cache_key );
826 720 wp_cache_delete( $cache_key, $group );
@@ -831,23 +725,19 @@
831 725 *
832 726 * @since 2.05.06
833 727 *
834 728 * @param string $group The name of the cache group.
835 - *
836 - * @return void
837 729 */
838 730 public static function cache_delete_group( $group ) {
839 731 $cached_keys = self::get_group_cached_keys( $group );
840 732
841 - if ( ! $cached_keys ) {
842 - return;
843 - }
733 + if ( ! empty( $cached_keys ) ) {
734 + foreach ( $cached_keys as $key ) {
735 + wp_cache_delete( $key, $group );
736 + }
844 737
845 - foreach ( $cached_keys as $key ) {
846 - wp_cache_delete( $key, $group );
738 + wp_cache_delete( 'cached_keys', $group );
847 739 }
848 -
849 - wp_cache_delete( 'cached_keys', $group );
850 740 }
851 741
852 742 /**
853 743 * Checks if a DB column exists.
@@ -855,9 +745,8 @@
855 745 * @since 6.7
856 746 *
857 747 * @param string $table Table name without `$wpdb->prefix`.
858 748 * @param string $column Column name.
859 - *
860 749 * @return bool
861 750 */
862 751 public static function db_column_exists( $table, $column ) {
863 752 global $wpdb;