PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +72 -77 6.27 → trunk View file →
@@ -16,9 +16,9 @@
16 16 $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
17 17
18 18 $new_values = array(
19 19 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
20 - 'name' => $values['name'],
20 + 'name' => FrmAppHelper::truncate( $values['name'], 255, 1, '', true ),
21 21 'description' => $values['description'],
22 22 'status' => $values['status'] ?? 'published',
23 23 'logged_in' => $values['logged_in'] ?? 0,
24 24 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
@@ -126,9 +126,9 @@
126 126
127 127 $form_id = $wpdb->insert_id;
128 128 FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
129 129
130 - // update form settings after fields are created
130 + // Update form settings after fields are created
131 131 do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
132 132
133 133 return $form_id;
134 134 }
@@ -165,8 +165,10 @@
165 165 /**
166 166 * Switches field ID in fields.
167 167 *
168 168 * @since 5.3
169 + * @since 6.35 The description column is checked too, so a field id in a description survives a
170 + * duplicate or import when the field it points at is created afterwards.
169 171 *
170 172 * @param int $form_id Form ID.
171 173 *
172 174 * @return void
@@ -174,9 +176,9 @@
174 176 private static function switch_field_ids_in_fields( $form_id ) {
175 177 global $wpdb;
176 178
177 179 // Keys of fields that you want to check to replace field ID.
178 - $keys = array( 'default_value', 'field_options' );
180 + $keys = array( 'default_value', 'description', 'field_options' );
179 181 $sql_cols = 'fi.id';
180 182
181 183 foreach ( $keys as $key ) {
182 184 $sql_cols .= ',fi.' . $key;
@@ -267,9 +269,9 @@
267 269 $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) );
268 270
269 271 foreach ( $values as $value_key => $value ) {
270 272 if ( $value_key && in_array( $value_key, $form_fields, true ) ) {
271 - $new_values[ $value_key ] = $value;
273 + $new_values[ $value_key ] = 'name' === $value_key ? FrmAppHelper::truncate( $value, 255, 1, '', true ) : $value;
272 274 }
273 275 }
274 276
275 277 if ( ! empty( $values['new_status'] ) ) {
@@ -406,13 +408,15 @@
406 408 );
407 409
408 410 if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
409 411 foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) {
410 - if ( is_array( $option ) ) {
411 - foreach ( $option as $key => $item ) {
412 - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' );
413 - }
412 + if ( ! is_array( $option ) ) {
413 + continue;
414 414 }
415 +
416 + foreach ( $option as $key => $item ) {
417 + $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' );
418 + }
415 419 }
416 420 }
417 421
418 422 self::prepare_field_update_values( $field, $values, $new_field );
@@ -431,26 +435,28 @@
431 435 * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc.
432 436 *
433 437 * @since 6.7
434 438 *
435 - * @param array $field
436 - * @param array $values
437 - * @param array $new_field
439 + * @param object $field
440 + * @param array $values
441 + * @param array $new_field
438 442 *
439 443 * @return void
440 444 */
441 445 private static function maybe_update_max_option( $field, $values, &$new_field ) {
442 - if ( $field->type === 'textarea' &&
443 - ! empty( $values['field_options'][ 'type_' . $field->id ] ) &&
444 - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) {
445 - $new_field['field_options']['max'] = '';
446 + if ( $field->type !== 'textarea' ||
447 + empty( $values['field_options'][ 'type_' . $field->id ] ) ||
448 + ! in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) {
449 + return;
450 + }
446 451
447 - /**
448 - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads.
449 - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting.
450 - */
451 - $_POST['field_options'][ 'max_' . $field->id ] = '';
452 - }
452 + $new_field['field_options']['max'] = '';
453 +
454 + /**
455 + * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads.
456 + * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting.
457 + */
458 + $_POST['field_options'][ 'max_' . $field->id ] = '';
453 459 }
454 460
455 461 /**
456 462 * @param string $opt
@@ -534,15 +540,17 @@
534 540 } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
535 541 $prev_opts = $field->field_options;
536 542 }
537 543
538 - if ( isset( $prev_opts ) ) {
539 - $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
544 + if ( ! isset( $prev_opts ) ) {
545 + return;
546 + }
540 547
541 - // phpcs:ignore Universal.Operators.StrictComparisons
542 - if ( $prev_opts != $field->field_options ) {
543 - FrmField::update( $field->id, array( 'field_options' => $field->field_options ) );
544 - }
548 + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
549 +
550 + // phpcs:ignore Universal.Operators.StrictComparisons
551 + if ( $prev_opts != $field->field_options ) {
552 + FrmField::update( $field->id, array( 'field_options' => $field->field_options ) );
545 553 }
546 554 }
547 555
548 556 /**
@@ -604,10 +612,10 @@
604 612 return apply_filters( 'frm_form_strings', $strings, $form );
605 613 }
606 614
607 615 /**
608 - * @param int $id
609 - * @param string $status
616 + * @param array|int $id
617 + * @param string $status
610 618 *
611 619 * @return bool|int
612 620 */
613 621 public static function set_status( $id, $status ) {
@@ -714,9 +722,9 @@
714 722
715 723 $id = $form->id;
716 724
717 725 // Disconnect the entries from this form
718 - $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
726 + $entries = FrmDb::get_col( 'frm_items', array( 'form_id' => $id ) );
719 727
720 728 foreach ( $entries as $entry_id ) {
721 729 FrmEntry::destroy( $entry_id );
722 730 unset( $entry_id );
@@ -726,23 +734,25 @@
726 734 $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
727 735
728 736 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
729 737
730 - if ( $query_results ) {
731 - // Delete all form actions linked to this form
732 - /**
733 - * @var FrmFormAction
734 - */
735 - $action_control = FrmFormActionsController::get_form_actions( 'email' );
736 - $action_control->destroy( $id, 'all' );
738 + if ( ! $query_results ) {
739 + return $query_results;
740 + }
737 741
738 - // Clear form caching
739 - self::clear_form_cache();
742 + // Delete all form actions linked to this form
743 + /**
744 + * @var FrmFormAction
745 + */
746 + $action_control = FrmFormActionsController::get_form_actions( 'email' );
747 + $action_control->destroy( $id, 'all' );
740 748
741 - do_action( 'frm_destroy_form', $id );
742 - do_action( 'frm_destroy_form_' . $id );
743 - }
749 + // Clear form caching
750 + self::clear_form_cache();
744 751
752 + do_action( 'frm_destroy_form', $id );
753 + do_action( 'frm_destroy_form_' . $id );
754 +
745 755 return $query_results;
746 756 }
747 757
748 758 /**
@@ -752,12 +762,10 @@
752 762 *
753 763 * @return int The number of forms deleted
754 764 */
755 765 public static function scheduled_delete( $delete_timestamp = '' ) {
756 - global $wpdb;
766 + $trash_forms = FrmDb::get_results( 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
757 767
758 - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
759 -
760 768 if ( ! $trash_forms ) {
761 769 return 0;
762 770 }
763 771
@@ -836,14 +844,14 @@
836 844 * If $form is numeric, get the form object
837 845 *
838 846 * @since 2.0.9
839 847 *
840 - * @param int|object $form
848 + * @param array|int|object $form
841 849 *
842 850 * @return void
843 851 */
844 852 public static function maybe_get_form( &$form ) {
845 - if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
853 + if ( ! is_object( $form ) && ! is_array( $form ) && $form ) {
846 854 $form = self::getOne( $form );
847 855 }
848 856 }
849 857
@@ -915,14 +923,14 @@
915 923 * @param array|string $where Where conditions array or raw WHERE string.
916 924 * @param string $order_by Order by clause.
917 925 * @param int|string $limit Limit clause or number.
918 926 *
919 - * @return array|object of objects
927 + * @return array|object Array of objects. If $limit is 1, a single object is returned.
920 928 */
921 929 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
922 930 if ( is_array( $where ) && $where ) {
923 931 if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
924 - // don't get trashed templates
932 + // Don't get trashed templates
925 933 $where['status'] = array( null, '', 'published' );
926 934 }
927 935
928 936 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
@@ -941,9 +949,9 @@
941 949 }
942 950 }
943 951
944 952 if ( $limit === ' LIMIT 1' || (int) $limit === 1 ) {
945 - // return the first form object if we are only getting one form
953 + // Return the first form object if we are only getting one form
946 954 $results = reset( $results );
947 955 }
948 956
949 957 return wp_unslash( $results );
@@ -957,9 +965,9 @@
957 965 * @param array $query
958 966 * @param int $limit
959 967 * @param string $inc_children
960 968 *
961 - * @return array|object of forms A single form object would be passed if $limit was set to 1.
969 + * @return array|object Array of forms. A single form object is returned if $limit is set to 1.
962 970 */
963 971 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
964 972 $query['is_template'] = 0;
965 973 $query['status'] = array( null, '', 'published' );
@@ -995,16 +1003,14 @@
995 1003 $statuses = array( 'published', 'draft', 'template', 'trash' );
996 1004 $counts = array_fill_keys( $statuses, 0 );
997 1005
998 1006 foreach ( $results as $row ) {
999 - if ( 'trash' !== $row->status ) {
1000 - if ( $row->is_template ) {
1001 - ++$counts['template'];
1002 - } else {
1003 - ++$counts['published'];
1004 - }
1007 + if ( 'trash' === $row->status ) {
1008 + ++$counts['trash'];
1009 + } elseif ( $row->is_template ) {
1010 + ++$counts['template'];
1005 1011 } else {
1006 - ++$counts['trash'];
1012 + ++$counts['published'];
1007 1013 }
1008 1014
1009 1015 if ( 'draft' === $row->status ) {
1010 1016 ++$counts['draft'];
@@ -1049,12 +1055,12 @@
1049 1055 */
1050 1056 public static function get_params( $form = null ) {
1051 1057 global $frm_vars;
1052 1058
1053 - if ( ! $form ) {
1059 + if ( $form ) {
1060 + self::maybe_get_form( $form );
1061 + } else {
1054 1062 $form = self::getAll( array(), 'name', 1 );
1055 - } else {
1056 - self::maybe_get_form( $form );
1057 1063 }
1058 1064
1059 1065 if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
1060 1066 return $frm_vars['form_params'][ $form->id ];
@@ -1190,13 +1196,9 @@
1190 1196 }
1191 1197
1192 1198 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
1193 1199
1194 - if ( $form_id ) {
1195 - $form_id = self::set_current_form( $form_id );
1196 - }
1197 -
1198 - return $form_id;
1200 + return $form_id ? self::set_current_form( $form_id ) : $form_id;
1199 1201 }
1200 1202
1201 1203 /**
1202 1204 * @param int $form_id
@@ -1204,14 +1206,9 @@
1204 1206 * @return false|object
1205 1207 */
1206 1208 public static function get_current_form( $form_id = 0 ) {
1207 1209 $form = self::maybe_get_current_form( $form_id );
1208 -
1209 - if ( is_numeric( $form ) ) {
1210 - $form = self::set_current_form( $form );
1211 - }
1212 -
1213 - return $form;
1210 + return is_numeric( $form ) ? self::set_current_form( $form ) : $form;
1214 1211 }
1215 1212
1216 1213 /**
1217 1214 * @param int $form_id
@@ -1249,9 +1246,9 @@
1249 1246 }
1250 1247
1251 1248 $frm_vars['forms_loaded'][] = $small_form;
1252 1249
1253 - if ( $this_load && empty( $global_load ) ) {
1250 + if ( $this_load && ! $global_load ) {
1254 1251 $global_load = true;
1255 1252 $frm_vars['load_css'] = true;
1256 1253 }
1257 1254
@@ -1264,9 +1261,9 @@
1264 1261 * @param object $form
1265 1262 *
1266 1263 * @return bool
1267 1264 */
1268 - public static function &is_visible_to_user( $form ) {
1265 + public static function is_visible_to_user( $form ) {
1269 1266 if ( $form->logged_in && isset( $form->options['logged_in_role'] ) ) {
1270 1267 $visible = FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1271 1268 } else {
1272 1269 $visible = true;
@@ -1277,11 +1274,9 @@
1277 1274 *
1278 1275 * @param bool $visible
1279 1276 * @param object $form
1280 1277 */
1281 - $visible = (bool) apply_filters( 'frm_form_is_visible', $visible, $form );
1282 -
1283 - return $visible;
1278 + return (bool) apply_filters( 'frm_form_is_visible', $visible, $form );
1284 1279 }
1285 1280
1286 1281 /**
1287 1282 * @param object $form