PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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 +88 -412 6.254.07.01 View file →
@@ -5,48 +5,38 @@
5 5
6 6 class FrmForm {
7 7
8 8 /**
9 - * @param array $values
10 - * @return bool|int id on success or false on failure.
9 + * @return int|boolean id on success or false on failure
11 10 */
12 11 public static function create( $values ) {
13 12 global $wpdb;
14 13
15 - $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
16 -
17 14 $new_values = array(
18 15 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
19 16 'name' => $values['name'],
20 17 'description' => $values['description'],
21 - 'status' => $values['status'] ?? 'published',
22 - 'logged_in' => $values['logged_in'] ?? 0,
18 + 'status' => isset( $values['status'] ) ? $values['status'] : 'published',
19 + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
23 20 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
24 21 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
25 22 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
26 - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ),
23 + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
27 24 );
28 25
29 26 $options = isset( $values['options'] ) ? (array) $values['options'] : array();
30 27 FrmFormsHelper::fill_form_options( $options, $values );
31 28
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' );
29 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
30 + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
31 + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
35 32
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 );
46 - $options = self::maybe_filter_form_options( $options );
33 + $options = apply_filters( 'frm_form_options_before_update', $options, $values );
47 34 $new_values['options'] = serialize( $options );
48 35
36 + //if(isset($values['id']) && is_numeric($values['id']))
37 + // $new_values['id'] = $values['id'];
38 +
49 39 $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
50 40
51 41 $id = $wpdb->insert_id;
52 42
@@ -56,23 +46,10 @@
56 46 return $id;
57 47 }
58 48
59 49 /**
60 - * @since 5.0.08
61 - *
62 - * @param array $options
63 - * @return array
50 + * @return int|boolean ID on success or false on failure
64 51 */
65 - private static function maybe_filter_form_options( $options ) {
66 - if ( ! FrmAppHelper::allow_unfiltered_html() && ! empty( $options['submit_html'] ) ) {
67 - $options['submit_html'] = FrmAppHelper::kses_submit_button( $options['submit_html'] );
68 - }
69 - return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) );
70 - }
71 -
72 - /**
73 - * @return bool|int ID on success or false on failure
74 - */
75 52 public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
76 53 global $wpdb;
77 54
78 55 $values = self::getOne( $id, $blog_id );
@@ -93,10 +70,10 @@
93 70 'is_template' => $template ? 1 : 0,
94 71 );
95 72
96 73 if ( $blog_id ) {
97 - $new_values['status'] = 'published';
98 - $new_options = $values->options;
74 + $new_values['status'] = 'published';
75 + $new_options = $values->options;
99 76 FrmAppHelper::unserialize_or_decode( $new_options );
100 77 $new_options['email_to'] = get_option( 'admin_email' );
101 78 $new_options['copy'] = false;
102 79 $new_values['options'] = $new_options;
@@ -126,9 +103,9 @@
126 103 return false;
127 104 }
128 105
129 106 public static function after_duplicate( $form_id, $values ) {
130 - $new_opts = $values['options'];
107 + $new_opts = $values['options'];
131 108 FrmAppHelper::unserialize_or_decode( $new_opts );
132 109 $values['options'] = $new_opts;
133 110
134 111 if ( isset( $new_opts['success_msg'] ) ) {
@@ -140,93 +117,16 @@
140 117 if ( $new_opts != $values['options'] ) {
141 118 global $wpdb;
142 119 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
143 120 }
144 -
145 - self::switch_field_ids_in_fields( $form_id );
146 121 }
147 122
148 123 /**
149 - * Switches field ID in fields.
150 - *
151 - * @since 5.3
152 - *
153 - * @param int $form_id Form ID.
124 + * @return int|boolean
154 125 */
155 - private static function switch_field_ids_in_fields( $form_id ) {
156 - global $wpdb;
157 -
158 - // Keys of fields that you want to check to replace field ID.
159 - $keys = array( 'default_value', 'field_options' );
160 - $sql_cols = 'fi.id';
161 - foreach ( $keys as $key ) {
162 - $sql_cols .= ',fi.' . $key;
163 - }
164 -
165 - $fields = FrmDb::get_results(
166 - "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id",
167 - array(
168 - 'or' => 1,
169 - 'fi.form_id' => $form_id,
170 - 'fr.parent_form_id' => $form_id,
171 - ),
172 - $sql_cols
173 - );
174 -
175 - if ( ! $fields || ! is_array( $fields ) ) {
176 - return;
177 - }
178 -
179 - foreach ( $fields as $field ) {
180 - self::switch_field_ids_in_field( (array) $field );
181 - }
182 - }
183 -
184 - /**
185 - * Switches field ID in a field.
186 - *
187 - * @since 5.3
188 - *
189 - * @param array $field Field array.
190 - */
191 - private static function switch_field_ids_in_field( $field ) {
192 - $new_values = array();
193 - foreach ( $field as $key => $value ) {
194 - if ( 'id' === $key || ! $value ) {
195 - continue;
196 - }
197 -
198 - if ( ! is_string( $value ) && ! is_array( $value ) ) {
199 - continue;
200 - }
201 -
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 -
211 - if ( $new_val !== $value ) {
212 - $new_values[ $key ] = $new_val;
213 - }
214 - }//end foreach
215 -
216 - if ( ! empty( $new_values ) ) {
217 - FrmField::update( $field['id'], $new_values );
218 - }
219 - }
220 -
221 - /**
222 - * @return bool|int
223 - */
224 126 public static function update( $id, $values, $create_link = false ) {
225 127 global $wpdb;
226 128
227 - $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
228 -
229 129 if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
230 130 $values['status'] = 'published';
231 131 }
232 132
@@ -235,9 +135,9 @@
235 135 }
236 136
237 137 $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
238 138
239 - $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) );
139 + $new_values = self::set_update_options( array(), $values );
240 140
241 141 foreach ( $values as $value_key => $value ) {
242 142 if ( $value_key && in_array( $value_key, $form_fields ) ) {
243 143 $new_values[ $value_key ] = $value;
@@ -243,9 +143,9 @@
243 143 $new_values[ $value_key ] = $value;
244 144 }
245 145 }
246 146
247 - if ( ! empty( $values['new_status'] ) ) {
147 + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
248 148 $new_values['status'] = $values['new_status'];
249 149 }
250 150
251 151 if ( ! empty( $new_values ) ) {
@@ -266,37 +166,24 @@
266 166 return $query_results;
267 167 }
268 168
269 169 /**
270 - * @param array $new_values
271 - * @param array $values
272 - * @param array $args
273 170 * @return array
274 171 */
275 - public static function set_update_options( $new_values, $values, $args = array() ) {
172 + public static function set_update_options( $new_values, $values ) {
276 173 if ( ! isset( $values['options'] ) ) {
277 174 return $new_values;
278 175 }
279 176
280 - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array();
177 + $options = isset( $values['options'] ) ? (array) $values['options'] : array();
281 178 FrmFormsHelper::fill_form_options( $options, $values );
282 179
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' );
180 + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
181 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
182 + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
183 + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
287 184
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 );
298 - $options = self::maybe_filter_form_options( $options );
185 + $options = apply_filters( 'frm_form_options_before_update', $options, $values );
299 186 $new_values['options'] = serialize( $options );
300 187
301 188 return $new_values;
302 189 }
@@ -348,20 +235,15 @@
348 235 continue;
349 236 }
350 237 }
351 238
352 - // Updating the form.
239 + //updating the form
353 240 $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field );
354 - // Don't check for POST html.
355 - unset( $update_options['custom_html'] );
241 + unset( $update_options['custom_html'] ); // don't check for POST html
356 242 $update_options = apply_filters( 'frm_field_options_to_update', $update_options );
357 243
358 - if ( ! is_array( $field->field_options ) ) {
359 - $field->field_options = array();
360 - }
361 -
362 244 foreach ( $update_options as $opt => $default ) {
363 - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default;
245 + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
364 246 self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
365 247 }
366 248
367 249 $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
@@ -370,135 +252,44 @@
370 252 'field_options' => $field->field_options,
371 253 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '',
372 254 );
373 255
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 256 self::prepare_field_update_values( $field, $values, $new_field );
385 - self::maybe_update_max_option( $field, $values, $new_field );
386 257
387 258 FrmField::update( $field_id, $new_field );
388 259
389 260 FrmField::delete_form_transient( $field->form_id );
390 - }//end foreach
261 + }
391 262 self::clear_form_cache();
392 263
393 264 return $values;
394 265 }
395 266
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 267 private static function sanitize_field_opt( $opt, &$value ) {
427 - if ( ! is_string( $value ) ) {
428 - return;
268 + if ( is_string( $value ) ) {
269 + if ( $opt === 'calc' ) {
270 + $allow = array( '<= ', ' >=' ); // Allow <= and >=
271 + $temp = array( '< = ', ' > =' );
272 + $value = str_replace( $allow, $temp, $value );
273 + $value = strip_tags( $value );
274 + $value = str_replace( $temp, $allow, $value );
275 + } else {
276 + $value = FrmAppHelper::kses( $value, 'all' );
277 + }
278 + $value = trim( $value );
429 279 }
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 280 }
454 281
455 282 /**
456 - * @param string $value
457 - * @return string
458 - */
459 - private static function sanitize_calc( $value ) {
460 - if ( false !== strpos( $value, '<' ) ) {
461 - $value = self::normalize_calc_spaces( $value );
462 - }
463 - // Allow <= and >=.
464 - $allow = array( '<= ', ' >=' );
465 - $temp = array( '< = ', ' > =' );
466 - $value = str_replace( $allow, $temp, $value );
467 - $value = strip_tags( $value );
468 - $value = str_replace( $temp, $allow, $value );
469 - return $value;
470 - }
471 -
472 - /**
473 - * Format a comparison like 5<10 to 5 < 10. Also works on 5< 10, 5 <10, 5<=10 variations.
474 - * This is to avoid an issue with unspaced calculations being recognized as HTML that gets removed when strip_tags is called.
475 - *
476 - * @param string $calc
477 - * @return string
478 - */
479 - private static function normalize_calc_spaces( $calc ) {
480 - // Check for a pattern with 5 parts
481 - // $1 \d|\] the first comparison digit or the end of a comparison shortcode.
482 - // $2 a space (optional).
483 - // $3 an equals sign (optional) that follows the < operator for <= comparisons.
484 - // $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;
489 - }
490 -
491 - /**
492 283 * Updating the settings page
493 284 */
494 285 private static function get_settings_page_html( $values, &$field ) {
495 286 if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
496 287 $prev_opts = array();
497 - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type );
288 + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
498 289
499 - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html;
500 - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
290 + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
291 + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
501 292 $prev_opts = $field->field_options;
502 293 }
503 294
504 295 if ( isset( $prev_opts ) ) {
@@ -519,14 +310,11 @@
519 310 'options' => '',
520 311 'name' => '',
521 312 );
522 313 foreach ( $field_cols as $col => $default ) {
523 - $default = $default === '' ? $field->{$col} : $default;
524 - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default;
525 - }
314 + $default = ( $default === '' ) ? $field->{$col} : $default;
526 315
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;
316 + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
529 317 }
530 318
531 319 // Don't save the template option.
532 320 if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
@@ -538,9 +326,9 @@
538 326 * Get a list of all form settings that should be translated
539 327 * on a multilingual site.
540 328 *
541 329 * @since 3.06.01
542 - * @param object $form The form object.
330 + * @param object $form - The form object
543 331 */
544 332 public static function translatable_strings( $form ) {
545 333 $strings = array(
546 334 'name',
@@ -547,12 +335,8 @@
547 335 'description',
548 336 'submit_value',
549 337 'submit_msg',
550 338 'success_msg',
551 - 'invalid_msg',
552 - 'failed_msg',
553 - 'login_msg',
554 - 'admin_permission',
555 339 );
556 340
557 341 return apply_filters( 'frm_form_strings', $strings, $form );
558 342 }
@@ -557,12 +341,11 @@
557 341 return apply_filters( 'frm_form_strings', $strings, $form );
558 342 }
559 343
560 344 /**
561 - * @param int $id
562 345 * @param string $status
563 346 *
564 - * @return bool|int
347 + * @return int|boolean
565 348 */
566 349 public static function set_status( $id, $status ) {
567 350 if ( 'trash' == $status ) {
568 351 return self::trash( $id );
@@ -568,9 +351,9 @@
568 351 return self::trash( $id );
569 352 }
570 353
571 354 $statuses = array( 'published', 'draft', 'trash' );
572 - if ( ! in_array( $status, $statuses, true ) ) {
355 + if ( ! in_array( $status, $statuses ) ) {
573 356 return false;
574 357 }
575 358
576 359 global $wpdb;
@@ -583,9 +366,9 @@
583 366 );
584 367 FrmDb::get_where_clause_and_values( $where );
585 368 array_unshift( $where['values'], $status );
586 369
587 - $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
370 + $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
588 371 } else {
589 372 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
590 373 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
591 374 }
@@ -597,9 +380,9 @@
597 380 return $query_results;
598 381 }
599 382
600 383 /**
601 - * @return bool|int
384 + * @return int|boolean
602 385 */
603 386 public static function trash( $id ) {
604 387 if ( ! EMPTY_TRASH_DAYS ) {
605 388 return self::destroy( $id );
@@ -609,12 +392,8 @@
609 392 if ( ! $form ) {
610 393 return false;
611 394 }
612 395
613 - if ( $form->status === 'trash' ) {
614 - return false;
615 - }
616 -
617 396 $options = $form->options;
618 397 $options['trash_time'] = time();
619 398
620 399 global $wpdb;
@@ -647,9 +426,9 @@
647 426 return $query_results;
648 427 }
649 428
650 429 /**
651 - * @return bool|int
430 + * @return int|boolean
652 431 */
653 432 public static function destroy( $id ) {
654 433 global $wpdb;
655 434
@@ -671,11 +450,8 @@
671 450
672 451 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
673 452 if ( $query_results ) {
674 453 // Delete all form actions linked to this form
675 - /**
676 - * @var FrmFormAction
677 - */
678 454 $action_control = FrmFormActionsController::get_form_actions( 'email' );
679 455 $action_control->destroy( $id, 'all' );
680 456
681 457 // Clear form caching
@@ -695,12 +471,12 @@
695 471 */
696 472 public static function scheduled_delete( $delete_timestamp = '' ) {
697 473 global $wpdb;
698 474
699 - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
475 + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
700 476
701 477 if ( ! $trash_forms ) {
702 - return 0;
478 + return;
703 479 }
704 480
705 481 if ( empty( $delete_timestamp ) ) {
706 482 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
@@ -710,11 +486,9 @@
710 486 foreach ( $trash_forms as $form ) {
711 487 FrmAppHelper::unserialize_or_decode( $form->options );
712 488 if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
713 489 self::destroy( $form->id );
714 - if ( empty( $form->parent_form_id ) ) {
715 - ++$count;
716 - }
490 + $count ++;
717 491 }
718 492
719 493 unset( $form );
720 494 }
@@ -734,12 +508,10 @@
734 508 }
735 509
736 510 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
737 511 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
512 + $r = stripslashes( $r );
738 513
739 - // An empty form name can result in a null value.
740 - $r = is_null( $r ) ? '' : stripslashes( $r );
741 -
742 514 return $r;
743 515 }
744 516
745 517 /**
@@ -774,10 +546,11 @@
774 546
775 547 /**
776 548 * If $form is numeric, get the form object
777 549 *
550 + * @param object|int $form
551 + *
778 552 * @since 2.0.9
779 - * @param int|object $form
780 553 */
781 554 public static function maybe_get_form( &$form ) {
782 555 if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
783 556 $form = self::getOne( $form );
@@ -784,11 +557,9 @@
784 557 }
785 558 }
786 559
787 560 /**
788 - * @param int|string $id
789 - * @param false|int $blog_id
790 - * @return stdClass|null
561 + * @return object form
791 562 */
792 563 public static function getOne( $id, $blog_id = false ) {
793 564 global $wpdb;
794 565
@@ -803,9 +574,10 @@
803 574 if ( $cache ) {
804 575 if ( isset( $cache->options ) ) {
805 576 FrmAppHelper::unserialize_or_decode( $cache->options );
806 577 }
807 - return self::prepare_form_row_data( $cache );
578 +
579 + return wp_unslash( $cache );
808 580 }
809 581 }
810 582
811 583 if ( is_numeric( $id ) ) {
@@ -820,43 +592,17 @@
820 592 FrmDb::set_cache( $results->id, $results, 'frm_form' );
821 593 FrmAppHelper::unserialize_or_decode( $results->options );
822 594 }
823 595
824 - return self::prepare_form_row_data( $results );
596 + return apply_filters( 'frm_form_object', wp_unslash( $results ) );
825 597 }
826 598
827 599 /**
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
600 + * @return object|array of objects
834 601 */
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 602 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
857 603 if ( is_array( $where ) && ! empty( $where ) ) {
858 - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
604 + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
859 605 // don't get trashed templates
860 606 $where['status'] = array( null, '', 'published' );
861 607 }
862 608
@@ -863,11 +609,11 @@
863 609 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
864 610 } else {
865 611 global $wpdb;
866 612
867 - // The query has already been prepared if this is not an array.
613 + // the query has already been prepared if this is not an array
868 614 $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
869 - $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
615 + $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok.
870 616 }
871 617
872 618 if ( $results ) {
873 619 foreach ( $results as $result ) {
@@ -875,9 +621,9 @@
875 621 FrmAppHelper::unserialize_or_decode( $result->options );
876 622 }
877 623 }
878 624
879 - if ( $limit === ' LIMIT 1' || $limit == 1 ) {
625 + if ( $limit == ' LIMIT 1' || $limit == 1 ) {
880 626 // return the first form object if we are only getting one form
881 627 $results = reset( $results );
882 628 }
883 629
@@ -887,18 +633,14 @@
887 633 /**
888 634 * Get all published forms
889 635 *
890 636 * @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.
637 + * @return array of forms
896 638 */
897 639 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
898 640 $query['is_template'] = 0;
899 641 $query['status'] = array( null, '', 'published' );
900 - if ( $inc_children === 'exclude' ) {
642 + if ( $inc_children == 'exclude' ) {
901 643 $query['parent_form_id'] = array( null, 0 );
902 644 }
903 645
904 646 $forms = self::getAll( $query, 'name', $limit );
@@ -934,18 +676,18 @@
934 676
935 677 foreach ( $results as $row ) {
936 678 if ( 'trash' != $row->status ) {
937 679 if ( $row->is_template ) {
938 - ++$counts['template'];
680 + $counts['template'] ++;
939 681 } else {
940 - ++$counts['published'];
682 + $counts['published'] ++;
941 683 }
942 684 } else {
943 - ++$counts['trash'];
685 + $counts['trash'] ++;
944 686 }
945 687
946 688 if ( 'draft' == $row->status ) {
947 - ++$counts['draft'];
689 + $counts['draft'] ++;
948 690 }
949 691
950 692 unset( $row );
951 693 }
@@ -988,9 +730,9 @@
988 730 if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
989 731 return $frm_vars['form_params'][ $form->id ];
990 732 }
991 733
992 - $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
734 + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok.
993 735 $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
994 736
995 737 $default_values = array(
996 738 'id' => '',
@@ -1011,11 +753,11 @@
1011 753 $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1012 754 }
1013 755
1014 756 if ( $form->id == $values['posted_form_id'] ) {
1015 - // If there are two forms on the same page, make sure not to submit both.
757 + //if there are two forms on the same page, make sure not to submit both
1016 758 foreach ( $default_values as $var => $default ) {
1017 - if ( $var === 'action' ) {
759 + if ( $var == 'action' ) {
1018 760 $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
1019 761 } else {
1020 762 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1021 763 }
@@ -1028,9 +770,9 @@
1028 770 }
1029 771 }
1030 772
1031 773 if ( in_array( $values['action'], array( 'create', 'update' ) ) &&
1032 - ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
774 + ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // WPCS: CSRF ok.
1033 775 ) {
1034 776 $values['action'] = 'new';
1035 777 }
1036 778
@@ -1083,9 +825,9 @@
1083 825 return $values;
1084 826 }
1085 827
1086 828 public static function get_current_form_id( $default_form = 'none' ) {
1087 - if ( 'first' === $default_form ) {
829 + if ( 'first' == $default_form ) {
1088 830 $form = self::get_current_form();
1089 831 } else {
1090 832 $form = self::maybe_get_current_form();
1091 833 }
@@ -1096,9 +838,9 @@
1096 838
1097 839 public static function maybe_get_current_form( $form_id = 0 ) {
1098 840 global $frm_vars;
1099 841
1100 - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
842 + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
1101 843 return $frm_vars['current_form'];
1102 844 }
1103 845
1104 846 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
@@ -1145,9 +887,9 @@
1145 887 $global_load = true;
1146 888 $frm_vars['load_css'] = true;
1147 889 }
1148 890
1149 - return empty( $frm_vars['css_loaded'] ) && $global_load;
891 + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
1150 892 }
1151 893
1152 894 /**
1153 895 * @since 4.06.03
@@ -1162,21 +904,13 @@
1162 904 } else {
1163 905 $visible = true;
1164 906 }
1165 907
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 908 return $visible;
1175 909 }
1176 910
1177 911 public static function show_submit( $form ) {
1178 - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() );
912 + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
1179 913 $show = apply_filters( 'frm_show_submit_button', $show, $form );
1180 914
1181 915 return $show;
1182 916 }
@@ -1184,12 +918,12 @@
1184 918 /**
1185 919 * @since 2.3
1186 920 */
1187 921 public static function get_option( $atts ) {
1188 - $form = $atts['form'];
1189 - $default = $atts['default'] ?? '';
922 + $form = $atts['form'];
923 + $default = isset( $atts['default'] ) ? $atts['default'] : '';
1190 924
1191 - return $form->options[ $atts['option'] ] ?? $default;
925 + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default;
1192 926 }
1193 927
1194 928 /**
1195 929 * Get the link to edit this form.
@@ -1201,81 +935,23 @@
1201 935 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1202 936 }
1203 937
1204 938 /**
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).
939 + * @deprecated 3.0
1260 940 * @codeCoverageIgnore
1261 941 *
1262 942 * @param string $key
943 + *
1263 944 * @return int form id
1264 945 */
1265 946 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 );
947 + return FrmFormDeprecated::getIdByKey( $key );
1268 948 }
1269 949
1270 950 /**
1271 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
951 + * @deprecated 3.0
1272 952 * @codeCoverageIgnore
1273 - *
1274 - * @param int|string $id
1275 - * @return string
1276 953 */
1277 954 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 );
955 + return FrmFormDeprecated::getKeyById( $id );
1280 956 }
1281 957 }