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