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 +24 -104 6.5.35.3 View file →
@@ -6,9 +6,9 @@
6 6 class FrmForm {
7 7
8 8 /**
9 9 * @param array $values
10 - * @return int|bool 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
@@ -32,18 +32,9 @@
32 32 $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
33 33 $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
34 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 );
@@ -198,17 +189,9 @@
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 197 }
@@ -284,18 +267,14 @@
284 267 $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
285 268 $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
286 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;
@@ -365,18 +344,8 @@
365 344 'field_options' => $field->field_options,
366 345 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '',
367 346 );
368 347
369 - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) {
370 - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) {
371 - if ( is_array( $option ) ) {
372 - foreach ( $option as $key => $item ) {
373 - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' );
374 - }
375 - }
376 - }
377 - }
378 -
379 348 self::prepare_field_update_values( $field, $values, $new_field );
380 349
381 350 FrmField::update( $field_id, $new_field );
382 351
@@ -386,40 +355,17 @@
386 355
387 356 return $values;
388 357 }
389 358
390 - /**
391 - * @param string $opt
392 - * @param mixed $value
393 - * @return void
394 - */
395 359 private static function sanitize_field_opt( $opt, &$value ) {
396 - if ( ! is_string( $value ) ) {
397 - 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 );
398 367 }
399 -
400 - /**
401 - * Allow the option to turn off sanitization for a field. This way a custom rule can be used instead.
402 - * Make sure to add custom sanitization using the frm_update_field_options filter as the data will no longer be sanitized.
403 - *
404 - * @since 6.0
405 - *
406 - * @param bool $should_sanitize
407 - * @param string $opt
408 - */
409 - $should_sanitize = apply_filters( 'frm_should_sanitize_field_opt_string', true, $opt );
410 -
411 - if ( ! $should_sanitize ) {
412 - return;
413 - }
414 -
415 - if ( $opt === 'calc' ) {
416 - $value = self::sanitize_calc( $value );
417 - } else {
418 - $value = FrmAppHelper::kses( $value, 'all' );
419 - }
420 -
421 - $value = trim( $value );
422 368 }
423 369
424 370 /**
425 371 * @param string $value
@@ -510,12 +456,8 @@
510 456 'description',
511 457 'submit_value',
512 458 'submit_msg',
513 459 'success_msg',
514 - 'invalid_msg',
515 - 'failed_msg',
516 - 'login_msg',
517 - 'admin_permission',
518 460 );
519 461
520 462 return apply_filters( 'frm_form_strings', $strings, $form );
521 463 }
@@ -687,12 +629,10 @@
687 629 }
688 630
689 631 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
690 632 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
633 + $r = stripslashes( $r );
691 634
692 - // An empty form name can result in a null value.
693 - $r = is_null( $r ) ? '' : stripslashes( $r );
694 -
695 635 return $r;
696 636 }
697 637
698 638 /**
@@ -756,9 +696,9 @@
756 696 if ( isset( $cache->options ) ) {
757 697 FrmAppHelper::unserialize_or_decode( $cache->options );
758 698 }
759 699
760 - return apply_filters( 'frm_form_object', wp_unslash( $cache ) );
700 + return wp_unslash( $cache );
761 701 }
762 702 }
763 703
764 704 if ( is_numeric( $id ) ) {
@@ -814,13 +754,9 @@
814 754 /**
815 755 * Get all published forms
816 756 *
817 757 * @since 2.0
818 - *
819 - * @param array $query
820 - * @param int $limit
821 - * @param string $inc_children
822 - * @return array|object of forms A single form object would be passed if $limit was set to 1.
758 + * @return array of forms
823 759 */
824 760 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
825 761 $query['is_template'] = 0;
826 762 $query['status'] = array( null, '', 'published' );
@@ -1120,39 +1056,23 @@
1120 1056 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1121 1057 }
1122 1058
1123 1059 /**
1124 - * Check if the "Submit this form with AJAX" setting is toggled on.
1125 - *
1126 - * @since 6.2
1127 - *
1128 - * @param stdClass $form
1129 - * @return bool
1130 - */
1131 - public static function is_ajax_on( $form ) {
1132 - return ! empty( $form->options['ajax_submit'] );
1133 - }
1134 -
1135 - /**
1136 - * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations).
1060 + * @deprecated 3.0
1137 1061 * @codeCoverageIgnore
1138 1062 *
1139 1063 * @param string $key
1064 + *
1140 1065 * @return int form id
1141 1066 */
1142 1067 public static function getIdByKey( $key ) {
1143 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' );
1144 - return self::get_id_by_key( $key );
1068 + return FrmFormDeprecated::getIdByKey( $key );
1145 1069 }
1146 1070
1147 1071 /**
1148 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
1072 + * @deprecated 3.0
1149 1073 * @codeCoverageIgnore
1150 - *
1151 - * @param string|int $id
1152 - * @return string
1153 1074 */
1154 1075 public static function getKeyById( $id ) {
1155 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' );
1156 - return self::get_key_by_id( $id );
1076 + return FrmFormDeprecated::getKeyById( $id );
1157 1077 }
1158 1078 }