PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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/FrmForm.php +86 -289 6.255.3 View file →
@@ -6,9 +6,9 @@
6 6 class FrmForm {
7 7
8 8 /**
9 9 * @param array $values
10 - * @return bool|int id on success or false on failure.
10 + * @return int|boolean id on success or false on failure
11 11 */
12 12 public static function create( $values ) {
13 13 global $wpdb;
14 14
@@ -17,33 +17,24 @@
17 17 $new_values = array(
18 18 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
19 19 'name' => $values['name'],
20 20 'description' => $values['description'],
21 - 'status' => $values['status'] ?? 'published',
22 - 'logged_in' => $values['logged_in'] ?? 0,
21 + 'status' => isset( $values['status'] ) ? $values['status'] : 'published',
22 + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
23 23 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
24 24 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
25 25 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
26 - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ),
26 + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
27 27 );
28 28
29 29 $options = isset( $values['options'] ) ? (array) $values['options'] : array();
30 30 FrmFormsHelper::fill_form_options( $options, $values );
31 31
32 - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' );
33 - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' );
34 - $options['submit_html'] = $values['options']['submit_html'] ?? FrmFormsHelper::get_default_html( 'submit' );
32 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
33 + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
34 + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
35 35
36 - /**
37 - * Allows modifying form options before updating or creating.
38 - *
39 - * @since 5.4 Add the third param.
40 - *
41 - * @param array $options Form options.
42 - * @param array $values Form data.
43 - * @param bool $update Is form updating or creating. It's `true` if is updating.
44 - */
45 - $options = apply_filters( 'frm_form_options_before_update', $options, $values, false );
36 + $options = apply_filters( 'frm_form_options_before_update', $options, $values );
46 37 $options = self::maybe_filter_form_options( $options );
47 38 $new_values['options'] = serialize( $options );
48 39
49 40 $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -69,9 +60,9 @@
69 60 return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) );
70 61 }
71 62
72 63 /**
73 - * @return bool|int ID on success or false on failure
64 + * @return int|boolean ID on success or false on failure
74 65 */
75 66 public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
76 67 global $wpdb;
77 68
@@ -93,10 +84,10 @@
93 84 'is_template' => $template ? 1 : 0,
94 85 );
95 86
96 87 if ( $blog_id ) {
97 - $new_values['status'] = 'published';
98 - $new_options = $values->options;
88 + $new_values['status'] = 'published';
89 + $new_options = $values->options;
99 90 FrmAppHelper::unserialize_or_decode( $new_options );
100 91 $new_options['email_to'] = get_option( 'admin_email' );
101 92 $new_options['copy'] = false;
102 93 $new_values['options'] = $new_options;
@@ -126,9 +117,9 @@
126 117 return false;
127 118 }
128 119
129 120 public static function after_duplicate( $form_id, $values ) {
130 - $new_opts = $values['options'];
121 + $new_opts = $values['options'];
131 122 FrmAppHelper::unserialize_or_decode( $new_opts );
132 123 $values['options'] = $new_opts;
133 124
134 125 if ( isset( $new_opts['success_msg'] ) ) {
@@ -158,9 +149,9 @@
158 149 // Keys of fields that you want to check to replace field ID.
159 150 $keys = array( 'default_value', 'field_options' );
160 151 $sql_cols = 'fi.id';
161 152 foreach ( $keys as $key ) {
162 - $sql_cols .= ',fi.' . $key;
153 + $sql_cols .= ( ',fi.' . $key );
163 154 }
164 155
165 156 $fields = FrmDb::get_results(
166 157 "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id",
@@ -198,21 +189,13 @@
198 189 if ( ! is_string( $value ) && ! is_array( $value ) ) {
199 190 continue;
200 191 }
201 192
202 - if ( 'field_options' === $key ) {
203 - // Need to loop through field_options to prevent breaking serialized string when length changed.
204 - FrmAppHelper::unserialize_or_decode( $value );
205 - $new_val = FrmFieldsHelper::switch_field_ids( $value );
206 - $new_val = serialize( $new_val );
207 - } else {
208 - $new_val = FrmFieldsHelper::switch_field_ids( $value );
209 - }
210 -
193 + $new_val = FrmFieldsHelper::switch_field_ids( $value );
211 194 if ( $new_val !== $value ) {
212 195 $new_values[ $key ] = $new_val;
213 196 }
214 - }//end foreach
197 + }
215 198
216 199 if ( ! empty( $new_values ) ) {
217 200 FrmField::update( $field['id'], $new_values );
218 201 }
@@ -218,9 +201,9 @@
218 201 }
219 202 }
220 203
221 204 /**
222 - * @return bool|int
205 + * @return int|boolean
223 206 */
224 207 public static function update( $id, $values, $create_link = false ) {
225 208 global $wpdb;
226 209
@@ -243,9 +226,9 @@
243 226 $new_values[ $value_key ] = $value;
244 227 }
245 228 }
246 229
247 - if ( ! empty( $values['new_status'] ) ) {
230 + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
248 231 $new_values['status'] = $values['new_status'];
249 232 }
250 233
251 234 if ( ! empty( $new_values ) ) {
@@ -276,26 +259,22 @@
276 259 if ( ! isset( $values['options'] ) ) {
277 260 return $new_values;
278 261 }
279 262
280 - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array();
263 + $options = isset( $values['options'] ) ? (array) $values['options'] : array();
281 264 FrmFormsHelper::fill_form_options( $options, $values );
282 265
283 - $options['custom_style'] = $values['options']['custom_style'] ?? 0;
284 - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' );
285 - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' );
286 - $options['submit_html'] = isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
266 + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
267 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
268 + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
269 + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
287 270
288 - /**
289 - * Allows modifying form options before updating or creating.
290 - *
291 - * @since 5.4 Added the third param.
292 - *
293 - * @param array $options Form options.
294 - * @param array $values Form data.
295 - * @param bool $update Is form updating or creating. It's `true` if is updating.
296 - */
297 - $options = apply_filters( 'frm_form_options_before_update', $options, $values, true );
271 + if ( ! empty( $options['success_url'] ) && ! empty( $args['form_id'] ) ) {
272 + $options['success_url'] = FrmFormsHelper::maybe_add_sanitize_url_attr( $options['success_url'], (int) $args['form_id'] );
273 + $values['options']['success_url'] = $options['success_url'];
274 + }
275 +
276 + $options = apply_filters( 'frm_form_options_before_update', $options, $values );
298 277 $options = self::maybe_filter_form_options( $options );
299 278 $new_values['options'] = serialize( $options );
300 279
301 280 return $new_values;
@@ -348,20 +327,15 @@
348 327 continue;
349 328 }
350 329 }
351 330
352 - // Updating the form.
331 + //updating the form
353 332 $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field );
354 - // Don't check for POST html.
355 - unset( $update_options['custom_html'] );
333 + unset( $update_options['custom_html'] ); // don't check for POST html
356 334 $update_options = apply_filters( 'frm_field_options_to_update', $update_options );
357 335
358 - if ( ! is_array( $field->field_options ) ) {
359 - $field->field_options = array();
360 - }
361 -
362 336 foreach ( $update_options as $opt => $default ) {
363 - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default;
337 + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
364 338 self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
365 339 }
366 340
367 341 $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
@@ -370,87 +344,28 @@
370 344 'field_options' => $field->field_options,
371 345 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '',
372 346 );
373 347
374 - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) {
375 - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) {
376 - if ( is_array( $option ) ) {
377 - foreach ( $option as $key => $item ) {
378 - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' );
379 - }
380 - }
381 - }
382 - }
383 -
384 348 self::prepare_field_update_values( $field, $values, $new_field );
385 - self::maybe_update_max_option( $field, $values, $new_field );
386 349
387 350 FrmField::update( $field_id, $new_field );
388 351
389 352 FrmField::delete_form_transient( $field->form_id );
390 - }//end foreach
353 + }
391 354 self::clear_form_cache();
392 355
393 356 return $values;
394 357 }
395 358
396 - /**
397 - * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc.
398 - *
399 - * @since 6.7
400 - *
401 - * @param array $field
402 - * @param array $values
403 - * @param array $new_field
404 - * @return void
405 - */
406 - private static function maybe_update_max_option( $field, $values, &$new_field ) {
407 - if ( $field->type === 'textarea' &&
408 - ! empty( $values['field_options'][ 'type_' . $field->id ] ) &&
409 - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) {
410 -
411 - $new_field['field_options']['max'] = '';
412 -
413 - /**
414 - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads.
415 - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting.
416 - */
417 - $_POST['field_options'][ 'max_' . $field->id ] = '';
418 - }
419 - }
420 -
421 - /**
422 - * @param string $opt
423 - * @param mixed $value
424 - * @return void
425 - */
426 359 private static function sanitize_field_opt( $opt, &$value ) {
427 - if ( ! is_string( $value ) ) {
428 - return;
360 + if ( is_string( $value ) ) {
361 + if ( $opt === 'calc' ) {
362 + $value = self::sanitize_calc( $value );
363 + } else {
364 + $value = FrmAppHelper::kses( $value, 'all' );
365 + }
366 + $value = trim( $value );
429 367 }
430 -
431 - /**
432 - * Allow the option to turn off sanitization for a field. This way a custom rule can be used instead.
433 - * Make sure to add custom sanitization using the frm_update_field_options filter as the data will no longer be sanitized.
434 - *
435 - * @since 6.0
436 - *
437 - * @param bool $should_sanitize
438 - * @param string $opt
439 - */
440 - $should_sanitize = apply_filters( 'frm_should_sanitize_field_opt_string', true, $opt );
441 -
442 - if ( ! $should_sanitize ) {
443 - return;
444 - }
445 -
446 - if ( $opt === 'calc' ) {
447 - $value = self::sanitize_calc( $value );
448 - } else {
449 - $value = FrmAppHelper::kses( $value, 'all' );
450 - }
451 -
452 - $value = trim( $value );
453 368 }
454 369
455 370 /**
456 371 * @param string $value
@@ -459,10 +374,9 @@
459 374 private static function sanitize_calc( $value ) {
460 375 if ( false !== strpos( $value, '<' ) ) {
461 376 $value = self::normalize_calc_spaces( $value );
462 377 }
463 - // Allow <= and >=.
464 - $allow = array( '<= ', ' >=' );
378 + $allow = array( '<= ', ' >=' ); // Allow <= and >=
465 379 $temp = array( '< = ', ' > =' );
466 380 $value = str_replace( $allow, $temp, $value );
467 381 $value = strip_tags( $value );
468 382 $value = str_replace( $temp, $allow, $value );
@@ -477,16 +391,14 @@
477 391 * @return string
478 392 */
479 393 private static function normalize_calc_spaces( $calc ) {
480 394 // Check for a pattern with 5 parts
481 - // $1 \d|\] the first comparison digit or the end of a comparison shortcode.
395 + // $1 \d the first comparison digit.
482 396 // $2 a space (optional).
483 397 // $3 an equals sign (optional) that follows the < operator for <= comparisons.
484 398 // $4 another space (optional).
485 - // $5 \d|\[ the second comparison digit or the start of a comparison shortcode.
486 - $calc = preg_replace( '/(\d|\])( ){0,1}<(=){0,1}( ){0,1}(\d|\[)/', '$1 <$3 $5', $calc );
487 -
488 - return $calc;
399 + // $5 \d the second comparison digit.
400 + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc );
489 401 }
490 402
491 403 /**
492 404 * Updating the settings page
@@ -493,12 +405,12 @@
493 405 */
494 406 private static function get_settings_page_html( $values, &$field ) {
495 407 if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
496 408 $prev_opts = array();
497 - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type );
409 + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
498 410
499 - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html;
500 - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
411 + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
412 + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
501 413 $prev_opts = $field->field_options;
502 414 }
503 415
504 416 if ( isset( $prev_opts ) ) {
@@ -519,14 +431,11 @@
519 431 'options' => '',
520 432 'name' => '',
521 433 );
522 434 foreach ( $field_cols as $col => $default ) {
523 - $default = $default === '' ? $field->{$col} : $default;
524 - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default;
525 - }
435 + $default = ( $default === '' ) ? $field->{$col} : $default;
526 436
527 - if ( $field->type === 'submit' && isset( $new_field['field_order'] ) && (int) $new_field['field_order'] === FrmSubmitHelper::DEFAULT_ORDER ) {
528 - $new_field['field_order'] = $field->field_order;
437 + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
529 438 }
530 439
531 440 // Don't save the template option.
532 441 if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
@@ -538,9 +447,9 @@
538 447 * Get a list of all form settings that should be translated
539 448 * on a multilingual site.
540 449 *
541 450 * @since 3.06.01
542 - * @param object $form The form object.
451 + * @param object $form - The form object
543 452 */
544 453 public static function translatable_strings( $form ) {
545 454 $strings = array(
546 455 'name',
@@ -547,12 +456,8 @@
547 456 'description',
548 457 'submit_value',
549 458 'submit_msg',
550 459 'success_msg',
551 - 'invalid_msg',
552 - 'failed_msg',
553 - 'login_msg',
554 - 'admin_permission',
555 460 );
556 461
557 462 return apply_filters( 'frm_form_strings', $strings, $form );
558 463 }
@@ -557,12 +462,11 @@
557 462 return apply_filters( 'frm_form_strings', $strings, $form );
558 463 }
559 464
560 465 /**
561 - * @param int $id
562 466 * @param string $status
563 467 *
564 - * @return bool|int
468 + * @return int|boolean
565 469 */
566 470 public static function set_status( $id, $status ) {
567 471 if ( 'trash' == $status ) {
568 472 return self::trash( $id );
@@ -568,9 +472,9 @@
568 472 return self::trash( $id );
569 473 }
570 474
571 475 $statuses = array( 'published', 'draft', 'trash' );
572 - if ( ! in_array( $status, $statuses, true ) ) {
476 + if ( ! in_array( $status, $statuses ) ) {
573 477 return false;
574 478 }
575 479
576 480 global $wpdb;
@@ -597,9 +501,9 @@
597 501 return $query_results;
598 502 }
599 503
600 504 /**
601 - * @return bool|int
505 + * @return int|boolean
602 506 */
603 507 public static function trash( $id ) {
604 508 if ( ! EMPTY_TRASH_DAYS ) {
605 509 return self::destroy( $id );
@@ -609,12 +513,8 @@
609 513 if ( ! $form ) {
610 514 return false;
611 515 }
612 516
613 - if ( $form->status === 'trash' ) {
614 - return false;
615 - }
616 -
617 517 $options = $form->options;
618 518 $options['trash_time'] = time();
619 519
620 520 global $wpdb;
@@ -647,9 +547,9 @@
647 547 return $query_results;
648 548 }
649 549
650 550 /**
651 - * @return bool|int
551 + * @return int|boolean
652 552 */
653 553 public static function destroy( $id ) {
654 554 global $wpdb;
655 555
@@ -671,11 +571,8 @@
671 571
672 572 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
673 573 if ( $query_results ) {
674 574 // Delete all form actions linked to this form
675 - /**
676 - * @var FrmFormAction
677 - */
678 575 $action_control = FrmFormActionsController::get_form_actions( 'email' );
679 576 $action_control->destroy( $id, 'all' );
680 577
681 578 // Clear form caching
@@ -695,9 +592,9 @@
695 592 */
696 593 public static function scheduled_delete( $delete_timestamp = '' ) {
697 594 global $wpdb;
698 595
699 - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
596 + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
700 597
701 598 if ( ! $trash_forms ) {
702 599 return 0;
703 600 }
@@ -710,11 +607,9 @@
710 607 foreach ( $trash_forms as $form ) {
711 608 FrmAppHelper::unserialize_or_decode( $form->options );
712 609 if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
713 610 self::destroy( $form->id );
714 - if ( empty( $form->parent_form_id ) ) {
715 - ++$count;
716 - }
611 + $count ++;
717 612 }
718 613
719 614 unset( $form );
720 615 }
@@ -734,12 +629,10 @@
734 629 }
735 630
736 631 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
737 632 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
633 + $r = stripslashes( $r );
738 634
739 - // An empty form name can result in a null value.
740 - $r = is_null( $r ) ? '' : stripslashes( $r );
741 -
742 635 return $r;
743 636 }
744 637
745 638 /**
@@ -774,10 +667,11 @@
774 667
775 668 /**
776 669 * If $form is numeric, get the form object
777 670 *
671 + * @param object|int $form
672 + *
778 673 * @since 2.0.9
779 - * @param int|object $form
780 674 */
781 675 public static function maybe_get_form( &$form ) {
782 676 if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
783 677 $form = self::getOne( $form );
@@ -784,11 +678,9 @@
784 678 }
785 679 }
786 680
787 681 /**
788 - * @param int|string $id
789 - * @param false|int $blog_id
790 - * @return stdClass|null
682 + * @return object form
791 683 */
792 684 public static function getOne( $id, $blog_id = false ) {
793 685 global $wpdb;
794 686
@@ -803,9 +695,10 @@
803 695 if ( $cache ) {
804 696 if ( isset( $cache->options ) ) {
805 697 FrmAppHelper::unserialize_or_decode( $cache->options );
806 698 }
807 - return self::prepare_form_row_data( $cache );
699 +
700 + return wp_unslash( $cache );
808 701 }
809 702 }
810 703
811 704 if ( is_numeric( $id ) ) {
@@ -820,43 +713,17 @@
820 713 FrmDb::set_cache( $results->id, $results, 'frm_form' );
821 714 FrmAppHelper::unserialize_or_decode( $results->options );
822 715 }
823 716
824 - return self::prepare_form_row_data( $results );
717 + return apply_filters( 'frm_form_object', wp_unslash( $results ) );
825 718 }
826 719
827 720 /**
828 - * Make sure that if $row is an object, that $row->options is an array and not a string.
829 - *
830 - * @since 6.8.3
831 - *
832 - * @param stdClass|null $row The database row for a target form.
833 - * @return stdClass|null
721 + * @return object|array of objects
834 722 */
835 - private static function prepare_form_row_data( $row ) {
836 - $row = wp_unslash( $row );
837 - if ( ! is_object( $row ) ) {
838 - return $row;
839 - }
840 -
841 - if ( ! is_array( $row->options ) ) {
842 - $row->options = FrmFormsHelper::get_default_opts();
843 - }
844 -
845 - /**
846 - * @since 4.03.02
847 - *
848 - * @param stdClass $row
849 - */
850 - return apply_filters( 'frm_form_object', $row );
851 - }
852 -
853 - /**
854 - * @return array|object of objects
855 - */
856 723 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
857 724 if ( is_array( $where ) && ! empty( $where ) ) {
858 - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
725 + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
859 726 // don't get trashed templates
860 727 $where['status'] = array( null, '', 'published' );
861 728 }
862 729
@@ -863,9 +730,9 @@
863 730 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
864 731 } else {
865 732 global $wpdb;
866 733
867 - // The query has already been prepared if this is not an array.
734 + // the query has already been prepared if this is not an array
868 735 $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
869 736 $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
870 737 }
871 738
@@ -875,9 +742,9 @@
875 742 FrmAppHelper::unserialize_or_decode( $result->options );
876 743 }
877 744 }
878 745
879 - if ( $limit === ' LIMIT 1' || $limit == 1 ) {
746 + if ( $limit == ' LIMIT 1' || $limit == 1 ) {
880 747 // return the first form object if we are only getting one form
881 748 $results = reset( $results );
882 749 }
883 750
@@ -887,18 +754,14 @@
887 754 /**
888 755 * Get all published forms
889 756 *
890 757 * @since 2.0
891 - *
892 - * @param array $query
893 - * @param int $limit
894 - * @param string $inc_children
895 - * @return array|object of forms A single form object would be passed if $limit was set to 1.
758 + * @return array of forms
896 759 */
897 760 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
898 761 $query['is_template'] = 0;
899 762 $query['status'] = array( null, '', 'published' );
900 - if ( $inc_children === 'exclude' ) {
763 + if ( $inc_children == 'exclude' ) {
901 764 $query['parent_form_id'] = array( null, 0 );
902 765 }
903 766
904 767 $forms = self::getAll( $query, 'name', $limit );
@@ -934,18 +797,18 @@
934 797
935 798 foreach ( $results as $row ) {
936 799 if ( 'trash' != $row->status ) {
937 800 if ( $row->is_template ) {
938 - ++$counts['template'];
801 + $counts['template'] ++;
939 802 } else {
940 - ++$counts['published'];
803 + $counts['published'] ++;
941 804 }
942 805 } else {
943 - ++$counts['trash'];
806 + $counts['trash'] ++;
944 807 }
945 808
946 809 if ( 'draft' == $row->status ) {
947 - ++$counts['draft'];
810 + $counts['draft'] ++;
948 811 }
949 812
950 813 unset( $row );
951 814 }
@@ -1011,11 +874,11 @@
1011 874 $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1012 875 }
1013 876
1014 877 if ( $form->id == $values['posted_form_id'] ) {
1015 - // If there are two forms on the same page, make sure not to submit both.
878 + //if there are two forms on the same page, make sure not to submit both
1016 879 foreach ( $default_values as $var => $default ) {
1017 - if ( $var === 'action' ) {
880 + if ( $var == 'action' ) {
1018 881 $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
1019 882 } else {
1020 883 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1021 884 }
@@ -1083,9 +946,9 @@
1083 946 return $values;
1084 947 }
1085 948
1086 949 public static function get_current_form_id( $default_form = 'none' ) {
1087 - if ( 'first' === $default_form ) {
950 + if ( 'first' == $default_form ) {
1088 951 $form = self::get_current_form();
1089 952 } else {
1090 953 $form = self::maybe_get_current_form();
1091 954 }
@@ -1096,9 +959,9 @@
1096 959
1097 960 public static function maybe_get_current_form( $form_id = 0 ) {
1098 961 global $frm_vars;
1099 962
1100 - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
963 + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
1101 964 return $frm_vars['current_form'];
1102 965 }
1103 966
1104 967 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
@@ -1145,9 +1008,9 @@
1145 1008 $global_load = true;
1146 1009 $frm_vars['load_css'] = true;
1147 1010 }
1148 1011
1149 - return empty( $frm_vars['css_loaded'] ) && $global_load;
1012 + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
1150 1013 }
1151 1014
1152 1015 /**
1153 1016 * @since 4.06.03
@@ -1162,21 +1025,13 @@
1162 1025 } else {
1163 1026 $visible = true;
1164 1027 }
1165 1028
1166 - /**
1167 - * @since 6.25
1168 - *
1169 - * @param bool $visible
1170 - * @param object $form
1171 - */
1172 - $visible = (bool) apply_filters( 'frm_form_is_visible', $visible, $form );
1173 -
1174 1029 return $visible;
1175 1030 }
1176 1031
1177 1032 public static function show_submit( $form ) {
1178 - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() );
1033 + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
1179 1034 $show = apply_filters( 'frm_show_submit_button', $show, $form );
1180 1035
1181 1036 return $show;
1182 1037 }
@@ -1184,12 +1039,12 @@
1184 1039 /**
1185 1040 * @since 2.3
1186 1041 */
1187 1042 public static function get_option( $atts ) {
1188 - $form = $atts['form'];
1189 - $default = $atts['default'] ?? '';
1043 + $form = $atts['form'];
1044 + $default = isset( $atts['default'] ) ? $atts['default'] : '';
1190 1045
1191 - return $form->options[ $atts['option'] ] ?? $default;
1046 + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default;
1192 1047 }
1193 1048
1194 1049 /**
1195 1050 * Get the link to edit this form.
@@ -1201,81 +1056,23 @@
1201 1056 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1202 1057 }
1203 1058
1204 1059 /**
1205 - * Check if the "Submit this form with AJAX" setting is toggled on.
1206 - *
1207 - * @since 6.2
1208 - *
1209 - * @param stdClass $form
1210 - * @return bool
1211 - */
1212 - public static function is_ajax_on( $form ) {
1213 - return ! empty( $form->options['ajax_submit'] );
1214 - }
1215 -
1216 - /**
1217 - * Get the latest form available.
1218 - *
1219 - * @since 6.8
1220 - * @return object
1221 - */
1222 - public static function get_latest_form() {
1223 -
1224 - $args = array(
1225 - array(
1226 - 'or' => 1,
1227 - 'parent_form_id' => null,
1228 - 'parent_form_id <' => 1,
1229 - ),
1230 - 'is_template' => 0,
1231 - 'status !' => 'trash',
1232 - );
1233 -
1234 - return self::getAll( $args, 'created_at desc', 1 );
1235 - }
1236 -
1237 - /**
1238 - * Count and return total forms.
1239 - *
1240 - * @since 6.8
1241 - * @return int
1242 - */
1243 - public static function get_forms_count() {
1244 -
1245 - $args = array(
1246 - array(
1247 - 'or' => 1,
1248 - 'parent_form_id' => null,
1249 - 'parent_form_id <' => 1,
1250 - ),
1251 - 'is_template' => 0,
1252 - 'status !' => 'trash',
1253 - );
1254 -
1255 - return FrmDb::get_count( 'frm_forms', $args );
1256 - }
1257 -
1258 - /**
1259 - * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations).
1060 + * @deprecated 3.0
1260 1061 * @codeCoverageIgnore
1261 1062 *
1262 1063 * @param string $key
1064 + *
1263 1065 * @return int form id
1264 1066 */
1265 1067 public static function getIdByKey( $key ) {
1266 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' );
1267 - return self::get_id_by_key( $key );
1068 + return FrmFormDeprecated::getIdByKey( $key );
1268 1069 }
1269 1070
1270 1071 /**
1271 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
1072 + * @deprecated 3.0
1272 1073 * @codeCoverageIgnore
1273 - *
1274 - * @param int|string $id
1275 - * @return string
1276 1074 */
1277 1075 public static function getKeyById( $id ) {
1278 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' );
1279 - return self::get_key_by_id( $id );
1076 + return FrmFormDeprecated::getKeyById( $id );
1280 1077 }
1281 1078 }