PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +182 -449 6.306.0 View file →
@@ -6,10 +6,9 @@
6 6 class FrmForm {
7 7
8 8 /**
9 9 * @param array $values
10 - *
11 - * @return bool|int id on success or false on failure.
10 + * @return int|boolean id on success or false on failure
12 11 */
13 12 public static function create( $values ) {
14 13 global $wpdb;
15 14
@@ -16,24 +15,24 @@
16 15 $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
17 16
18 17 $new_values = array(
19 18 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
20 - 'name' => FrmAppHelper::truncate( $values['name'], 255, 1, '', true ),
19 + 'name' => $values['name'],
21 20 'description' => $values['description'],
22 - 'status' => $values['status'] ?? 'published',
23 - '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,
24 23 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
25 24 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
26 25 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
27 - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ),
26 + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
28 27 );
29 28
30 29 $options = isset( $values['options'] ) ? (array) $values['options'] : array();
31 30 FrmFormsHelper::fill_form_options( $options, $values );
32 31
33 - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' );
34 - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' );
35 - $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' );
36 35
37 36 /**
38 37 * Allows modifying form options before updating or creating.
39 38 *
@@ -60,9 +59,8 @@
60 59 /**
61 60 * @since 5.0.08
62 61 *
63 62 * @param array $options
64 - *
65 63 * @return array
66 64 */
67 65 private static function maybe_filter_form_options( $options ) {
68 66 if ( ! FrmAppHelper::allow_unfiltered_html() && ! empty( $options['submit_html'] ) ) {
@@ -71,22 +69,14 @@
71 69 return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) );
72 70 }
73 71
74 72 /**
75 - * Duplicate a form.
76 - *
77 - * @param int $id Form ID to duplicate.
78 - * @param bool $template Whether the duplicated form is a template.
79 - * @param bool $copy_keys Whether to copy the original form key.
80 - * @param false|int $blog_id Blog ID when duplicating across sites, or false for current site.
81 - *
82 - * @return bool|int ID on success or false on failure
73 + * @return int|boolean ID on success or false on failure
83 74 */
84 75 public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
85 76 global $wpdb;
86 77
87 78 $values = self::getOne( $id, $blog_id );
88 -
89 79 if ( ! $values ) {
90 80 return false;
91 81 }
92 82
@@ -103,10 +93,10 @@
103 93 'is_template' => $template ? 1 : 0,
104 94 );
105 95
106 96 if ( $blog_id ) {
107 - $new_values['status'] = 'published';
108 - $new_options = $values->options;
97 + $new_values['status'] = 'published';
98 + $new_options = $values->options;
109 99 FrmAppHelper::unserialize_or_decode( $new_options );
110 100 $new_options['email_to'] = get_option( 'admin_email' );
111 101 $new_options['copy'] = false;
112 102 $new_values['options'] = $new_options;
@@ -126,9 +116,9 @@
126 116
127 117 $form_id = $wpdb->insert_id;
128 118 FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
129 119
130 - // Update form settings after fields are created
120 + // update form settings after fields are created
131 121 do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
132 122
133 123 return $form_id;
134 124 }
@@ -135,16 +125,10 @@
135 125
136 126 return false;
137 127 }
138 128
139 - /**
140 - * @param int $form_id
141 - * @param array $values
142 - *
143 - * @return void
144 - */
145 129 public static function after_duplicate( $form_id, $values ) {
146 - $new_opts = $values['options'];
130 + $new_opts = $values['options'];
147 131 FrmAppHelper::unserialize_or_decode( $new_opts );
148 132 $values['options'] = $new_opts;
149 133
150 134 if ( isset( $new_opts['success_msg'] ) ) {
@@ -152,9 +136,8 @@
152 136 }
153 137
154 138 $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
155 139
156 - // phpcs:ignore Universal.Operators.StrictComparisons
157 140 if ( $new_opts != $values['options'] ) {
158 141 global $wpdb;
159 142 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
160 143 }
@@ -167,10 +150,8 @@
167 150 *
168 151 * @since 5.3
169 152 *
170 153 * @param int $form_id Form ID.
171 - *
172 - * @return void
173 154 */
174 155 private static function switch_field_ids_in_fields( $form_id ) {
175 156 global $wpdb;
176 157
@@ -176,11 +157,10 @@
176 157
177 158 // Keys of fields that you want to check to replace field ID.
178 159 $keys = array( 'default_value', 'field_options' );
179 160 $sql_cols = 'fi.id';
180 -
181 161 foreach ( $keys as $key ) {
182 - $sql_cols .= ',fi.' . $key;
162 + $sql_cols .= ( ',fi.' . $key );
183 163 }
184 164
185 165 $fields = FrmDb::get_results(
186 166 "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id",
@@ -206,14 +186,11 @@
206 186 *
207 187 * @since 5.3
208 188 *
209 189 * @param array $field Field array.
210 - *
211 - * @return void
212 190 */
213 191 private static function switch_field_ids_in_field( $field ) {
214 192 $new_values = array();
215 -
216 193 foreach ( $field as $key => $value ) {
217 194 if ( 'id' === $key || ! $value ) {
218 195 continue;
219 196 }
@@ -233,23 +210,17 @@
233 210
234 211 if ( $new_val !== $value ) {
235 212 $new_values[ $key ] = $new_val;
236 213 }
237 - }//end foreach
214 + }
238 215
239 - if ( $new_values ) {
216 + if ( ! empty( $new_values ) ) {
240 217 FrmField::update( $field['id'], $new_values );
241 218 }
242 219 }
243 220
244 221 /**
245 - * Update a form.
246 - *
247 - * @param int $id Form ID.
248 - * @param array $values Form values to update.
249 - * @param bool $create_link Whether this is being called from link creation.
250 - *
251 - * @return bool|int
222 + * @return int|boolean
252 223 */
253 224 public static function update( $id, $values, $create_link = false ) {
254 225 global $wpdb;
255 226
@@ -263,23 +234,23 @@
263 234 $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
264 235 }
265 236
266 237 $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
267 - $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) );
268 238
239 + $new_values = self::set_update_options( array(), $values, array( 'form_id' => $id ) );
240 +
269 241 foreach ( $values as $value_key => $value ) {
270 - if ( $value_key && in_array( $value_key, $form_fields, true ) ) {
271 - $new_values[ $value_key ] = 'name' === $value_key ? FrmAppHelper::truncate( $value, 255, 1, '', true ) : $value;
242 + if ( $value_key && in_array( $value_key, $form_fields ) ) {
243 + $new_values[ $value_key ] = $value;
272 244 }
273 245 }
274 246
275 - if ( ! empty( $values['new_status'] ) ) {
247 + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
276 248 $new_values['status'] = $values['new_status'];
277 249 }
278 250
279 - if ( $new_values ) {
251 + if ( ! empty( $new_values ) ) {
280 252 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
281 -
282 253 if ( $query_results ) {
283 254 self::clear_form_cache();
284 255 }
285 256 } else {
@@ -298,9 +269,8 @@
298 269 /**
299 270 * @param array $new_values
300 271 * @param array $values
301 272 * @param array $args
302 - *
303 273 * @return array
304 274 */
305 275 public static function set_update_options( $new_values, $values, $args = array() ) {
306 276 if ( ! isset( $values['options'] ) ) {
@@ -306,16 +276,21 @@
306 276 if ( ! isset( $values['options'] ) ) {
307 277 return $new_values;
308 278 }
309 279
310 - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array();
280 + $options = isset( $values['options'] ) ? (array) $values['options'] : array();
311 281 FrmFormsHelper::fill_form_options( $options, $values );
312 282
313 - $options['custom_style'] = $values['options']['custom_style'] ?? 0;
314 - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' );
315 - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' );
316 - $options['submit_html'] = isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
283 + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
284 + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
285 + $options['after_html'] = isset( $values['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' );
317 287
288 + if ( ! empty( $options['success_url'] ) && ! empty( $args['form_id'] ) ) {
289 + $options['success_url'] = FrmFormsHelper::maybe_add_sanitize_url_attr( $options['success_url'], (int) $args['form_id'] );
290 + $values['options']['success_url'] = $options['success_url'];
291 + }
292 +
318 293 /**
319 294 * Allows modifying form options before updating or creating.
320 295 *
321 296 * @since 5.4 Added the third param.
@@ -331,14 +306,11 @@
331 306 return $new_values;
332 307 }
333 308
334 309 /**
335 - * @param int $id Form ID.
336 - * @param array $values Form values array.
337 - *
338 310 * @return array
339 311 */
340 - public static function update_fields( $id, $values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
312 + public static function update_fields( $id, $values ) {
341 313
342 314 if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
343 315 return $values;
344 316 }
@@ -343,10 +315,9 @@
343 315 return $values;
344 316 }
345 317
346 318 $all_fields = FrmField::get_all_for_form( $id );
347 -
348 - if ( ! $all_fields ) {
319 + if ( empty( $all_fields ) ) {
349 320 return $values;
350 321 }
351 322
352 323 if ( ! isset( $values['item_meta'] ) ) {
@@ -354,28 +325,28 @@
354 325 }
355 326
356 327 $field_array = array();
357 328 $existing_keys = array_keys( $values['item_meta'] );
358 -
359 329 foreach ( $all_fields as $fid ) {
360 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict, SlevomatCodingStandard.Files.LineLength.LineTooLong
361 330 if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
362 331 $values['item_meta'][ $fid->id ] = '';
363 332 }
364 -
365 333 $field_array[ $fid->id ] = $fid;
366 334 }
367 335 unset( $all_fields );
368 336
369 337 foreach ( $values['item_meta'] as $field_id => $default_value ) {
370 - $field = $field_array[ $field_id ] ?? FrmField::getOne( $field_id );
338 + if ( isset( $field_array[ $field_id ] ) ) {
339 + $field = $field_array[ $field_id ];
340 + } else {
341 + $field = FrmField::getOne( $field_id );
342 + }
371 343
372 344 if ( ! $field ) {
373 345 continue;
374 346 }
375 347
376 - $is_settings_page = isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] );
377 -
348 + $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
378 349 if ( $is_settings_page ) {
379 350 self::get_settings_page_html( $values, $field );
380 351
381 352 if ( ! defined( 'WP_IMPORTING' ) ) {
@@ -382,20 +353,15 @@
382 353 continue;
383 354 }
384 355 }
385 356
386 - // Updating the form.
357 + //updating the form
387 358 $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field );
388 - // Don't check for POST html.
389 - unset( $update_options['custom_html'] );
359 + unset( $update_options['custom_html'] ); // don't check for POST html
390 360 $update_options = apply_filters( 'frm_field_options_to_update', $update_options );
391 361
392 - if ( ! is_array( $field->field_options ) ) {
393 - $field->field_options = array();
394 - }
395 -
396 362 foreach ( $update_options as $opt => $default ) {
397 - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default;
363 + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
398 364 self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
399 365 }
400 366
401 367 $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
@@ -404,27 +370,14 @@
404 370 'field_options' => $field->field_options,
405 371 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '',
406 372 );
407 373
408 - 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 - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) {
410 - if ( ! is_array( $option ) ) {
411 - continue;
412 - }
413 -
414 - foreach ( $option as $key => $item ) {
415 - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' );
416 - }
417 - }
418 - }
419 -
420 374 self::prepare_field_update_values( $field, $values, $new_field );
421 - self::maybe_update_max_option( $field, $values, $new_field );
422 375
423 376 FrmField::update( $field_id, $new_field );
424 377
425 378 FrmField::delete_form_transient( $field->form_id );
426 - }//end foreach
379 + }
427 380 self::clear_form_cache();
428 381
429 382 return $values;
430 383 }
@@ -429,38 +382,10 @@
429 382 return $values;
430 383 }
431 384
432 385 /**
433 - * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc.
434 - *
435 - * @since 6.7
436 - *
437 - * @param object $field
438 - * @param array $values
439 - * @param array $new_field
440 - *
441 - * @return void
442 - */
443 - private static function maybe_update_max_option( $field, $values, &$new_field ) {
444 - if ( $field->type !== 'textarea' ||
445 - empty( $values['field_options'][ 'type_' . $field->id ] ) ||
446 - ! in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) {
447 - return;
448 - }
449 -
450 - $new_field['field_options']['max'] = '';
451 -
452 - /**
453 - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads.
454 - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting.
455 - */
456 - $_POST['field_options'][ 'max_' . $field->id ] = '';
457 - }
458 -
459 - /**
460 386 * @param string $opt
461 387 * @param mixed $value
462 - *
463 388 * @return void
464 389 */
465 390 private static function sanitize_field_opt( $opt, &$value ) {
466 391 if ( ! is_string( $value ) ) {
@@ -481,27 +406,31 @@
481 406 if ( ! $should_sanitize ) {
482 407 return;
483 408 }
484 409
485 - $value = $opt === 'calc' ? self::sanitize_calc( $value ) : FrmAppHelper::kses( $value, 'all' );
410 + if ( $opt === 'calc' ) {
411 + $value = self::sanitize_calc( $value );
412 + } else {
413 + $value = FrmAppHelper::kses( $value, 'all' );
414 + }
415 +
486 416 $value = trim( $value );
487 417 }
488 418
489 419 /**
490 420 * @param string $value
491 - *
492 421 * @return string
493 422 */
494 423 private static function sanitize_calc( $value ) {
495 - if ( str_contains( $value, '<' ) ) {
424 + if ( false !== strpos( $value, '<' ) ) {
496 425 $value = self::normalize_calc_spaces( $value );
497 426 }
498 - // Allow <= and >=.
499 - $allow = array( '<= ', ' >=' );
427 + $allow = array( '<= ', ' >=' ); // Allow <= and >=
500 428 $temp = array( '< = ', ' > =' );
501 429 $value = str_replace( $allow, $temp, $value );
502 430 $value = strip_tags( $value );
503 - return str_replace( $temp, $allow, $value );
431 + $value = str_replace( $temp, $allow, $value );
432 + return $value;
504 433 }
505 434
506 435 /**
507 436 * Format a comparison like 5<10 to 5 < 10. Also works on 5< 10, 5 <10, 5<=10 variations.
@@ -507,58 +436,41 @@
507 436 * Format a comparison like 5<10 to 5 < 10. Also works on 5< 10, 5 <10, 5<=10 variations.
508 437 * This is to avoid an issue with unspaced calculations being recognized as HTML that gets removed when strip_tags is called.
509 438 *
510 439 * @param string $calc
511 - *
512 440 * @return string
513 441 */
514 442 private static function normalize_calc_spaces( $calc ) {
515 443 // Check for a pattern with 5 parts
516 - // $1 \d|\] the first comparison digit or the end of a comparison shortcode.
444 + // $1 \d the first comparison digit.
517 445 // $2 a space (optional).
518 446 // $3 an equals sign (optional) that follows the < operator for <= comparisons.
519 447 // $4 another space (optional).
520 - // $5 \d|\[ the second comparison digit or the start of a comparison shortcode.
521 - return preg_replace( '/(\d|\])( ){0,1}<(=){0,1}( ){0,1}(\d|\[)/', '$1 <$3 $5', $calc );
448 + // $5 \d the second comparison digit.
449 + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc );
522 450 }
523 451
524 452 /**
525 453 * Updating the settings page
526 - *
527 - * @param array $values Form values array.
528 - * @param object $field Field object, passed by reference.
529 - *
530 - * @return void
531 454 */
532 455 private static function get_settings_page_html( $values, &$field ) {
533 456 if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
534 457 $prev_opts = array();
535 - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type );
458 + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
536 459
537 - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html;
538 - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
460 + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
461 + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
539 462 $prev_opts = $field->field_options;
540 463 }
541 464
542 - if ( ! isset( $prev_opts ) ) {
543 - return;
465 + if ( isset( $prev_opts ) ) {
466 + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
467 + if ( $prev_opts != $field->field_options ) {
468 + FrmField::update( $field->id, array( 'field_options' => $field->field_options ) );
469 + }
544 470 }
545 -
546 - $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
547 -
548 - // phpcs:ignore Universal.Operators.StrictComparisons
549 - if ( $prev_opts != $field->field_options ) {
550 - FrmField::update( $field->id, array( 'field_options' => $field->field_options ) );
551 - }
552 471 }
553 472
554 - /**
555 - * @param object $field
556 - * @param array $values
557 - * @param array $new_field
558 - *
559 - * @return void
560 - */
561 473 private static function prepare_field_update_values( $field, $values, &$new_field ) {
562 474 $field_cols = array(
563 475 'field_order' => 0,
564 476 'field_key' => '',
@@ -567,16 +479,12 @@
567 479 'description' => '',
568 480 'options' => '',
569 481 'name' => '',
570 482 );
571 -
572 483 foreach ( $field_cols as $col => $default ) {
573 - $default = $default === '' ? $field->{$col} : $default;
574 - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default;
575 - }
484 + $default = ( $default === '' ) ? $field->{$col} : $default;
576 485
577 - if ( $field->type === 'submit' && isset( $new_field['field_order'] ) && (int) $new_field['field_order'] === FrmSubmitHelper::DEFAULT_ORDER ) {
578 - $new_field['field_order'] = $field->field_order;
486 + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
579 487 }
580 488
581 489 // Don't save the template option.
582 490 if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
@@ -588,12 +496,9 @@
588 496 * Get a list of all form settings that should be translated
589 497 * on a multilingual site.
590 498 *
591 499 * @since 3.06.01
592 - *
593 - * @param object $form The form object.
594 - *
595 - * @return array
500 + * @param object $form - The form object
596 501 */
597 502 public static function translatable_strings( $form ) {
598 503 $strings = array(
599 504 'name',
@@ -610,21 +515,19 @@
610 515 return apply_filters( 'frm_form_strings', $strings, $form );
611 516 }
612 517
613 518 /**
614 - * @param array|int $id
615 - * @param string $status
519 + * @param string $status
616 520 *
617 - * @return bool|int
521 + * @return int|boolean
618 522 */
619 523 public static function set_status( $id, $status ) {
620 - if ( 'trash' === $status ) {
524 + if ( 'trash' == $status ) {
621 525 return self::trash( $id );
622 526 }
623 527
624 528 $statuses = array( 'published', 'draft', 'trash' );
625 -
626 - if ( ! in_array( $status, $statuses, true ) ) {
529 + if ( ! in_array( $status, $statuses ) ) {
627 530 return false;
628 531 }
629 532
630 533 global $wpdb;
@@ -637,9 +540,9 @@
637 540 );
638 541 FrmDb::get_where_clause_and_values( $where );
639 542 array_unshift( $where['values'], $status );
640 543
641 - $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, SlevomatCodingStandard.Files.LineLength.LineTooLong
544 + $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
642 545 } else {
643 546 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
644 547 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
645 548 }
@@ -651,11 +554,9 @@
651 554 return $query_results;
652 555 }
653 556
654 557 /**
655 - * @param int|string $id Form ID.
656 - *
657 - * @return bool|int
558 + * @return int|boolean
658 559 */
659 560 public static function trash( $id ) {
660 561 if ( ! EMPTY_TRASH_DAYS ) {
661 562 return self::destroy( $id );
@@ -661,17 +562,12 @@
661 562 return self::destroy( $id );
662 563 }
663 564
664 565 $form = self::getOne( $id );
665 -
666 566 if ( ! $form ) {
667 567 return false;
668 568 }
669 569
670 - if ( $form->status === 'trash' ) {
671 - return false;
672 - }
673 -
674 570 $options = $form->options;
675 571 $options['trash_time'] = time();
676 572
677 573 global $wpdb;
@@ -704,26 +600,21 @@
704 600 return $query_results;
705 601 }
706 602
707 603 /**
708 - * @param int|string $id Form ID.
709 - *
710 - * @return bool|int
604 + * @return int|boolean
711 605 */
712 606 public static function destroy( $id ) {
713 607 global $wpdb;
714 608
715 609 $form = self::getOne( $id );
716 -
717 610 if ( ! $form ) {
718 611 return false;
719 612 }
720 -
721 613 $id = $form->id;
722 614
723 615 // Disconnect the entries from this form
724 - $entries = FrmDb::get_col( 'frm_items', array( 'form_id' => $id ) );
725 -
616 + $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
726 617 foreach ( $entries as $entry_id ) {
727 618 FrmEntry::destroy( $entry_id );
728 619 unset( $entry_id );
729 620 }
@@ -728,29 +619,23 @@
728 619 unset( $entry_id );
729 620 }
730 621
731 622 // Disconnect the fields from this form
732 - $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
623 + $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 ) );
733 624
734 625 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
626 + if ( $query_results ) {
627 + // Delete all form actions linked to this form
628 + $action_control = FrmFormActionsController::get_form_actions( 'email' );
629 + $action_control->destroy( $id, 'all' );
735 630
736 - if ( ! $query_results ) {
737 - return $query_results;
631 + // Clear form caching
632 + self::clear_form_cache();
633 +
634 + do_action( 'frm_destroy_form', $id );
635 + do_action( 'frm_destroy_form_' . $id );
738 636 }
739 637
740 - // Delete all form actions linked to this form
741 - /**
742 - * @var FrmFormAction
743 - */
744 - $action_control = FrmFormActionsController::get_form_actions( 'email' );
745 - $action_control->destroy( $id, 'all' );
746 -
747 - // Clear form caching
748 - self::clear_form_cache();
749 -
750 - do_action( 'frm_destroy_form', $id );
751 - do_action( 'frm_destroy_form_' . $id );
752 -
753 638 return $query_results;
754 639 }
755 640
756 641 /**
@@ -755,34 +640,29 @@
755 640
756 641 /**
757 642 * Delete trashed forms based on how long they have been trashed
758 643 *
759 - * @param int|string $delete_timestamp Timestamp cutoff for deletion.
760 - *
761 644 * @return int The number of forms deleted
762 645 */
763 646 public static function scheduled_delete( $delete_timestamp = '' ) {
764 - $trash_forms = FrmDb::get_results( 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
647 + global $wpdb;
765 648
649 + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
650 +
766 651 if ( ! $trash_forms ) {
767 652 return 0;
768 653 }
769 654
770 - if ( ! $delete_timestamp ) {
655 + if ( empty( $delete_timestamp ) ) {
771 656 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
772 657 }
773 658
774 659 $count = 0;
775 -
776 660 foreach ( $trash_forms as $form ) {
777 661 FrmAppHelper::unserialize_or_decode( $form->options );
778 -
779 662 if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
780 663 self::destroy( $form->id );
781 -
782 - if ( empty( $form->parent_form_id ) ) {
783 - ++$count;
784 - }
664 + $count ++;
785 665 }
786 666
787 667 unset( $form );
788 668 }
@@ -790,24 +670,23 @@
790 670 return $count;
791 671 }
792 672
793 673 /**
794 - * @param int|string $id Form ID or key.
795 - *
796 674 * @return string form name
797 675 */
798 676 public static function getName( $id ) {
799 677 $form = FrmDb::check_cache( $id, 'frm_form' );
678 + if ( $form ) {
679 + $r = stripslashes( $form->name );
800 680
801 - if ( $form ) {
802 - return stripslashes( $form->name );
681 + return $r;
803 682 }
804 683
805 684 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
806 685 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
686 + $r = stripslashes( $r );
807 687
808 - // An empty form name can result in a null value.
809 - return is_null( $r ) ? '' : stripslashes( $r );
688 + return $r;
810 689 }
811 690
812 691 /**
813 692 * @since 3.0
@@ -822,9 +701,9 @@
822 701
823 702 /**
824 703 * @since 3.0
825 704 *
826 - * @param int|string $id
705 + * @param int $id
827 706 *
828 707 * @return string form key
829 708 */
830 709 public static function get_key_by_id( $id ) {
@@ -829,57 +708,59 @@
829 708 */
830 709 public static function get_key_by_id( $id ) {
831 710 $id = (int) $id;
832 711 $cache = FrmDb::check_cache( $id, 'frm_form' );
833 -
834 712 if ( $cache ) {
835 713 return $cache->form_key;
836 714 }
837 715
838 - return FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
716 + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
717 +
718 + return $key;
839 719 }
840 720
841 721 /**
842 722 * If $form is numeric, get the form object
843 723 *
724 + * @param object|int $form
725 + *
844 726 * @since 2.0.9
845 - *
846 - * @param array|int|object $form
847 - *
848 - * @return void
849 727 */
850 728 public static function maybe_get_form( &$form ) {
851 - if ( ! is_object( $form ) && ! is_array( $form ) && $form ) {
729 + if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
852 730 $form = self::getOne( $form );
853 731 }
854 732 }
855 733
856 734 /**
857 - * @param int|string $id
858 - * @param false|int $blog_id
859 - *
860 - * @return stdClass|null
735 + * @return object form
861 736 */
862 737 public static function getOne( $id, $blog_id = false ) {
863 738 global $wpdb;
864 739
865 740 if ( $blog_id && is_multisite() ) {
866 - $prefix = $wpdb->get_blog_prefix( $blog_id );
741 + global $wpmuBaseTablePrefix;
742 + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
743 +
867 744 $table_name = $prefix . 'frm_forms';
868 745 } else {
869 746 $table_name = $wpdb->prefix . 'frm_forms';
870 747 $cache = wp_cache_get( $id, 'frm_form' );
871 -
872 748 if ( $cache ) {
873 749 if ( isset( $cache->options ) ) {
874 750 FrmAppHelper::unserialize_or_decode( $cache->options );
875 751 }
876 752
877 - return self::prepare_form_row_data( $cache );
753 + return apply_filters( 'frm_form_object', wp_unslash( $cache ) );
878 754 }
879 755 }
880 756
881 - $where = is_numeric( $id ) ? array( 'id' => $id ) : array( 'form_key' => $id );
757 + if ( is_numeric( $id ) ) {
758 + $where = array( 'id' => $id );
759 + } else {
760 + $where = array( 'form_key' => $id );
761 + }
762 +
882 763 $results = FrmDb::get_row( $table_name, $where );
883 764
884 765 if ( isset( $results->options ) ) {
885 766 FrmDb::set_cache( $results->id, $results, 'frm_form' );
@@ -885,50 +766,18 @@
885 766 FrmDb::set_cache( $results->id, $results, 'frm_form' );
886 767 FrmAppHelper::unserialize_or_decode( $results->options );
887 768 }
888 769
889 - return self::prepare_form_row_data( $results );
770 + return apply_filters( 'frm_form_object', wp_unslash( $results ) );
890 771 }
891 772
892 773 /**
893 - * Make sure that if $row is an object, that $row->options is an array and not a string.
894 - *
895 - * @since 6.8.3
896 - *
897 - * @param stdClass|null $row The database row for a target form.
898 - *
899 - * @return stdClass|null
774 + * @return object|array of objects
900 775 */
901 - private static function prepare_form_row_data( $row ) {
902 - $row = wp_unslash( $row );
903 -
904 - if ( ! is_object( $row ) ) {
905 - return $row;
906 - }
907 -
908 - if ( ! is_array( $row->options ) ) {
909 - $row->options = FrmFormsHelper::get_default_opts();
910 - }
911 -
912 - /**
913 - * @since 4.03.02
914 - *
915 - * @param stdClass $row
916 - */
917 - return apply_filters( 'frm_form_object', $row );
918 - }
919 -
920 - /**
921 - * @param array|string $where Where conditions array or raw WHERE string.
922 - * @param string $order_by Order by clause.
923 - * @param int|string $limit Limit clause or number.
924 - *
925 - * @return array|object Array of objects. If $limit is 1, a single object is returned.
926 - */
927 776 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
928 - if ( is_array( $where ) && $where ) {
929 - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
930 - // Don't get trashed templates
777 + if ( is_array( $where ) && ! empty( $where ) ) {
778 + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
779 + // don't get trashed templates
931 780 $where['status'] = array( null, '', 'published' );
932 781 }
933 782
934 783 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
@@ -934,10 +783,10 @@
934 783 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
935 784 } else {
936 785 global $wpdb;
937 786
938 - // The query has already been prepared if this is not an array.
939 - $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
787 + // the query has already been prepared if this is not an array
788 + $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
940 789 $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
941 790 }
942 791
943 792 if ( $results ) {
@@ -946,10 +795,10 @@
946 795 FrmAppHelper::unserialize_or_decode( $result->options );
947 796 }
948 797 }
949 798
950 - if ( $limit === ' LIMIT 1' || (int) $limit === 1 ) {
951 - // Return the first form object if we are only getting one form
799 + if ( $limit == ' LIMIT 1' || $limit == 1 ) {
800 + // return the first form object if we are only getting one form
952 801 $results = reset( $results );
953 802 }
954 803
955 804 return wp_unslash( $results );
@@ -958,24 +807,20 @@
958 807 /**
959 808 * Get all published forms
960 809 *
961 810 * @since 2.0
962 - *
963 - * @param array $query
964 - * @param int $limit
965 - * @param string $inc_children
966 - *
967 - * @return array|object Array of forms. A single form object is returned if $limit is set to 1.
811 + * @return array of forms
968 812 */
969 813 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
970 814 $query['is_template'] = 0;
971 815 $query['status'] = array( null, '', 'published' );
972 -
973 - if ( $inc_children === 'exclude' ) {
816 + if ( $inc_children == 'exclude' ) {
974 817 $query['parent_form_id'] = array( null, 0 );
975 818 }
976 819
977 - return self::getAll( $query, 'name', $limit );
820 + $forms = self::getAll( $query, 'name', $limit );
821 +
822 + return $forms;
978 823 }
979 824
980 825 /**
981 826 * @return object count of forms
@@ -980,16 +825,18 @@
980 825 /**
981 826 * @return object count of forms
982 827 */
983 828 public static function get_count() {
829 + global $wpdb;
830 +
984 831 $cache_key = 'frm_form_counts';
985 - $counts = wp_cache_get( $cache_key, 'frm_form' );
986 832
833 + $counts = wp_cache_get( $cache_key, 'frm_form' );
987 834 if ( false !== $counts ) {
988 835 return $counts;
989 836 }
990 837
991 - $results = FrmDb::get_results(
838 + $results = (array) FrmDb::get_results(
992 839 'frm_forms',
993 840 array(
994 841 'or' => 1,
995 842 'parent_form_id' => null,
@@ -1001,18 +848,20 @@
1001 848 $statuses = array( 'published', 'draft', 'template', 'trash' );
1002 849 $counts = array_fill_keys( $statuses, 0 );
1003 850
1004 851 foreach ( $results as $row ) {
1005 - if ( 'trash' === $row->status ) {
1006 - ++$counts['trash'];
1007 - } elseif ( $row->is_template ) {
1008 - ++$counts['template'];
852 + if ( 'trash' != $row->status ) {
853 + if ( $row->is_template ) {
854 + $counts['template'] ++;
855 + } else {
856 + $counts['published'] ++;
857 + }
1009 858 } else {
1010 - ++$counts['published'];
859 + $counts['trash'] ++;
1011 860 }
1012 861
1013 - if ( 'draft' === $row->status ) {
1014 - ++$counts['draft'];
862 + if ( 'draft' == $row->status ) {
863 + $counts['draft'] ++;
1015 864 }
1016 865
1017 866 unset( $row );
1018 867 }
@@ -1028,10 +877,8 @@
1028 877 * Called when a form is created, updated, duplicated, or deleted
1029 878 * or when the form status is changed
1030 879 *
1031 880 * @since 2.0.4
1032 - *
1033 - * @return void
1034 881 */
1035 882 public static function clear_form_cache() {
1036 883 FrmDb::cache_delete_group( 'frm_form' );
1037 884 }
@@ -1036,29 +883,23 @@
1036 883 FrmDb::cache_delete_group( 'frm_form' );
1037 884 }
1038 885
1039 886 /**
1040 - * @param array $values Form values to validate.
1041 - *
1042 887 * @return array of errors
1043 888 */
1044 889 public static function validate( $values ) {
1045 890 $errors = array();
891 +
1046 892 return apply_filters( 'frm_validate_form', $errors, $values );
1047 893 }
1048 894
1049 - /**
1050 - * @param object|null $form
1051 - *
1052 - * @return array
1053 - */
1054 895 public static function get_params( $form = null ) {
1055 896 global $frm_vars;
1056 897
1057 - if ( $form ) {
898 + if ( ! $form ) {
899 + $form = self::getAll( array(), 'name', 1 );
900 + } else {
1058 901 self::maybe_get_form( $form );
1059 - } else {
1060 - $form = self::getAll( array(), 'name', 1 );
1061 902 }
1062 903
1063 904 if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
1064 905 return $frm_vars['form_params'][ $form->id ];
@@ -1081,18 +922,16 @@
1081 922 );
1082 923
1083 924 $values = array();
1084 925 $values['posted_form_id'] = FrmAppHelper::get_param( 'form_id', '', 'get', 'absint' );
1085 -
1086 926 if ( ! $values['posted_form_id'] ) {
1087 927 $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1088 928 }
1089 929
1090 - // phpcs:ignore Universal.Operators.StrictComparisons
1091 930 if ( $form->id == $values['posted_form_id'] ) {
1092 - // If there are two forms on the same page, make sure not to submit both.
931 + //if there are two forms on the same page, make sure not to submit both
1093 932 foreach ( $default_values as $var => $default ) {
1094 - if ( $var === 'action' ) {
933 + if ( $var == 'action' ) {
1095 934 $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
1096 935 } else {
1097 936 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1098 937 }
@@ -1104,9 +943,9 @@
1104 943 unset( $var, $default );
1105 944 }
1106 945 }
1107 946
1108 - if ( in_array( $values['action'], array( 'create', 'update' ), true ) &&
947 + if ( in_array( $values['action'], array( 'create', 'update' ) ) &&
1109 948 ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
1110 949 ) {
1111 950 $values['action'] = 'new';
1112 951 }
@@ -1113,11 +952,8 @@
1113 952
1114 953 return $values;
1115 954 }
1116 955
1117 - /**
1118 - * @return array
1119 - */
1120 956 public static function list_page_params() {
1121 957 $values = array();
1122 958 $defaults = array(
1123 959 'template' => 0,
@@ -1127,9 +963,8 @@
1127 963 'search' => '',
1128 964 'sort' => '',
1129 965 'sdir' => '',
1130 966 );
1131 -
1132 967 foreach ( $defaults as $var => $default ) {
1133 968 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1134 969 }
1135 970
@@ -1135,16 +970,10 @@
1135 970
1136 971 return $values;
1137 972 }
1138 973
1139 - /**
1140 - * @param int|object|string|null $form
1141 - *
1142 - * @return array
1143 - */
1144 974 public static function get_admin_params( $form = null ) {
1145 975 $form_id = $form;
1146 -
1147 976 if ( $form === null ) {
1148 977 $form_id = self::get_current_form_id();
1149 978 } elseif ( $form && is_object( $form ) ) {
1150 979 $form_id = $form->id;
@@ -1162,9 +991,8 @@
1162 991 'sdir' => '',
1163 992 'fid' => '',
1164 993 'keep_post' => '',
1165 994 );
1166 -
1167 995 foreach ( $defaults as $var => $default ) {
1168 996 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1169 997 }
1170 998
@@ -1170,55 +998,47 @@
1170 998
1171 999 return $values;
1172 1000 }
1173 1001
1174 - /**
1175 - * @param string $default_form
1176 - *
1177 - * @return int|string
1178 - */
1179 1002 public static function get_current_form_id( $default_form = 'none' ) {
1180 - $form = 'first' === $default_form ? self::get_current_form() : self::maybe_get_current_form();
1181 - return $form ? $form->id : 0;
1003 + if ( 'first' == $default_form ) {
1004 + $form = self::get_current_form();
1005 + } else {
1006 + $form = self::maybe_get_current_form();
1007 + }
1008 + $form_id = $form ? $form->id : 0;
1009 +
1010 + return $form_id;
1182 1011 }
1183 1012
1184 - /**
1185 - * @param int|string $form_id
1186 - *
1187 - * @return false|int|object|string
1188 - */
1189 1013 public static function maybe_get_current_form( $form_id = 0 ) {
1190 1014 global $frm_vars;
1191 1015
1192 - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || (int) $form_id === (int) $frm_vars['current_form']->id ) ) {
1016 + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
1193 1017 return $frm_vars['current_form'];
1194 1018 }
1195 1019
1196 1020 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
1021 + if ( $form_id ) {
1022 + $form_id = self::set_current_form( $form_id );
1023 + }
1197 1024
1198 - return $form_id ? self::set_current_form( $form_id ) : $form_id;
1025 + return $form_id;
1199 1026 }
1200 1027
1201 - /**
1202 - * @param int $form_id
1203 - *
1204 - * @return false|object
1205 - */
1206 1028 public static function get_current_form( $form_id = 0 ) {
1207 1029 $form = self::maybe_get_current_form( $form_id );
1208 - return is_numeric( $form ) ? self::set_current_form( $form ) : $form;
1030 + if ( is_numeric( $form ) ) {
1031 + $form = self::set_current_form( $form );
1032 + }
1033 +
1034 + return $form;
1209 1035 }
1210 1036
1211 - /**
1212 - * @param int $form_id
1213 - *
1214 - * @return false|object
1215 - */
1216 1037 public static function set_current_form( $form_id ) {
1217 1038 global $frm_vars;
1218 1039
1219 1040 $query = array();
1220 -
1221 1041 if ( $form_id ) {
1222 1042 $query['id'] = $form_id;
1223 1043 }
1224 1044
@@ -1226,19 +1046,11 @@
1226 1046
1227 1047 return $frm_vars['current_form'];
1228 1048 }
1229 1049
1230 - /**
1231 - * @param object $form
1232 - * @param int|string $this_load
1233 - * @param bool $global_load
1234 - *
1235 - * @return bool
1236 - */
1237 1050 public static function is_form_loaded( $form, $this_load, $global_load ) {
1238 1051 global $frm_vars;
1239 1052 $small_form = new stdClass();
1240 -
1241 1053 foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
1242 1054 $small_form->{$var} = $form->{$var};
1243 1055 unset( $var );
1244 1056 }
@@ -1244,14 +1056,14 @@
1244 1056 }
1245 1057
1246 1058 $frm_vars['forms_loaded'][] = $small_form;
1247 1059
1248 - if ( $this_load && ! $global_load ) {
1060 + if ( $this_load && empty( $global_load ) ) {
1249 1061 $global_load = true;
1250 1062 $frm_vars['load_css'] = true;
1251 1063 }
1252 1064
1253 - return empty( $frm_vars['css_loaded'] ) && $global_load;
1065 + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
1254 1066 }
1255 1067
1256 1068 /**
1257 1069 * @since 4.06.03
@@ -1259,9 +1071,9 @@
1259 1071 * @param object $form
1260 1072 *
1261 1073 * @return bool
1262 1074 */
1263 - public static function is_visible_to_user( $form ) {
1075 + public static function &is_visible_to_user( $form ) {
1264 1076 if ( $form->logged_in && isset( $form->options['logged_in_role'] ) ) {
1265 1077 $visible = FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1266 1078 } else {
1267 1079 $visible = true;
@@ -1266,39 +1078,26 @@
1266 1078 } else {
1267 1079 $visible = true;
1268 1080 }
1269 1081
1270 - /**
1271 - * @since 6.25
1272 - *
1273 - * @param bool $visible
1274 - * @param object $form
1275 - */
1276 - return (bool) apply_filters( 'frm_form_is_visible', $visible, $form );
1082 + return $visible;
1277 1083 }
1278 1084
1279 - /**
1280 - * @param object $form
1281 - *
1282 - * @return bool
1283 - */
1284 1085 public static function show_submit( $form ) {
1285 - $show = ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin();
1286 - return apply_filters( 'frm_show_submit_button', $show, $form );
1086 + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
1087 + $show = apply_filters( 'frm_show_submit_button', $show, $form );
1088 +
1089 + return $show;
1287 1090 }
1288 1091
1289 1092 /**
1290 1093 * @since 2.3
1291 - *
1292 - * @param array $atts Attributes including form, option, and default.
1293 - *
1294 - * @return mixed
1295 1094 */
1296 1095 public static function get_option( $atts ) {
1297 - $form = $atts['form'];
1298 - $default = $atts['default'] ?? '';
1096 + $form = $atts['form'];
1097 + $default = isset( $atts['default'] ) ? $atts['default'] : '';
1299 1098
1300 - return $form->options[ $atts['option'] ] ?? $default;
1099 + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default;
1301 1100 }
1302 1101
1303 1102 /**
1304 1103 * Get the link to edit this form.
@@ -1303,12 +1102,9 @@
1303 1102 /**
1304 1103 * Get the link to edit this form.
1305 1104 *
1306 1105 * @since 4.0
1307 - *
1308 1106 * @param int $form_id The id of the form.
1309 - *
1310 - * @return string
1311 1107 */
1312 1108 public static function get_edit_link( $form_id ) {
1313 1109 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1314 1110 }
@@ -1313,65 +1109,9 @@
1313 1109 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1314 1110 }
1315 1111
1316 1112 /**
1317 - * Check if the "Submit this form with AJAX" setting is toggled on.
1318 - *
1319 - * @since 6.2
1320 - *
1321 - * @param stdClass $form
1322 - *
1323 - * @return bool
1324 - */
1325 - public static function is_ajax_on( $form ) {
1326 - return ! empty( $form->options['ajax_submit'] );
1327 - }
1328 -
1329 - /**
1330 - * Get the latest form available.
1331 - *
1332 - * @since 6.8
1333 - *
1334 - * @return object
1335 - */
1336 - public static function get_latest_form() {
1337 - $args = array(
1338 - array(
1339 - 'or' => 1,
1340 - 'parent_form_id' => null,
1341 - 'parent_form_id <' => 1,
1342 - ),
1343 - 'is_template' => 0,
1344 - 'status !' => 'trash',
1345 - );
1346 -
1347 - return self::getAll( $args, 'created_at desc', 1 );
1348 - }
1349 -
1350 - /**
1351 - * Count and return total forms.
1352 - *
1353 - * @since 6.8
1354 - *
1355 - * @return int
1356 - */
1357 - public static function get_forms_count() {
1358 - $args = array(
1359 - array(
1360 - 'or' => 1,
1361 - 'parent_form_id' => null,
1362 - 'parent_form_id <' => 1,
1363 - ),
1364 - 'is_template' => 0,
1365 - 'status !' => 'trash',
1366 - );
1367 -
1368 - return FrmDb::get_count( 'frm_forms', $args );
1369 - }
1370 -
1371 - /**
1372 - * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations).
1373 - *
1113 + * @deprecated 3.0
1374 1114 * @codeCoverageIgnore
1375 1115 *
1376 1116 * @param string $key
1377 1117 *
@@ -1377,22 +1117,15 @@
1377 1117 *
1378 1118 * @return int form id
1379 1119 */
1380 1120 public static function getIdByKey( $key ) {
1381 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' );
1382 - return self::get_id_by_key( $key );
1121 + return FrmFormDeprecated::getIdByKey( $key );
1383 1122 }
1384 1123
1385 1124 /**
1386 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
1387 - *
1125 + * @deprecated 3.0
1388 1126 * @codeCoverageIgnore
1389 - *
1390 - * @param int|string $id
1391 - *
1392 - * @return string
1393 1127 */
1394 1128 public static function getKeyById( $id ) {
1395 - _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' );
1396 - return self::get_key_by_id( $id );
1129 + return FrmFormDeprecated::getKeyById( $id );
1397 1130 }
1398 1131 }