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