PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 +88 -383 6.255.0 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,87 +252,28 @@
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 + $value = self::sanitize_calc( $value );
271 + } else {
272 + $value = FrmAppHelper::kses( $value, 'all' );
273 + }
274 + $value = trim( $value );
429 275 }
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 276 }
454 277
455 278 /**
456 279 * @param string $value
@@ -459,10 +282,9 @@
459 282 private static function sanitize_calc( $value ) {
460 283 if ( false !== strpos( $value, '<' ) ) {
461 284 $value = self::normalize_calc_spaces( $value );
462 285 }
463 - // Allow <= and >=.
464 - $allow = array( '<= ', ' >=' );
286 + $allow = array( '<= ', ' >=' ); // Allow <= and >=
465 287 $temp = array( '< = ', ' > =' );
466 288 $value = str_replace( $allow, $temp, $value );
467 289 $value = strip_tags( $value );
468 290 $value = str_replace( $temp, $allow, $value );
@@ -477,16 +299,14 @@
477 299 * @return string
478 300 */
479 301 private static function normalize_calc_spaces( $calc ) {
480 302 // Check for a pattern with 5 parts
481 - // $1 \d|\] the first comparison digit or the end of a comparison shortcode.
303 + // $1 \d the first comparison digit.
482 304 // $2 a space (optional).
483 305 // $3 an equals sign (optional) that follows the < operator for <= comparisons.
484 306 // $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;
307 + // $5 \d the second comparison digit.
308 + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc );
489 309 }
490 310
491 311 /**
492 312 * Updating the settings page
@@ -493,12 +313,12 @@
493 313 */
494 314 private static function get_settings_page_html( $values, &$field ) {
495 315 if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
496 316 $prev_opts = array();
497 - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type );
317 + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
498 318
499 - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html;
500 - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) {
319 + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
320 + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
501 321 $prev_opts = $field->field_options;
502 322 }
503 323
504 324 if ( isset( $prev_opts ) ) {
@@ -519,14 +339,11 @@
519 339 'options' => '',
520 340 'name' => '',
521 341 );
522 342 foreach ( $field_cols as $col => $default ) {
523 - $default = $default === '' ? $field->{$col} : $default;
524 - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default;
525 - }
343 + $default = ( $default === '' ) ? $field->{$col} : $default;
526 344
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;
345 + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
529 346 }
530 347
531 348 // Don't save the template option.
532 349 if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
@@ -538,9 +355,9 @@
538 355 * Get a list of all form settings that should be translated
539 356 * on a multilingual site.
540 357 *
541 358 * @since 3.06.01
542 - * @param object $form The form object.
359 + * @param object $form - The form object
543 360 */
544 361 public static function translatable_strings( $form ) {
545 362 $strings = array(
546 363 'name',
@@ -547,12 +364,8 @@
547 364 'description',
548 365 'submit_value',
549 366 'submit_msg',
550 367 'success_msg',
551 - 'invalid_msg',
552 - 'failed_msg',
553 - 'login_msg',
554 - 'admin_permission',
555 368 );
556 369
557 370 return apply_filters( 'frm_form_strings', $strings, $form );
558 371 }
@@ -557,12 +370,11 @@
557 370 return apply_filters( 'frm_form_strings', $strings, $form );
558 371 }
559 372
560 373 /**
561 - * @param int $id
562 374 * @param string $status
563 375 *
564 - * @return bool|int
376 + * @return int|boolean
565 377 */
566 378 public static function set_status( $id, $status ) {
567 379 if ( 'trash' == $status ) {
568 380 return self::trash( $id );
@@ -568,9 +380,9 @@
568 380 return self::trash( $id );
569 381 }
570 382
571 383 $statuses = array( 'published', 'draft', 'trash' );
572 - if ( ! in_array( $status, $statuses, true ) ) {
384 + if ( ! in_array( $status, $statuses ) ) {
573 385 return false;
574 386 }
575 387
576 388 global $wpdb;
@@ -583,9 +395,9 @@
583 395 );
584 396 FrmDb::get_where_clause_and_values( $where );
585 397 array_unshift( $where['values'], $status );
586 398
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
399 + $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
588 400 } else {
589 401 $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
590 402 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
591 403 }
@@ -597,9 +409,9 @@
597 409 return $query_results;
598 410 }
599 411
600 412 /**
601 - * @return bool|int
413 + * @return int|boolean
602 414 */
603 415 public static function trash( $id ) {
604 416 if ( ! EMPTY_TRASH_DAYS ) {
605 417 return self::destroy( $id );
@@ -609,12 +421,8 @@
609 421 if ( ! $form ) {
610 422 return false;
611 423 }
612 424
613 - if ( $form->status === 'trash' ) {
614 - return false;
615 - }
616 -
617 425 $options = $form->options;
618 426 $options['trash_time'] = time();
619 427
620 428 global $wpdb;
@@ -647,9 +455,9 @@
647 455 return $query_results;
648 456 }
649 457
650 458 /**
651 - * @return bool|int
459 + * @return int|boolean
652 460 */
653 461 public static function destroy( $id ) {
654 462 global $wpdb;
655 463
@@ -671,11 +479,8 @@
671 479
672 480 $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
673 481 if ( $query_results ) {
674 482 // Delete all form actions linked to this form
675 - /**
676 - * @var FrmFormAction
677 - */
678 483 $action_control = FrmFormActionsController::get_form_actions( 'email' );
679 484 $action_control->destroy( $id, 'all' );
680 485
681 486 // Clear form caching
@@ -695,12 +500,12 @@
695 500 */
696 501 public static function scheduled_delete( $delete_timestamp = '' ) {
697 502 global $wpdb;
698 503
699 - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' );
504 + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
700 505
701 506 if ( ! $trash_forms ) {
702 - return 0;
507 + return;
703 508 }
704 509
705 510 if ( empty( $delete_timestamp ) ) {
706 511 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
@@ -710,11 +515,9 @@
710 515 foreach ( $trash_forms as $form ) {
711 516 FrmAppHelper::unserialize_or_decode( $form->options );
712 517 if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
713 518 self::destroy( $form->id );
714 - if ( empty( $form->parent_form_id ) ) {
715 - ++$count;
716 - }
519 + $count ++;
717 520 }
718 521
719 522 unset( $form );
720 523 }
@@ -734,12 +537,10 @@
734 537 }
735 538
736 539 $query_key = is_numeric( $id ) ? 'id' : 'form_key';
737 540 $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
541 + $r = stripslashes( $r );
738 542
739 - // An empty form name can result in a null value.
740 - $r = is_null( $r ) ? '' : stripslashes( $r );
741 -
742 543 return $r;
743 544 }
744 545
745 546 /**
@@ -774,10 +575,11 @@
774 575
775 576 /**
776 577 * If $form is numeric, get the form object
777 578 *
579 + * @param object|int $form
580 + *
778 581 * @since 2.0.9
779 - * @param int|object $form
780 582 */
781 583 public static function maybe_get_form( &$form ) {
782 584 if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
783 585 $form = self::getOne( $form );
@@ -784,11 +586,9 @@
784 586 }
785 587 }
786 588
787 589 /**
788 - * @param int|string $id
789 - * @param false|int $blog_id
790 - * @return stdClass|null
590 + * @return object form
791 591 */
792 592 public static function getOne( $id, $blog_id = false ) {
793 593 global $wpdb;
794 594
@@ -803,9 +603,10 @@
803 603 if ( $cache ) {
804 604 if ( isset( $cache->options ) ) {
805 605 FrmAppHelper::unserialize_or_decode( $cache->options );
806 606 }
807 - return self::prepare_form_row_data( $cache );
607 +
608 + return wp_unslash( $cache );
808 609 }
809 610 }
810 611
811 612 if ( is_numeric( $id ) ) {
@@ -820,43 +621,17 @@
820 621 FrmDb::set_cache( $results->id, $results, 'frm_form' );
821 622 FrmAppHelper::unserialize_or_decode( $results->options );
822 623 }
823 624
824 - return self::prepare_form_row_data( $results );
625 + return apply_filters( 'frm_form_object', wp_unslash( $results ) );
825 626 }
826 627
827 628 /**
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
629 + * @return object|array of objects
834 630 */
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 631 public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
857 632 if ( is_array( $where ) && ! empty( $where ) ) {
858 - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
633 + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
859 634 // don't get trashed templates
860 635 $where['status'] = array( null, '', 'published' );
861 636 }
862 637
@@ -863,11 +638,11 @@
863 638 $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) );
864 639 } else {
865 640 global $wpdb;
866 641
867 - // The query has already been prepared if this is not an array.
642 + // the query has already been prepared if this is not an array
868 643 $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
644 + $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok.
870 645 }
871 646
872 647 if ( $results ) {
873 648 foreach ( $results as $result ) {
@@ -875,9 +650,9 @@
875 650 FrmAppHelper::unserialize_or_decode( $result->options );
876 651 }
877 652 }
878 653
879 - if ( $limit === ' LIMIT 1' || $limit == 1 ) {
654 + if ( $limit == ' LIMIT 1' || $limit == 1 ) {
880 655 // return the first form object if we are only getting one form
881 656 $results = reset( $results );
882 657 }
883 658
@@ -887,18 +662,14 @@
887 662 /**
888 663 * Get all published forms
889 664 *
890 665 * @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.
666 + * @return array of forms
896 667 */
897 668 public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
898 669 $query['is_template'] = 0;
899 670 $query['status'] = array( null, '', 'published' );
900 - if ( $inc_children === 'exclude' ) {
671 + if ( $inc_children == 'exclude' ) {
901 672 $query['parent_form_id'] = array( null, 0 );
902 673 }
903 674
904 675 $forms = self::getAll( $query, 'name', $limit );
@@ -934,18 +705,18 @@
934 705
935 706 foreach ( $results as $row ) {
936 707 if ( 'trash' != $row->status ) {
937 708 if ( $row->is_template ) {
938 - ++$counts['template'];
709 + $counts['template'] ++;
939 710 } else {
940 - ++$counts['published'];
711 + $counts['published'] ++;
941 712 }
942 713 } else {
943 - ++$counts['trash'];
714 + $counts['trash'] ++;
944 715 }
945 716
946 717 if ( 'draft' == $row->status ) {
947 - ++$counts['draft'];
718 + $counts['draft'] ++;
948 719 }
949 720
950 721 unset( $row );
951 722 }
@@ -988,9 +759,9 @@
988 759 if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
989 760 return $frm_vars['form_params'][ $form->id ];
990 761 }
991 762
992 - $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
763 + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok.
993 764 $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
994 765
995 766 $default_values = array(
996 767 'id' => '',
@@ -1011,11 +782,11 @@
1011 782 $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1012 783 }
1013 784
1014 785 if ( $form->id == $values['posted_form_id'] ) {
1015 - // If there are two forms on the same page, make sure not to submit both.
786 + //if there are two forms on the same page, make sure not to submit both
1016 787 foreach ( $default_values as $var => $default ) {
1017 - if ( $var === 'action' ) {
788 + if ( $var == 'action' ) {
1018 789 $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
1019 790 } else {
1020 791 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
1021 792 }
@@ -1028,9 +799,9 @@
1028 799 }
1029 800 }
1030 801
1031 802 if ( in_array( $values['action'], array( 'create', 'update' ) ) &&
1032 - ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
803 + ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // WPCS: CSRF ok.
1033 804 ) {
1034 805 $values['action'] = 'new';
1035 806 }
1036 807
@@ -1083,9 +854,9 @@
1083 854 return $values;
1084 855 }
1085 856
1086 857 public static function get_current_form_id( $default_form = 'none' ) {
1087 - if ( 'first' === $default_form ) {
858 + if ( 'first' == $default_form ) {
1088 859 $form = self::get_current_form();
1089 860 } else {
1090 861 $form = self::maybe_get_current_form();
1091 862 }
@@ -1096,9 +867,9 @@
1096 867
1097 868 public static function maybe_get_current_form( $form_id = 0 ) {
1098 869 global $frm_vars;
1099 870
1100 - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
871 + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
1101 872 return $frm_vars['current_form'];
1102 873 }
1103 874
1104 875 $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' );
@@ -1145,9 +916,9 @@
1145 916 $global_load = true;
1146 917 $frm_vars['load_css'] = true;
1147 918 }
1148 919
1149 - return empty( $frm_vars['css_loaded'] ) && $global_load;
920 + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
1150 921 }
1151 922
1152 923 /**
1153 924 * @since 4.06.03
@@ -1162,21 +933,13 @@
1162 933 } else {
1163 934 $visible = true;
1164 935 }
1165 936
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 937 return $visible;
1175 938 }
1176 939
1177 940 public static function show_submit( $form ) {
1178 - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() );
941 + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
1179 942 $show = apply_filters( 'frm_show_submit_button', $show, $form );
1180 943
1181 944 return $show;
1182 945 }
@@ -1184,12 +947,12 @@
1184 947 /**
1185 948 * @since 2.3
1186 949 */
1187 950 public static function get_option( $atts ) {
1188 - $form = $atts['form'];
1189 - $default = $atts['default'] ?? '';
951 + $form = $atts['form'];
952 + $default = isset( $atts['default'] ) ? $atts['default'] : '';
1190 953
1191 - return $form->options[ $atts['option'] ] ?? $default;
954 + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default;
1192 955 }
1193 956
1194 957 /**
1195 958 * Get the link to edit this form.
@@ -1201,81 +964,23 @@
1201 964 return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
1202 965 }
1203 966
1204 967 /**
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).
968 + * @deprecated 3.0
1260 969 * @codeCoverageIgnore
1261 970 *
1262 971 * @param string $key
972 + *
1263 973 * @return int form id
1264 974 */
1265 975 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 );
976 + return FrmFormDeprecated::getIdByKey( $key );
1268 977 }
1269 978
1270 979 /**
1271 - * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13.
980 + * @deprecated 3.0
1272 981 * @codeCoverageIgnore
1273 - *
1274 - * @param int|string $id
1275 - * @return string
1276 982 */
1277 983 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 );
984 + return FrmFormDeprecated::getKeyById( $id );
1280 985 }
1281 986 }