PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.1
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/helpers/FrmFormsHelper.php +183 -339 6.27 → 6.22.1 View file →
@@ -15,33 +15,20 @@
15 15 private static $field_type_data_for_insert_opt_html;
16 16
17 17 /**
18 18 * @since 2.2.10
19 - *
20 - * @return string
21 19 */
22 20 public static function form_error_class() {
23 21 return apply_filters( 'frm_form_error_class', 'frm_error_style' );
24 22 }
25 23
26 - /**
27 - * @param string $key
28 - * @param false|object $form
29 - *
30 - * @return string
31 - */
32 24 public static function get_direct_link( $key, $form = false ) {
33 25 $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) );
34 - return apply_filters( 'frm_direct_link', $target_url, $key, $form );
26 + $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form );
27 +
28 + return $target_url;
35 29 }
36 30
37 - /**
38 - * @param string $field_name
39 - * @param int|string $field_value
40 - * @param array $args
41 - *
42 - * @return void
43 - */
44 31 public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
45 32 $defaults = array(
46 33 'blank' => true,
47 34 'field_id' => false,
@@ -56,9 +43,8 @@
56 43 $args['field_id'] = $field_name;
57 44 }
58 45
59 46 $query = array();
60 -
61 47 if ( $args['exclude'] ) {
62 48 $query['id !'] = $args['exclude'];
63 49 }
64 50
@@ -72,13 +58,13 @@
72 58 <select name="<?php echo esc_attr( $field_name ); ?>"
73 59 id="<?php echo esc_attr( $args['field_id'] ); ?>"
74 60 <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
75 61 <?php if ( $args['blank'] ) { ?>
76 - <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; // phpcs:ignore Universal.Operators.StrictComparisons ?></option>
62 + <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
77 63 <?php } ?>
78 64 <?php foreach ( $forms as $form ) { ?>
79 65 <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>>
80 - <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
66 + <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
81 67 </option>
82 68 <?php } ?>
83 69 </select>
84 70 <?php
@@ -85,17 +71,14 @@
85 71 }
86 72
87 73 /**
88 74 * @since 2.0.6
89 - *
90 75 * @param string $class
91 76 * @param string $param
92 77 * @param array $add_html
93 - *
94 - * @return void
95 78 */
96 79 public static function add_html_attr( $class, $param, &$add_html ) {
97 - if ( $class ) {
80 + if ( ! empty( $class ) ) {
98 81 $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"';
99 82 }
100 83 }
101 84
@@ -100,12 +83,10 @@
100 83 }
101 84
102 85 /**
103 86 * @param false|object|string $selected - The label for the placeholder, or the form object.
104 - *
105 - * @return void
106 87 */
107 - public static function form_switcher( $selected = false ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong
88 + public static function form_switcher( $selected = false ) {
108 89 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
109 90 $forms = FrmForm::get_published_forms( $where );
110 91
111 92 $args = array(
@@ -111,9 +92,8 @@
111 92 $args = array(
112 93 'id' => 0,
113 94 'form' => 0,
114 95 );
115 -
116 96 if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
117 97 unset( $args['form'] );
118 98 } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) {
119 99 unset( $args['id'] );
@@ -119,9 +99,8 @@
119 99 unset( $args['id'] );
120 100 }
121 101
122 102 $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
123 -
124 103 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) {
125 104 $args['frm_action'] = 'list';
126 105 $args['form'] = 0;
127 106 } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) {
@@ -131,21 +110,18 @@
131 110 unset( $args['id'] );
132 111 $query_args = array(
133 112 'page' => 'formidable-styles',
134 113 );
135 -
136 114 if ( $frm_action ) {
137 115 $query_args['frm_action'] = $frm_action;
138 116 }
139 -
140 117 $base = add_query_arg( $query_args, admin_url( 'admin.php' ) );
141 118 } elseif ( isset( $_GET['post'] ) ) {
142 119 $args['form'] = 0;
143 120 $base = admin_url( 'edit.php?post_type=frm_display' );
144 - }//end if
121 + }
145 122
146 123 $form_id = 0;
147 -
148 124 if ( is_object( $selected ) ) {
149 125 $form_id = $selected->id;
150 126 $selected = $selected->name;
151 127 }
@@ -201,9 +177,8 @@
201 177
202 178 if ( isset( $args['id'] ) ) {
203 179 $args['id'] = $form->id;
204 180 }
205 -
206 181 if ( isset( $args['form'] ) ) {
207 182 $args['form'] = $form->id;
208 183 }
209 184
@@ -233,18 +208,11 @@
233 208 </div>
234 209 <?php
235 210 }
236 211
237 - /**
238 - * @param string $col
239 - * @param string $sort_col
240 - * @param string $sort_dir
241 - *
242 - * @return void
243 - */
244 212 public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
245 - echo $sort_col == $col ? 'sorted' : 'sortable'; // phpcs:ignore Universal.Operators.StrictComparisons
246 - echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; // phpcs:ignore Universal.Operators.StrictComparisons
213 + echo $sort_col == $col ? 'sorted' : 'sortable';
214 + echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc';
247 215 }
248 216
249 217 /**
250 218 * @since 3.0
@@ -249,13 +217,18 @@
249 217 /**
250 218 * @since 3.0
251 219 *
252 220 * @param array|string $field_type
253 - *
254 221 * @return string
255 222 */
256 223 public static function get_field_link_name( $field_type ) {
257 - return is_array( $field_type ) ? $field_type['name'] : $field_type;
224 + if ( is_array( $field_type ) ) {
225 + $field_label = $field_type['name'];
226 + } else {
227 + $field_label = $field_type;
228 + }
229 +
230 + return $field_label;
258 231 }
259 232
260 233 /**
261 234 * @since 3.0
@@ -260,13 +233,18 @@
260 233 /**
261 234 * @since 3.0
262 235 *
263 236 * @param array|string $field_type
264 - *
265 237 * @return string
266 238 */
267 239 public static function get_field_link_icon( $field_type ) {
268 - return is_array( $field_type ) && isset( $field_type['icon'] ) ? $field_type['icon'] : 'frmfont frm_pencil_icon';
240 + if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) {
241 + $icon = $field_type['icon'];
242 + } else {
243 + $icon = 'frm_icon_font frm_pencil_icon';
244 + }
245 +
246 + return $icon;
269 247 }
270 248
271 249 /**
272 250 * Get the invalid form error message
@@ -278,9 +256,8 @@
278 256 * @return string
279 257 */
280 258 public static function get_invalid_error_message( $args ) {
281 259 $settings_args = $args;
282 -
283 260 if ( isset( $args['form'] ) ) {
284 261 $settings_args['current_form'] = $args['form']->id;
285 262 }
286 263
@@ -297,48 +274,24 @@
297 274 * @type stdClass $form
298 275 * @type int $entry_id
299 276 * @type string $class
300 277 * }
301 - *
302 278 * @return string
303 279 */
304 280 public static function get_success_message( $atts ) {
305 281 $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
306 -
307 - // Only autop if the message includes line breaks.
308 - $autop = str_contains( $message, "\n" );
309 -
310 - /**
311 - * Filters whether to autop the success message.
312 - * This is false by default if the message does not include line breaks.
313 - *
314 - * @since 6.23
315 - *
316 - * @param bool $autop
317 - * @param string $message
318 - * @param object $form
319 - */
320 - $autop = (bool) apply_filters( 'frm_wpautop_success_message', $autop, $message, $atts['form'] );
321 -
322 - if ( $autop ) {
323 - $message = FrmAppHelper::use_wpautop( $message );
324 - }
325 -
326 - $message = do_shortcode( $message );
327 - return '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
282 + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) );
283 + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
284 + return $message;
328 285 }
329 286
330 287 /**
331 288 * Used when a form is created
332 - *
333 - * @param array $values
334 - *
335 - * @return array
336 289 */
337 290 public static function setup_new_vars( $values = array() ) {
338 291 global $wpdb;
339 292
340 - if ( $values ) {
293 + if ( ! empty( $values ) ) {
341 294 $post_values = $values;
342 295 } else {
343 296 $values = array();
344 297 $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -347,9 +300,8 @@
347 300 $defaults = array(
348 301 'name' => '',
349 302 'description' => '',
350 303 );
351 -
352 304 foreach ( $defaults as $var => $default ) {
353 305 if ( ! isset( $values[ $var ] ) ) {
354 306 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
355 307 }
@@ -364,9 +316,8 @@
364 316 'is_template' => 0,
365 317 'status' => 'published',
366 318 'parent_form_id' => 0,
367 319 );
368 -
369 320 foreach ( $defaults as $var => $default ) {
370 321 if ( ! isset( $values[ $var ] ) ) {
371 322 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
372 323 }
@@ -373,9 +324,9 @@
373 324 }
374 325 unset( $defaults );
375 326
376 327 if ( ! isset( $values['form_key'] ) ) {
377 - $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
328 + $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
378 329 }
379 330
380 331 $values = self::fill_default_opts( $values, false, $post_values );
381 332 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -384,22 +335,16 @@
384 335 }
385 336
386 337 /**
387 338 * Used when editing a form
388 - *
389 - * @param array $values
390 - * @param object $record
391 - * @param array $post_values
392 - *
393 - * @return array
394 339 */
395 340 public static function setup_edit_vars( $values, $record, $post_values = array() ) {
396 - if ( ! $post_values ) {
341 + if ( empty( $post_values ) ) {
397 342 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
398 343 }
399 344
400 - $values['form_key'] = $post_values['form_key'] ?? $record->form_key;
401 - $values['is_template'] = $post_values['is_template'] ?? $record->is_template;
345 + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
346 + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
402 347 $values['status'] = $record->status;
403 348
404 349 $values = self::fill_default_opts( $values, $record, $post_values );
405 350
@@ -405,19 +350,11 @@
405 350
406 351 return apply_filters( 'frm_setup_edit_form_vars', $values );
407 352 }
408 353
409 - /**
410 - * @param array $values
411 - * @param false|object $record
412 - * @param array|false $post_values
413 - *
414 - * @return array
415 - */
416 - public static function fill_default_opts( $values, $record, $post_values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
354 + public static function fill_default_opts( $values, $record, $post_values ) {
417 355
418 356 $defaults = self::get_default_opts();
419 -
420 357 foreach ( $defaults as $var => $default ) {
421 358 if ( is_array( $default ) ) {
422 359 if ( ! isset( $values[ $var ] ) ) {
423 360 $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
@@ -423,13 +360,13 @@
423 360 $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
424 361 }
425 362
426 363 foreach ( $default as $k => $v ) {
427 - $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
364 + $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v );
428 365
429 366 if ( is_array( $v ) ) {
430 367 foreach ( $v as $k1 => $v1 ) {
431 - $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
368 + $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
432 369 unset( $k1, $v1 );
433 370 }
434 371 }
435 372
@@ -435,9 +372,9 @@
435 372
436 373 unset( $k, $v );
437 374 }
438 375 } else {
439 - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
376 + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default );
440 377 }
441 378
442 379 unset( $var, $default );
443 380 }//end foreach
@@ -474,19 +411,15 @@
474 411 }
475 412
476 413 /**
477 414 * @since 2.0.6
478 - *
479 415 * @param array $options
480 416 * @param array $values
481 - *
482 - * @return void
483 417 */
484 418 public static function fill_form_options( &$options, $values ) {
485 419 $defaults = self::get_default_opts();
486 -
487 420 foreach ( $defaults as $var => $default ) {
488 - $options[ $var ] = $values['options'][ $var ] ?? $default;
421 + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
489 422 unset( $var, $default );
490 423 }
491 424 }
492 425
@@ -491,10 +424,8 @@
491 424 }
492 425
493 426 /**
494 427 * @param string $loc
495 - *
496 - * @return string
497 428 */
498 429 public static function get_default_html( $loc ) {
499 430 if ( $loc === 'submit' ) {
500 431 $draft_link = self::get_draft_link();
@@ -519,13 +450,12 @@
519 450
520 451 return $default_html;
521 452 }
522 453
523 - /**
524 - * @return string
525 - */
526 454 public static function get_draft_link() {
527 - return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
455 + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
456 +
457 + return $link;
528 458 }
529 459
530 460 /**
531 461 * Gets start over button shortcode.
@@ -537,21 +467,11 @@
537 467 public static function get_start_over_shortcode() {
538 468 return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]';
539 469 }
540 470
541 - /**
542 - * @param string $html
543 - * @param object $form
544 - * @param string $submit
545 - * @param object|null $form_action
546 - * @param array $values
547 - *
548 - * @return void
549 - */
550 471 public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
551 472 $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
552 -
553 - if ( ! str_contains( $button, '[button_action]' ) ) {
473 + if ( ! strpos( $button, '[button_action]' ) ) {
554 474 echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
555 475 return;
556 476 }
557 477
@@ -558,20 +478,17 @@
558 478 /**
559 479 * @since 5.0.06
560 480 */
561 481 $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) );
562 -
563 482 if ( FrmAppHelper::should_never_allow_unfiltered_html() ) {
564 483 $button = FrmAppHelper::kses_submit_button( $button );
565 484 }
566 -
567 485 $button_parts = explode( '[button_action]', $button );
568 - $classes = apply_filters( 'frm_submit_button_class', array(), $form );
569 486
570 - if ( $classes ) {
487 + $classes = apply_filters( 'frm_submit_button_class', array(), $form );
488 + if ( ! empty( $classes ) ) {
571 489 $classes = implode( ' ', $classes );
572 490 $button_class = 'frm_button_submit';
573 -
574 491 if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
575 492 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
576 493 } else {
577 494 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
@@ -584,10 +501,8 @@
584 501 }
585 502
586 503 /**
587 504 * @since 4.0
588 - *
589 - * @return array
590 505 */
591 506 public static function html_shortcodes() {
592 507 $codes = array(
593 508 'id' => array(
@@ -674,15 +589,14 @@
674 589 /**
675 590 * @since 4.0
676 591 *
677 592 * @param array $args
678 - *
679 593 * @return void
680 594 */
681 595 public static function insert_opt_html( $args ) {
682 - $class = $args['class'] ?? '';
596 + $class = isset( $args['class'] ) ? $args['class'] : '';
683 597 $fields = self::get_field_type_data_for_insert_opt_html();
684 - $field = $fields[ $args['type'] ] ?? array();
598 + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
685 599
686 600 self::prepare_field_type( $field );
687 601
688 602 if ( ! isset( $field['icon'] ) ) {
@@ -689,9 +603,8 @@
689 603 $field['icon'] = 'frmfont frm_pencil_icon';
690 604 }
691 605
692 606 $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
693 -
694 607 if ( $possible_email_field ) {
695 608 $class .= ' show_frm_not_email_to';
696 609 }
697 610
@@ -699,30 +612,34 @@
699 612 $class .= ' frm_insert_url';
700 613 }
701 614
702 615 $truncated_name = FrmAppHelper::truncate( $args['name'], 60 );
703 -
616 + if ( isset( $field['icon'] ) ) {
617 + $icon = FrmAppHelper::icon_by_class(
618 + $field['icon'],
619 + array(
620 + 'aria-hidden' => 'true',
621 + 'echo' => false,
622 + )
623 + );
624 + } else {
625 + $icon = '';
626 + }
704 627 ?>
705 628 <li class="<?php echo esc_attr( $class ); ?>">
706 629 <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>">
707 630 <?php
708 - if ( isset( $field['icon'] ) ) {
709 - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) );
710 - }
711 -
631 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
712 632 echo esc_html( $truncated_name );
713 633 ?>
714 - <span>[<?php echo esc_attr( $args['id_label'] ?? $args['id'] ); ?>]</span>
634 + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
715 635 </a>
716 636 <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>">
717 637 <?php
718 - if ( isset( $field['icon'] ) ) {
719 - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) );
720 - }
721 -
638 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
722 639 echo esc_html( $truncated_name );
723 640 ?>
724 - <span>[<?php echo esc_attr( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) ); ?>]</span>
641 + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
725 642 </a>
726 643 </li>
727 644 <?php
728 645 }
@@ -743,12 +660,9 @@
743 660 }
744 661
745 662 /**
746 663 * @since 4.0
747 - *
748 664 * @param array $args
749 - *
750 - * @return void
751 665 */
752 666 public static function insert_code_html( $args ) {
753 667 $defaults = array(
754 668 'class' => '',
@@ -780,9 +694,8 @@
780 694 *
781 695 * @since 4.0
782 696 *
783 697 * @param array|string $field
784 - *
785 698 * @return void
786 699 */
787 700 public static function prepare_field_type( &$field ) {
788 701 if ( ! is_array( $field ) ) {
@@ -787,9 +700,9 @@
787 700 public static function prepare_field_type( &$field ) {
788 701 if ( ! is_array( $field ) ) {
789 702 $field = array(
790 703 'name' => $field,
791 - 'icon' => 'frmfont frm_pencil_icon',
704 + 'icon' => 'frm_icon_font frm_pencil_icon',
792 705 );
793 706 }
794 707 }
795 708
@@ -800,13 +713,11 @@
800 713 *
801 714 * @param object $form
802 715 * @param array $fields
803 716 * @param bool $reset_fields
804 - *
805 - * @return void
806 717 */
807 718 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
808 - if ( ! $fields ) {
719 + if ( empty( $fields ) ) {
809 720 return;
810 721 }
811 722
812 723 $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
@@ -813,9 +724,8 @@
813 724 $open = false;
814 725 $prev_order = false;
815 726 $add_order = 0;
816 727 $last_field = false;
817 -
818 728 foreach ( $fields as $field ) {
819 729 if ( $prev_order === $field->field_order ) {
820 730 ++$add_order;
821 731 }
@@ -858,17 +768,8 @@
858 768
859 769 /**
860 770 * Create end section field if it doesn't exist. This is for migration from < 2.0
861 771 * Fix any ordering that may be messed up
862 - *
863 - * @param bool $open
864 - * @param bool $reset_fields
865 - * @param int $add_order
866 - * @param array $end_section_values
867 - * @param object $field
868 - * @param string $move
869 - *
870 - * @return void
871 772 */
872 773 public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) {
873 774 if ( ! $open ) {
874 775 return;
@@ -887,17 +788,8 @@
887 788 $open = false;
888 789 $reset_fields = true;
889 790 }
890 791
891 - /**
892 - * @param string $html
893 - * @param object $form
894 - * @param bool $title
895 - * @param bool $description
896 - * @param array $values
897 - *
898 - * @return string
899 - */
900 792 public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
901 793 $codes = array(
902 794 'form_name' => $title,
903 795 'form_description' => $description,
@@ -902,9 +794,8 @@
902 794 'form_name' => $title,
903 795 'form_description' => $description,
904 796 'entry_key' => true,
905 797 );
906 -
907 798 foreach ( $codes as $code => $show ) {
908 799 if ( $code === 'form_name' ) {
909 800 $replace_with = $form->name;
910 801 } elseif ( $code === 'form_description' ) {
@@ -914,9 +805,9 @@
914 805 } else {
915 806 $replace_with = '';
916 807 }
917 808
918 - FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
809 + FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
919 810 }
920 811
921 812 // Replace [form_key].
922 813 $html = str_replace( '[form_key]', $form->form_key, $html );
@@ -923,9 +814,9 @@
923 814
924 815 // Replace [frmurl].
925 816 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
926 817
927 - if ( str_contains( $html, '[button_label]' ) ) {
818 + if ( strpos( $html, '[button_label]' ) ) {
928 819 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
929 820 $submit_label = apply_filters( 'frm_submit_button', $title, $form );
930 821 $submit_label = esc_attr( do_shortcode( $submit_label ) );
931 822 $html = str_replace( '[button_label]', $submit_label, $html );
@@ -932,17 +823,17 @@
932 823 }
933 824
934 825 $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values );
935 826
936 - if ( str_contains( $html, '[if back_button]' ) ) {
827 + if ( strpos( $html, '[if back_button]' ) ) {
937 828 $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html );
938 829 }
939 830
940 - if ( str_contains( $html, '[if save_draft]' ) ) {
831 + if ( strpos( $html, '[if save_draft]' ) ) {
941 832 $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
942 833 }
943 834
944 - if ( str_contains( $html, '[if start_over]' ) ) {
835 + if ( strpos( $html, '[if start_over]' ) ) {
945 836 $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html );
946 837 }
947 838
948 839 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
@@ -951,13 +842,8 @@
951 842
952 843 return $html;
953 844 }
954 845
955 - /**
956 - * @param string $submit
957 - *
958 - * @return string
959 - */
960 846 public static function submit_button_label( $submit ) {
961 847 if ( ! $submit ) {
962 848 $frm_settings = FrmAppHelper::get_settings();
963 849 $submit = $frm_settings->submit_value;
@@ -975,9 +861,8 @@
975 861 * @return void
976 862 */
977 863 public static function maybe_hide_inline() {
978 864 $frm_settings = FrmAppHelper::get_settings();
979 -
980 865 if ( $frm_settings->load_style === 'none' ) {
981 866 echo ' style="display:none;"';
982 867 } elseif ( $frm_settings->load_style === 'dynamic' ) {
983 868 FrmStylesController::enqueue_style();
@@ -984,10 +869,8 @@
984 869 }
985 870 }
986 871
987 872 /**
988 - * @param array|bool|int|object|string $form
989 - *
990 873 * @return string|null
991 874 */
992 875 public static function get_form_style_class( $form = false ) {
993 876 $style = self::get_form_style( $form );
@@ -992,10 +875,13 @@
992 875 public static function get_form_style_class( $form = false ) {
993 876 $style = self::get_form_style( $form );
994 877 $class = ' with_frm_style';
995 878
996 - if ( ! $style ) {
997 - return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null;
879 + if ( empty( $style ) ) {
880 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
881 + return $class;
882 + }
883 + return;
998 884 }
999 885
1000 886 // If submit button needs to be inline or centered.
1001 887 if ( is_object( $form ) ) {
@@ -1016,9 +902,11 @@
1016 902 } elseif ( 'center' === $submit_align ) {
1017 903 $class .= ' frm_center_submit';
1018 904 }
1019 905
1020 - return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) );
906 + $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) );
907 +
908 + return $class;
1021 909 }
1022 910
1023 911 /**
1024 912 * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work.
@@ -1025,17 +913,16 @@
1025 913 *
1026 914 * @since 5.0.12
1027 915 *
1028 916 * @param array $form
1029 - *
1030 917 * @return bool
1031 918 */
1032 919 private static function form_should_be_inline_and_missing_class( $form ) {
1033 - if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) {
920 + if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) {
1034 921 // not missing class, avoid adding it twice.
1035 922 return false;
1036 923 }
1037 - return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' );
924 + return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' );
1038 925 }
1039 926
1040 927 /**
1041 928 * Returns appropriate class if form has top labels
@@ -1060,9 +947,8 @@
1060 947 return false;
1061 948 }
1062 949
1063 950 $fields = $form['fields'];
1064 -
1065 951 if ( count( $fields ) <= 0 ) {
1066 952 return false;
1067 953 }
1068 954
@@ -1067,13 +953,11 @@
1067 953 }
1068 954
1069 955 // Start from the fields closest to the submit button.
1070 956 $fields = array_reverse( $fields );
1071 -
1072 957 foreach ( $fields as $field ) {
1073 - $type = $field['original_type'] ?? $field['type'];
958 + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
1074 959 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
1075 -
1076 960 if ( $has_input ) {
1077 961 return self::field_has_top_label( $field, $form );
1078 962 }
1079 963 }
@@ -1090,20 +974,19 @@
1090 974 * @return bool
1091 975 */
1092 976 private static function field_has_top_label( $field, $form ) {
1093 977 $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form );
1094 - return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true );
978 +
979 + return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
1095 980 }
1096 981
1097 982 /**
1098 983 * @param array|bool|int|object|string $form
1099 - *
1100 984 * @return string
1101 985 */
1102 986 public static function get_form_style( $form ) {
1103 987 $style = 1;
1104 -
1105 - if ( ! $form || 'default' === $form ) {
988 + if ( empty( $form ) || 'default' === $form ) {
1106 989 return $style;
1107 990 }
1108 991
1109 992 if ( is_object( $form ) && $form->parent_form_id ) {
@@ -1118,9 +1001,11 @@
1118 1001 if ( $form && ( is_string( $form ) || is_int( $form ) ) ) {
1119 1002 $form = FrmForm::getOne( $form );
1120 1003 }
1121 1004
1122 - return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
1005 + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
1006 +
1007 + return $style;
1123 1008 }
1124 1009
1125 1010 /**
1126 1011 * Display the validation error messages when an entry is submitted
@@ -1125,17 +1010,14 @@
1125 1010 /**
1126 1011 * Display the validation error messages when an entry is submitted
1127 1012 *
1128 1013 * @since 2.0.6
1129 - *
1130 1014 * @param array $args Includes img, errors.
1131 - *
1132 - * @return void
1133 1015 */
1134 1016 public static function show_errors( $args ) {
1135 1017 $invalid_msg = self::get_invalid_error_message( $args );
1136 1018
1137 - if ( ! $invalid_msg ) {
1019 + if ( empty( $invalid_msg ) ) {
1138 1020 $show_img = false;
1139 1021 } else {
1140 1022 echo wp_kses_post( $invalid_msg );
1141 1023 $show_img = true;
@@ -1155,12 +1037,9 @@
1155 1037 * The image was removed from the styling settings, but it may still be set with a hook
1156 1038 * If the message in the global settings is empty, show every validation message in the error box
1157 1039 *
1158 1040 * @since 2.0.6
1159 - *
1160 1041 * @param array $args Includes img, errors, and show_img.
1161 - *
1162 - * @return void
1163 1042 */
1164 1043 public static function show_error( $args ) {
1165 1044 // remove any blank messages
1166 1045 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -1165,11 +1044,10 @@
1165 1044 // remove any blank messages
1166 1045 $args['errors'] = array_filter( (array) $args['errors'] );
1167 1046
1168 1047 $line_break_first = $args['show_img'];
1169 -
1170 1048 foreach ( $args['errors'] as $error_key => $error ) {
1171 - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) {
1049 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1172 1050 continue;
1173 1051 }
1174 1052
1175 1053 $id = str_replace( 'field', 'field_', $error_key );
@@ -1186,27 +1064,15 @@
1186 1064 echo '</div>';
1187 1065 }
1188 1066 }
1189 1067
1190 - /**
1191 - * @param int|string $id
1192 - *
1193 - * @return void
1194 - */
1195 1068 public static function maybe_get_scroll_js( $id ) {
1196 1069 $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
1197 -
1198 - // phpcs:ignore Universal.Operators.StrictComparisons
1199 1070 if ( $offset != - 1 ) {
1200 1071 self::get_scroll_js( $id );
1201 1072 }
1202 1073 }
1203 1074
1204 - /**
1205 - * @param int|string $form_id
1206 - *
1207 - * @return void
1208 - */
1209 1075 public static function get_scroll_js( $form_id ) {
1210 1076 echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
1211 1077 }
1212 1078
@@ -1211,13 +1077,8 @@
1211 1077 }
1212 1078
1213 1079 /**
1214 1080 * @since 3.0
1215 - *
1216 - * @param int|object|string $form_id
1217 - * @param mixed $form
1218 - *
1219 - * @return array
1220 1081 */
1221 1082 public static function get_action_links( $form_id, $form ) {
1222 1083 if ( ! is_object( $form ) ) {
1223 1084 $form = FrmForm::getOne( $form_id );
@@ -1224,10 +1085,9 @@
1224 1085 }
1225 1086
1226 1087 $actions = array();
1227 1088 $trash_links = self::delete_trash_links( $form_id );
1228 -
1229 - if ( 'trash' === $form->status ) {
1089 + if ( 'trash' == $form->status ) {
1230 1090 $actions['restore'] = $trash_links['restore'];
1231 1091
1232 1092 if ( current_user_can( 'frm_delete_forms' ) ) {
1233 1093 $actions['trash'] = $trash_links['delete'];
@@ -1233,20 +1093,19 @@
1233 1093 $actions['trash'] = $trash_links['delete'];
1234 1094 }
1235 1095 } elseif ( current_user_can( 'frm_edit_forms' ) ) {
1236 1096 $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id;
1237 -
1238 1097 if ( $form->is_template ) {
1239 1098 $actions['frm_duplicate'] = array(
1240 1099 'url' => wp_nonce_url( $duplicate_link ),
1241 1100 'label' => __( 'Create Form from Template', 'formidable' ),
1242 - 'icon' => 'frmfont frm_clone_icon',
1101 + 'icon' => 'frm_icon_font frm_clone_icon',
1243 1102 );
1244 1103 } else {
1245 1104 $actions['duplicate'] = array(
1246 1105 'url' => wp_nonce_url( $duplicate_link ),
1247 1106 'label' => __( 'Duplicate Form', 'formidable' ),
1248 - 'icon' => 'frmfont frm_clone_icon',
1107 + 'icon' => 'frm_icon_font frm_clone_icon',
1249 1108 );
1250 1109 }
1251 1110
1252 1111 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
@@ -1256,9 +1115,8 @@
1256 1115 }
1257 1116
1258 1117 /**
1259 1118 * @param int|object|string $data
1260 - *
1261 1119 * @return string
1262 1120 */
1263 1121 public static function edit_form_link( $data ) {
1264 1122 $form_id = self::get_form_id_from_data( $data );
@@ -1267,9 +1125,10 @@
1267 1125 return '';
1268 1126 }
1269 1127
1270 1128 $label = self::edit_form_link_label( $data );
1271 - return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1129 + $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1130 + return $link;
1272 1131 }
1273 1132
1274 1133 /**
1275 1134 * Returns a text used when no title is set.
@@ -1283,70 +1142,58 @@
1283 1142 }
1284 1143
1285 1144 /**
1286 1145 * @param int|object|string $data
1287 - *
1288 1146 * @return string
1289 1147 */
1290 1148 public static function edit_form_link_label( $data ) {
1291 1149 $name = self::get_form_name_from_data( $data );
1292 -
1293 1150 if ( ! $name ) {
1294 1151 return self::get_no_title_text();
1295 1152 }
1296 -
1297 1153 return FrmAppHelper::truncate( $name, 40 );
1298 1154 }
1299 1155
1300 1156 /**
1301 1157 * @param int|object|string $data
1302 - *
1303 1158 * @return int|string
1304 1159 */
1305 1160 private static function get_form_id_from_data( $data ) {
1306 - return is_object( $data ) ? $data->id : $data;
1161 + if ( is_object( $data ) ) {
1162 + $form_id = $data->id;
1163 + } else {
1164 + $form_id = $data;
1165 + }
1166 + return $form_id;
1307 1167 }
1308 1168
1309 1169 /**
1310 1170 * @param mixed $data
1311 - *
1312 1171 * @return string
1313 1172 */
1314 1173 private static function get_form_name_from_data( $data ) {
1315 1174 if ( is_object( $data ) ) {
1316 - return $data->name;
1175 + $form_name = $data->name;
1176 + } else {
1177 + $form_id = $data;
1178 + $form_name = FrmForm::getName( $form_id );
1317 1179 }
1318 -
1319 - $form_id = $data;
1320 - return FrmForm::getName( $form_id );
1180 + return $form_name;
1321 1181 }
1322 1182
1323 - /**
1324 - * @param int $id
1325 - * @param string $status
1326 - * @param string $length
1327 - *
1328 - * @return string
1329 - */
1330 1183 public static function delete_trash_link( $id, $status, $length = 'label' ) {
1331 1184 $link_details = self::delete_trash_info( $id, $status );
1185 +
1332 1186 return self::format_link_html( $link_details, $length );
1333 1187 }
1334 1188
1335 1189 /**
1336 1190 * @since 3.0
1337 - *
1338 - * @param array $link_details
1339 - * @param string $length
1340 - *
1341 - * @return string
1342 1191 */
1343 1192 public static function format_link_html( $link_details, $length = 'label' ) {
1344 1193 $link = '';
1345 -
1346 - if ( $link_details ) {
1194 + if ( ! empty( $link_details ) ) {
1347 1195 $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"';
1348 -
1349 1196 if ( isset( $link_details['data'] ) ) {
1350 1197 foreach ( $link_details['data'] as $data => $value ) {
1351 1198 $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
1352 1199 }
@@ -1353,10 +1200,9 @@
1353 1200 } elseif ( isset( $link_details['confirm'] ) ) {
1354 1201 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1355 1202 }
1356 1203
1357 - $label = $link_details[ $length ] ?? $link_details['label'];
1358 -
1204 + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1359 1205 if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1360 1206 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1361 1207 $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1362 1208 }
@@ -1368,13 +1214,8 @@
1368 1214 }
1369 1215
1370 1216 /**
1371 1217 * @since 3.0
1372 - *
1373 - * @param int $id
1374 - * @param string $status
1375 - *
1376 - * @return array
1377 1218 */
1378 1219 public static function delete_trash_info( $id, $status ) {
1379 1220 $labels = self::delete_trash_links( $id );
1380 1221
@@ -1380,9 +1221,13 @@
1380 1221
1381 1222 if ( 'trash' === $status ) {
1382 1223 $info = $labels['restore'];
1383 1224 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1384 - $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete'];
1225 + if ( EMPTY_TRASH_DAYS ) {
1226 + $info = $labels['trash'];
1227 + } else {
1228 + $info = $labels['delete'];
1229 + }
1385 1230 } else {
1386 1231 $info = array();
1387 1232 }
1388 1233
@@ -1390,12 +1235,8 @@
1390 1235 }
1391 1236
1392 1237 /**
1393 1238 * @since 3.0
1394 - *
1395 - * @param int $id
1396 - *
1397 - * @return array
1398 1239 */
1399 1240 public static function delete_trash_links( $id ) {
1400 1241 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1401 1242 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
@@ -1409,9 +1250,9 @@
1409 1250 'trash' => array(
1410 1251 'label' => __( 'Move Form to Trash', 'formidable' ),
1411 1252 'short' => __( 'Trash', 'formidable' ),
1412 1253 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
1413 - 'icon' => 'frmfont frm_delete_icon',
1254 + 'icon' => 'frm_icon_font frm_delete_icon',
1414 1255 'data' => array(
1415 1256 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ),
1416 1257 'frmverify-btn' => 'frm-button-red',
1417 1258 ),
@@ -1420,9 +1261,9 @@
1420 1261 'label' => __( 'Delete Permanently', 'formidable' ),
1421 1262 'short' => __( 'Delete', 'formidable' ),
1422 1263 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
1423 1264 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
1424 - 'icon' => 'frmfont frm_delete_icon',
1265 + 'icon' => 'frm_icon_font frm_delete_icon',
1425 1266 'data' => array(
1426 1267 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ),
1427 1268 'frmverify-btn' => 'frm-button-red',
1428 1269 ),
@@ -1431,10 +1272,8 @@
1431 1272 }
1432 1273
1433 1274 /**
1434 1275 * @since 3.0
1435 - *
1436 - * @return array
1437 1276 */
1438 1277 public static function css_classes() {
1439 1278 $classes = array(
1440 1279 'frm_total' => array(
@@ -1446,9 +1285,9 @@
1446 1285 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1447 1286 ),
1448 1287 'frm_scroll_box' => array(
1449 1288 'label' => __( 'Scroll Box', 'formidable' ),
1450 - 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1289 + 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ),
1451 1290 ),
1452 1291 'frm_first' => array(
1453 1292 'label' => __( 'First', 'formidable' ),
1454 1293 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
@@ -1469,11 +1308,8 @@
1469 1308
1470 1309 return apply_filters( 'frm_layout_classes', $classes );
1471 1310 }
1472 1311
1473 - /**
1474 - * @return array
1475 - */
1476 1312 public static function grid_classes() {
1477 1313 return array(
1478 1314 'frm_half' => '1/2',
1479 1315 'frm_third' => '1/3',
@@ -1487,18 +1323,12 @@
1487 1323 }
1488 1324
1489 1325 /**
1490 1326 * @since 3.0
1491 - *
1492 - * @param mixed $style
1493 - * @param string $class
1494 - *
1495 - * @return string
1496 1327 */
1497 1328 public static function style_class_label( $style, $class ) {
1498 1329 $label = '';
1499 -
1500 - if ( ! $style ) {
1330 + if ( empty( $style ) ) {
1501 1331 $label = $class;
1502 1332 } elseif ( ! is_array( $style ) ) {
1503 1333 $label = $style;
1504 1334 } elseif ( isset( $style['label'] ) ) {
@@ -1507,13 +1337,8 @@
1507 1337
1508 1338 return $label;
1509 1339 }
1510 1340
1511 - /**
1512 - * @param string $status
1513 - *
1514 - * @return string
1515 - */
1516 1341 public static function status_nice_name( $status ) {
1517 1342 $nice_names = array(
1518 1343 'draft' => __( 'Draft', 'formidable' ),
1519 1344 'trash' => __( 'Trash', 'formidable' ),
@@ -1523,9 +1348,11 @@
1523 1348 if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1524 1349 $status = 'publish';
1525 1350 }
1526 1351
1527 - return $nice_names[ $status ];
1352 + $name = $nice_names[ $status ];
1353 +
1354 + return $name;
1528 1355 }
1529 1356
1530 1357 /**
1531 1358 * Renders a template icon based on the given categories.
@@ -1532,9 +1359,8 @@
1532 1359 *
1533 1360 * @param array $categories The categories to render the icon for.
1534 1361 * @param array $atts {
1535 1362 * Optional. An array of attributes for rendering.
1536 - *
1537 1363 * @type string $html 'span' or 'div'. Default 'span'.
1538 1364 * @type bool $bg Whether to add a background color or not. Default false.
1539 1365 * }
1540 1366 *
@@ -1584,13 +1410,12 @@
1584 1410 );
1585 1411
1586 1412 // Determine the icon to be used.
1587 1413 $icon = $icons[''];
1588 -
1589 1414 if ( count( $categories ) === 1 ) {
1590 1415 $category = reset( $categories );
1591 - $icon = $icons[ $category ] ?? $icon;
1592 - } elseif ( $categories ) {
1416 + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1417 + } elseif ( ! empty( $categories ) ) {
1593 1418 $icons = array_intersect_key( $icons, array_flip( $categories ) );
1594 1419 $icon = reset( $icons );
1595 1420 }
1596 1421
@@ -1595,13 +1420,12 @@
1595 1420 }
1596 1421
1597 1422 // Prepare variables for output.
1598 1423 $icon_name = $icon[0];
1599 - $bg_color = $icon[1] ?? '';
1424 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1600 1425
1601 1426 // Render the icon.
1602 1427 echo '<span class="frm-category-icon frm-icon-wrapper"';
1603 -
1604 1428 if ( $bg_color && $atts['bg'] ) {
1605 1429 echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1606 1430 }
1607 1431 echo '>';
@@ -1615,9 +1439,8 @@
1615 1439 * @since 4.02
1616 1440 *
1617 1441 * @param array $template Template details.
1618 1442 * @param array $args Additional arguments.
1619 - *
1620 1443 * @return array The link attributes.
1621 1444 */
1622 1445 public static function get_template_install_link( $template, $args ) {
1623 1446 $defaults = array(
@@ -1649,9 +1472,8 @@
1649 1472 *
1650 1473 * @since 4.02.02
1651 1474 *
1652 1475 * @param array $args
1653 - *
1654 1476 * @return bool
1655 1477 */
1656 1478 public static function plan_is_allowed( $args ) {
1657 1479 if ( empty( $args['license_type'] ) ) {
@@ -1670,9 +1492,8 @@
1670 1492 foreach ( $plans as $plan ) {
1671 1493 if ( $included || $plan === $license_type ) {
1672 1494 break;
1673 1495 }
1674 -
1675 1496 $included = $plan === $plan_required;
1676 1497 }
1677 1498
1678 1499 return $included;
@@ -1682,16 +1503,11 @@
1682 1503 * If a template or add-on cannot be installed, show a message
1683 1504 * about which plan is required.
1684 1505 *
1685 1506 * @since 4.0
1686 - *
1687 - * @param string $requires
1688 - * @param string $link
1689 - *
1690 - * @return void
1691 1507 */
1692 1508 public static function show_plan_required( $requires, $link ) {
1693 - if ( ! $requires ) {
1509 + if ( empty( $requires ) ) {
1694 1510 return;
1695 1511 }
1696 1512
1697 1513 ?>
@@ -1707,9 +1523,8 @@
1707 1523 /**
1708 1524 * @since 4.0
1709 1525 *
1710 1526 * @param array $item
1711 - *
1712 1527 * @return false|string
1713 1528 */
1714 1529 public static function get_plan_required( &$item ) {
1715 1530 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
@@ -1720,9 +1535,12 @@
1720 1535
1721 1536 foreach ( $item['categories'] as $k => $category ) {
1722 1537 if ( in_array( $category, $plans, true ) ) {
1723 1538 unset( $item['categories'][ $k ] );
1724 - return self::convert_legacy_package_names( $category );
1539 +
1540 + $category = self::convert_legacy_package_names( $category );
1541 +
1542 + return $category;
1725 1543 }
1726 1544 }
1727 1545
1728 1546 return false;
@@ -1731,11 +1549,9 @@
1731 1549 /**
1732 1550 * Converts legacy package names to the current standard package name.
1733 1551 *
1734 1552 * @since 6.15
1735 - *
1736 1553 * @param string $package_name
1737 - *
1738 1554 * @return string The updated package name.
1739 1555 */
1740 1556 public static function convert_legacy_package_names( $package_name ) {
1741 1557 if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) {
@@ -1750,17 +1566,17 @@
1750 1566 *
1751 1567 * @since 6.15
1752 1568 *
1753 1569 * @param array $args
1754 - *
1755 1570 * @return array
1756 1571 */
1757 1572 public static function get_license_types( $args = array() ) {
1758 - $defaults = array(
1573 + $defaults = array(
1759 1574 'include_all' => true,
1760 1575 'case_lower' => false,
1761 1576 );
1762 - $args = wp_parse_args( $args, $defaults );
1577 + $args = wp_parse_args( $args, $defaults );
1578 +
1763 1579 $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' );
1764 1580
1765 1581 if ( $args['include_all'] ) {
1766 1582 $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types );
@@ -1782,9 +1598,10 @@
1782 1598 *
1783 1599 * @return array An array of warnings or an empty array.
1784 1600 */
1785 1601 public static function check_for_warnings( $values ) {
1786 - $warnings = array();
1602 + $warnings = array();
1603 +
1787 1604 $redirect_warning = self::check_redirect_url_for_unsafe_params( $values );
1788 1605
1789 1606 if ( $redirect_warning ) {
1790 1607 $warnings[] = $redirect_warning;
@@ -1829,13 +1646,11 @@
1829 1646 * @return array An array of params whose names are reserved words or an empty array.
1830 1647 */
1831 1648 private static function get_unsafe_params( $url ) {
1832 1649 $redirect_components = parse_url( $url );
1833 -
1834 1650 if ( empty( $redirect_components['query'] ) ) {
1835 1651 return array();
1836 1652 }
1837 -
1838 1653 parse_str( $redirect_components['query'], $redirect_params );
1839 1654 $redirect_param_names = array_keys( $redirect_params );
1840 1655 $reserved_words = self::reserved_words();
1841 1656 $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words );
@@ -1861,17 +1676,17 @@
1861 1676 if ( $count === 0 ) {
1862 1677 return false;
1863 1678 }
1864 1679
1865 - if ( $count === 1 ) {
1680 + if ( $count == 1 ) {
1866 1681 /* translators: %s: the name of a single parameter in the redirect URL */
1867 - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1682 + return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link;
1868 1683 }
1869 1684
1870 1685 $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect );
1871 1686
1872 1687 /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */
1873 - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1688 + return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link;
1874 1689 }
1875 1690
1876 1691 /**
1877 1692 * Returns an array of common reserved words in WordPress.
@@ -1937,19 +1752,17 @@
1937 1752 * @since 5.0.16
1938 1753 *
1939 1754 * @param string $url
1940 1755 * @param int $form_id
1941 - *
1942 1756 * @return string
1943 1757 */
1944 1758 public static function maybe_add_sanitize_url_attr( $url, $form_id ) {
1945 - if ( ! str_contains( $url, '[' ) ) {
1759 + if ( false === strpos( $url, '[' ) ) {
1946 1760 // Do nothing if no shortcodes are detected.
1947 1761 return $url;
1948 1762 }
1949 1763
1950 1764 $parsed = wp_parse_url( $url );
1951 -
1952 1765 if ( empty( $parsed['query'] ) ) {
1953 1766 // Do nothing if no query can be detected in the url string.
1954 1767 return $url;
1955 1768 }
@@ -1955,10 +1768,10 @@
1955 1768 }
1956 1769
1957 1770 $original_query = $parsed['query'];
1958 1771 $query = $parsed['query'];
1959 - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id );
1960 1772
1773 + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id );
1961 1774 if ( empty( $shortcodes[0] ) ) {
1962 1775 // No shortcodes found, do nothing.
1963 1776 return $url;
1964 1777 }
@@ -1970,21 +1783,20 @@
1970 1783 // Skip if shortcodes.
1971 1784 continue;
1972 1785 }
1973 1786
1974 - if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) {
1787 + if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) {
1975 1788 // A sanitize option is already set so leave it alone.
1976 1789 continue;
1977 1790 }
1978 1791
1979 1792 $new_shortcode = '[' . $shortcodes[2][ $key ];
1980 -
1981 1793 if ( $options ) {
1982 1794 $new_shortcode .= ' ' . $options;
1983 1795 }
1796 + $new_shortcode .= ' sanitize_url=1]';
1984 1797
1985 - $new_shortcode .= ' sanitize_url=1]';
1986 - $query = str_replace( $shortcode, $new_shortcode, $query );
1798 + $query = str_replace( $shortcode, $new_shortcode, $query );
1987 1799 }//end foreach
1988 1800
1989 1801 if ( $query === $original_query ) {
1990 1802 return $url;
@@ -2015,9 +1827,8 @@
2015 1827 *
2016 1828 * @since 6.16
2017 1829 *
2018 1830 * @param string $classname
2019 - *
2020 1831 * @return string
2021 1832 */
2022 1833 public static function sanitize_layout_class( $classname ) {
2023 1834 // Strip out any percent-encoded characters.
@@ -2023,9 +1834,11 @@
2023 1834 // Strip out any percent-encoded characters.
2024 1835 $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
2025 1836
2026 1837 // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'.
2027 - return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1838 + $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1839 +
1840 + return $sanitized;
2028 1841 }
2029 1842
2030 1843 /**
2031 1844 * Returns true if the preview should be blocked.
@@ -2032,9 +1845,8 @@
2032 1845 *
2033 1846 * @since 6.20
2034 1847 *
2035 1848 * @param string $form_key
2036 - *
2037 1849 * @return bool
2038 1850 */
2039 1851 public static function should_block_preview( $form_key ) {
2040 1852 $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' );
@@ -2045,9 +1857,10 @@
2045 1857 *
2046 1858 * @param bool $should_block
2047 1859 * @param string $form_key
2048 1860 */
2049 - return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key );
1861 + $should_block = (bool) apply_filters( 'frm_block_preview', $should_block, $form_key );
1862 + return $should_block;
2050 1863 }
2051 1864
2052 1865 /**
2053 1866 * Checks if the form is loaded by API.
@@ -2057,13 +1870,11 @@
2057 1870 * @return bool
2058 1871 */
2059 1872 public static function form_is_loaded_by_api() {
2060 1873 global $frm_vars;
2061 -
2062 1874 if ( ! empty( $frm_vars['inplace_edit'] ) ) {
2063 1875 return true;
2064 1876 }
2065 -
2066 1877 return self::is_formidable_api_form() || self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview();
2067 1878 }
2068 1879
2069 1880 /**
@@ -2090,19 +1901,18 @@
2090 1901 * @return bool
2091 1902 */
2092 1903 private static function is_gutenberg_editor() {
2093 1904 $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
2094 -
2095 - if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) {
1905 + if ( false !== strpos( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) {
2096 1906 return true;
2097 1907 }
2098 1908
2099 - if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) {
1909 + global $pagenow;
1910 + if ( 'post.php' === $pagenow ) {
2100 1911 return true;
2101 1912 }
2102 1913
2103 - global $pagenow;
2104 - return 'post.php' === $pagenow;
1914 + return false;
2105 1915 }
2106 1916
2107 1917 /**
2108 1918 * @since 6.21
@@ -2114,10 +1924,9 @@
2114 1924 return false;
2115 1925 }
2116 1926
2117 1927 $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
2118 -
2119 - if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) {
1928 + if ( false !== strpos( $url, '/wp-json/frm/v2/forms/' ) ) {
2120 1929 // Prevent the honeypot from appearing for an API loaded form.
2121 1930 // This is to prevent conflicts where the script is not working.
2122 1931 return true;
2123 1932 }
@@ -2129,7 +1938,42 @@
2129 1938 return true;
2130 1939 }
2131 1940 }
2132 1941
1942 + return false;
1943 + }
1944 +
1945 + /**
1946 + * @since 3.0
1947 + * @deprecated 6.11
1948 + *
1949 + * @param array $atts
1950 + * @return void
1951 + */
1952 + public static function actions_dropdown( $atts ) {
1953 + _deprecated_function( __METHOD__, '6.11' );
1954 +
1955 + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
1956 + return;
1957 + }
1958 +
1959 + $status = $atts['status'];
1960 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1961 + $trash_link = self::delete_trash_info( $form_id, $status );
1962 + $links = self::get_action_links( $form_id, $status );
1963 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php';
1964 + }
1965 +
1966 + /**
1967 + * Check if Pro isn't up to date yet.
1968 + * If Pro is active but using a version earlier than v6.2 fallback to Pro for AJAX submit (so things don't all happen twice).
1969 + *
1970 + * @since 6.2
1971 + * @deprecated 6.20
1972 + *
1973 + * @return bool
1974 + */
1975 + public static function should_use_pro_for_ajax_submit() {
1976 + _deprecated_function( __METHOD__, '6.20' );
2133 1977 return false;
2134 1978 }
2135 1979 }