PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.15
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 +80 -358 6.255.0.15 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'] ) ) {
@@ -140,88 +131,13 @@
140 131 if ( $new_opts != $values['options'] ) {
141 132 global $wpdb;
142 133 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
143 134 }
144 -
145 - self::switch_field_ids_in_fields( $form_id );
146 135 }
147 136
148 137 /**
149 - * Switches field ID in fields.
150 - *
151 - * @since 5.3
152 - *
153 - * @param int $form_id Form ID.
138 + * @return int|boolean
154 139 */
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 140 public static function update( $id, $values, $create_link = false ) {
225 141 global $wpdb;
226 142
227 143 $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
@@ -235,9 +151,9 @@
235 151 }
236 152
237 153 $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
238 154
239 - $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) );
155 + $new_values = self::set_update_options( array(), $values );
240 156
241 157 foreach ( $values as $value_key => $value ) {
242 158 if ( $value_key && in_array( $value_key, $form_fields ) ) {
243 159 $new_values[ $value_key ] = $value;
@@ -243,9 +159,9 @@
243 159 $new_values[ $value_key ] = $value;
244 160 }
245 161 }
246 162
247 - if ( ! empty( $values['new_status'] ) ) {
163 + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
248 164 $new_values['status'] = $values['new_status'];
249 165 }
250 166
251 167 if ( ! empty( $new_values ) ) {
@@ -266,36 +182,24 @@
266 182 return $query_results;
267 183 }
268 184
269 185 /**
270 - * @param array $new_values
271 - * @param array $values
272 - * @param array $args
273 186 * @return array
274 187 */
275 - public static function set_update_options( $new_values, $values, $args = array() ) {
188 + public static function set_update_options( $new_values, $values ) {
276 189 if ( ! isset( $values['options'] ) ) {
277 190 return $new_values;
278 191 }
279 192
280 - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array();
193 + $options = isset( $values['options'] ) ? (array) $values['options'] : array();
281 194 FrmFormsHelper::fill_form_options( $options, $values );
282 195
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' );
196 + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
197 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
198 + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
199 + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
287 200
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 );
201 + $options = apply_filters( 'frm_form_options_before_update', $options, $values );
298 202 $options = self::maybe_filter_form_options( $options );
299 203 $new_values['options'] = serialize( $options );
300 204
301 205 return $new_values;
@@ -348,20 +252,15 @@
348 252 continue;
349 253 }
350 254 }
351 255
352 - // Updating the form.
256 + //updating the form
353 257 $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field );
354 - // Don't check for POST html.
355 - unset( $update_options['custom_html'] );
258 + unset( $update_options['custom_html'] ); // don't check for POST html
356 259 $update_options = apply_filters( 'frm_field_options_to_update', $update_options );
357 260
358 - if ( ! is_array( $field->field_options ) ) {
359 - $field->field_options = array();
360 - }
361 -
362 261 foreach ( $update_options as $opt => $default ) {
363 - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default;
262 + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
364 263 self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
365 264 }
366 265
367 266 $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
@@ -370,87 +269,28 @@
370 269 'field_options' => $field->field_options,
371 270 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '',
372 271 );
373 272
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 273 self::prepare_field_update_values( $field, $values, $new_field );
385 - self::maybe_update_max_option( $field, $values, $new_field );
386 274
387 275 FrmField::update( $field_id, $new_field );
388 276
389 277 FrmField::delete_form_transient( $field->form_id );
390 - }//end foreach
278 + }
391 279 self::clear_form_cache();
392 280
393 281 return $values;
394 282 }
395 283
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 284 private static function sanitize_field_opt( $opt, &$value ) {
427 - if ( ! is_string( $value ) ) {
428 - return;
285 + if ( is_string( $value ) ) {
286 + if ( $opt === 'calc' ) {
287 + $value = self::sanitize_calc( $value );
288 + } else {
289 + $value = FrmAppHelper::kses( $value, 'all' );
290 + }
291 + $value = trim( $value );
429 292 }
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 293 }
454 294
455 295 /**
456 296 * @param string $value
@@ -459,10 +299,9 @@
459 299 private static function sanitize_calc( $value ) {
460 300 if ( false !== strpos( $value, '<' ) ) {
461 301 $value = self::normalize_calc_spaces( $value );
462 302 }
463 - // Allow <= and >=.
464 - $allow = array( '<= ', ' >=' );
303 + $allow = array( '<= ', ' >=' ); // Allow <= and >=
465 304 $temp = array( '< = ', ' > =' );
466 305 $value = str_replace( $allow, $temp, $value );
467 306 $value = strip_tags( $value );
468 307 $value = str_replace( $temp, $allow, $value );
@@ -477,16 +316,14 @@
477 316 * @return string
478 317 */
479 318 private static function normalize_calc_spaces( $calc ) {
480 319 // Check for a pattern with 5 parts
481 - // $1 \d|\] the first comparison digit or the end of a comparison shortcode.
320 + // $1 \d the first comparison digit.
482 321 // $2 a space (optional).
483 322 // $3 an equals sign (optional) that follows the < operator for <= comparisons.
484 323 // $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;
324 + // $5 \d the second comparison digit.
325 + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc );
489 326 }
490 327
491 328 /**
492 329 * Updating the settings page
@@ -493,12 +330,12 @@
493 330 */
494 331 private static function get_settings_page_html( $values, &$field ) {
495 332 if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
496 333 $prev_opts = array();
497 - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type );
334 + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
498 335
499 - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html;
500 - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
336 + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
337 + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
501 338 $prev_opts = $field->field_options;
502 339 }
503 340
504 341 if ( isset( $prev_opts ) ) {
@@ -519,14 +356,11 @@
519 356 'options' => '',
520 357 'name' => '',
521 358 );
522 359 foreach ( $field_cols as $col => $default ) {
523 - $default = $default === '' ? $field->{$col} : $default;
524 - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default;
525 - }
360 + $default = ( $default === '' ) ? $field->{$col} : $default;
526 361
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;
362 + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
529 363 }
530 364
531 365 // Don't save the template option.
532 366 if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
@@ -538,9 +372,9 @@
538 372 * Get a list of all form settings that should be translated
539 373 * on a multilingual site.
540 374 *
541 375 * @since 3.06.01
542 - * @param object $form The form object.
376 + * @param object $form - The form object
543 377 */
544 378 public static function translatable_strings( $form ) {
545 379 $strings = array(
546 380 'name',
@@ -547,12 +381,8 @@
547 381 'description',
548 382 'submit_value',
549 383 'submit_msg',
550 384 'success_msg',
551 - 'invalid_msg',
552 - 'failed_msg',
553 - 'login_msg',
554 - 'admin_permission',
555 385 );
556 386
557 387 return apply_filters( 'frm_form_strings', $strings, $form );
558 388 }
@@ -557,12 +387,11 @@
557 387 return apply_filters( 'frm_form_strings', $strings, $form );
558 388 }
559 389
560 390 /**
561 - * @param int $id
562 391 * @param string $status
563 392 *
564 - * @return bool|int
393 + * @return int|boolean
565 394 */
566 395 public static function set_status( $id, $status ) {
567 396 if ( 'trash' == $status ) {
568 397 return self::trash( $id );
@@ -568,9 +397,9 @@
568 397 return self::trash( $id );
569 398 }
570 399
571 400 $statuses = array( 'published', 'draft', 'trash' );
572 - if ( ! in_array( $status, $statuses, true ) ) {
401 + if ( ! in_array( $status, $statuses ) ) {
573 402 return false;
574 403 }
575 404
576 405 global $wpdb;
@@ -597,9 +426,9 @@
597 426 return $query_results;
598 427 }
599 428
600 429 /**
601 - * @return bool|int
430 + * @return int|boolean
602 431 */
603 432 public static function trash( $id ) {
604 433 if ( ! EMPTY_TRASH_DAYS ) {
605 434 return self::destroy( $id );
@@ -609,12 +438,8 @@
609 438 if ( ! $form ) {
610 439 return false;
611 440 }
612 441
613 - if ( $form->status === 'trash' ) {
614 - return false;
615 - }
616 -
617 442 $options = $form->options;
618 443 $options['trash_time'] = time();
619 444
620 445 global $wpdb;
@@ -647,9 +472,9 @@
647 472 return $query_results;
648 473 }
649 474
650 475 /**
651 - * @return bool|int
476 + * @return int|boolean
652 477 */
653 478 public static function destroy( $id ) {
654 479 global $wpdb;
655 480
@@ -671,11 +496,8 @@
671 496
672 497 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
673 498 if ( $query_results ) {
674 499 // Delete all form actions linked to this form
675 - /**
676 - * @var FrmFormAction
677 - */
678 500 $action_control = FrmFormActionsController::get_form_actions( 'email' );
679 501 $action_control->destroy( $id, 'all' );
680 502
681 503 // Clear form caching
@@ -695,9 +517,9 @@
695 517 */
696 518 public static function scheduled_delete( $delete_timestamp = '' ) {
697 519 global $wpdb;
698 520
699 - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
521 + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
700 522
701 523 if ( ! $trash_forms ) {
702 524 return 0;
703 525 }
@@ -710,11 +532,9 @@
710 532 foreach ( $trash_forms as $form ) {
711 533 FrmAppHelper::unserialize_or_decode( $form->options );
712 534 if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
713 535 self::destroy( $form->id );
714 - if ( empty( $form->parent_form_id ) ) {
715 - ++$count;
716 - }
536 + $count ++;
717 537 }
718 538
719 539 unset( $form );
720 540 }
@@ -734,12 +554,10 @@
734 554 }
735 555
736 556 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
737 557 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
558 + $r = stripslashes( $r );
738 559
739 - // An empty form name can result in a null value.
740 - $r = is_null( $r ) ? '' : stripslashes( $r );
741 -
742 560 return $r;
743 561 }
744 562
745 563 /**
@@ -774,10 +592,11 @@
774 592
775 593 /**
776 594 * If $form is numeric, get the form object
777 595 *
596 + * @param object|int $form
597 + *
778 598 * @since 2.0.9
779 - * @param int|object $form
780 599 */
781 600 public static function maybe_get_form( &$form ) {
782 601 if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
783 602 $form = self::getOne( $form );
@@ -784,11 +603,9 @@
784 603 }
785 604 }
786 605
787 606 /**
788 - * @param int|string $id
789 - * @param false|int $blog_id
790 - * @return stdClass|null
607 + * @return object form
791 608 */
792 609 public static function getOne( $id, $blog_id = false ) {
793 610 global $wpdb;
794 611
@@ -803,9 +620,10 @@
803 620 if ( $cache ) {
804 621 if ( isset( $cache->options ) ) {
805 622 FrmAppHelper::unserialize_or_decode( $cache->options );
806 623 }
807 - return self::prepare_form_row_data( $cache );
624 +
625 + return wp_unslash( $cache );
808 626 }
809 627 }
810 628
811 629 if ( is_numeric( $id ) ) {
@@ -820,43 +638,17 @@
820 638 FrmDb::set_cache( $results->id, $results, 'frm_form' );
821 639 FrmAppHelper::unserialize_or_decode( $results->options );
822 640 }
823 641
824 - return self::prepare_form_row_data( $results );
642 + return apply_filters( 'frm_form_object', wp_unslash( $results ) );
825 643 }
826 644
827 645 /**
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
646 + * @return object|array of objects
834 647 */
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 648 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
857 649 if ( is_array( $where ) && ! empty( $where ) ) {
858 - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
650 + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
859 651 // don't get trashed templates
860 652 $where['status'] = array( null, '', 'published' );
861 653 }
862 654
@@ -863,9 +655,9 @@
863 655 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
864 656 } else {
865 657 global $wpdb;
866 658
867 - // The query has already been prepared if this is not an array.
659 + // the query has already been prepared if this is not an array
868 660 $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
869 661 $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
870 662 }
871 663
@@ -875,9 +667,9 @@
875 667 FrmAppHelper::unserialize_or_decode( $result->options );
876 668 }
877 669 }
878 670
879 - if ( $limit === ' LIMIT 1' || $limit == 1 ) {
671 + if ( $limit == ' LIMIT 1' || $limit == 1 ) {
880 672 // return the first form object if we are only getting one form
881 673 $results = reset( $results );
882 674 }
883 675
@@ -887,18 +679,14 @@
887 679 /**
888 680 * Get all published forms
889 681 *
890 682 * @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.
683 + * @return array of forms
896 684 */
897 685 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
898 686 $query['is_template'] = 0;
899 687 $query['status'] = array( null, '', 'published' );
900 - if ( $inc_children === 'exclude' ) {
688 + if ( $inc_children == 'exclude' ) {
901 689 $query['parent_form_id'] = array( null, 0 );
902 690 }
903 691
904 692 $forms = self::getAll( $query, 'name', $limit );
@@ -934,18 +722,18 @@
934 722
935 723 foreach ( $results as $row ) {
936 724 if ( 'trash' != $row->status ) {
937 725 if ( $row->is_template ) {
938 - ++$counts['template'];
726 + $counts['template'] ++;
939 727 } else {
940 - ++$counts['published'];
728 + $counts['published'] ++;
941 729 }
942 730 } else {
943 - ++$counts['trash'];
731 + $counts['trash'] ++;
944 732 }
945 733
946 734 if ( 'draft' == $row->status ) {
947 - ++$counts['draft'];
735 + $counts['draft'] ++;
948 736 }
949 737
950 738 unset( $row );
951 739 }
@@ -1011,11 +799,11 @@
1011 799 $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1012 800 }
1013 801
1014 802 if ( $form->id == $values['posted_form_id'] ) {
1015 - // If there are two forms on the same page, make sure not to submit both.
803 + //if there are two forms on the same page, make sure not to submit both
1016 804 foreach ( $default_values as $var => $default ) {
1017 - if ( $var === 'action' ) {
805 + if ( $var == 'action' ) {
1018 806 $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
1019 807 } else {
1020 808 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1021 809 }
@@ -1083,9 +871,9 @@
1083 871 return $values;
1084 872 }
1085 873
1086 874 public static function get_current_form_id( $default_form = 'none' ) {
1087 - if ( 'first' === $default_form ) {
875 + if ( 'first' == $default_form ) {
1088 876 $form = self::get_current_form();
1089 877 } else {
1090 878 $form = self::maybe_get_current_form();
1091 879 }
@@ -1096,9 +884,9 @@
1096 884
1097 885 public static function maybe_get_current_form( $form_id = 0 ) {
1098 886 global $frm_vars;
1099 887
1100 - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
888 + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
1101 889 return $frm_vars['current_form'];
1102 890 }
1103 891
1104 892 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
@@ -1145,9 +933,9 @@
1145 933 $global_load = true;
1146 934 $frm_vars['load_css'] = true;
1147 935 }
1148 936
1149 - return empty( $frm_vars['css_loaded'] ) && $global_load;
937 + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
1150 938 }
1151 939
1152 940 /**
1153 941 * @since 4.06.03
@@ -1162,21 +950,13 @@
1162 950 } else {
1163 951 $visible = true;
1164 952 }
1165 953
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 954 return $visible;
1175 955 }
1176 956
1177 957 public static function show_submit( $form ) {
1178 - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() );
958 + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
1179 959 $show = apply_filters( 'frm_show_submit_button', $show, $form );
1180 960
1181 961 return $show;
1182 962 }
@@ -1184,12 +964,12 @@
1184 964 /**
1185 965 * @since 2.3
1186 966 */
1187 967 public static function get_option( $atts ) {
1188 - $form = $atts['form'];
1189 - $default = $atts['default'] ?? '';
968 + $form = $atts['form'];
969 + $default = isset( $atts['default'] ) ? $atts['default'] : '';
1190 970
1191 - return $form->options[ $atts['option'] ] ?? $default;
971 + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default;
1192 972 }
1193 973
1194 974 /**
1195 975 * Get the link to edit this form.
@@ -1201,81 +981,23 @@
1201 981 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1202 982 }
1203 983
1204 984 /**
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).
985 + * @deprecated 3.0
1260 986 * @codeCoverageIgnore
1261 987 *
1262 988 * @param string $key
989 + *
1263 990 * @return int form id
1264 991 */
1265 992 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 );
993 + return FrmFormDeprecated::getIdByKey( $key );
1268 994 }
1269 995
1270 996 /**
1271 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
997 + * @deprecated 3.0
1272 998 * @codeCoverageIgnore
1273 - *
1274 - * @param int|string $id
1275 - * @return string
1276 999 */
1277 1000 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 );
1001 + return FrmFormDeprecated::getKeyById( $id );
1280 1002 }
1281 1003 }