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