PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.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 +340 -237 6.36.16.1 View file →
@@ -5,8 +5,17 @@
5 5
6 6 class FrmFormsHelper {
7 7
8 8 /**
9 + * Store and re-use field type data for the insert_opt_html function (to avoid multiple calls to FrmField::all_field_selection).
10 + *
11 + * @since 6.10
12 + *
13 + * @var array|null
14 + */
15 + private static $field_type_data_for_insert_opt_html;
16 +
17 + /**
9 18 * @since 2.2.10
10 19 */
11 20 public static function form_error_class() {
12 21 return apply_filters( 'frm_form_error_class', 'frm_error_style' );
@@ -49,13 +58,13 @@
49 58 <select name="<?php echo esc_attr( $field_name ); ?>"
50 59 id="<?php echo esc_attr( $args['field_id'] ); ?>"
51 60 <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
52 61 <?php if ( $args['blank'] ) { ?>
53 - <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
62 + <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
54 63 <?php } ?>
55 64 <?php foreach ( $forms as $form ) { ?>
56 65 <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>>
57 - <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
66 + <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
58 67 </option>
59 68 <?php } ?>
60 69 </select>
61 70 <?php
@@ -61,13 +70,12 @@
61 70 <?php
62 71 }
63 72
64 73 /**
74 + * @since 2.0.6
65 75 * @param string $class
66 76 * @param string $param
67 - * @param array $add_html
68 - *
69 - * @since 2.0.6
77 + * @param array $add_html
70 78 */
71 79 public static function add_html_attr( $class, $param, &$add_html ) {
72 80 if ( ! empty( $class ) ) {
73 81 $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"';
@@ -74,9 +82,9 @@
74 82 }
75 83 }
76 84
77 85 /**
78 - * @param string|object|false $selected - The label for the placeholder, or the form object.
86 + * @param false|object|string $selected - The label for the placeholder, or the form object.
79 87 */
80 88 public static function form_switcher( $selected = false ) {
81 89 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
82 90 $forms = FrmForm::get_published_forms( $where );
@@ -91,15 +99,16 @@
91 99 unset( $args['id'] );
92 100 }
93 101
94 102 $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
95 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ) ) ) {
103 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) {
96 104 $args['frm_action'] = 'list';
97 105 $args['form'] = 0;
98 - } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
106 + } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) {
99 107 $args['frm_action'] = 'edit';
100 108 } elseif ( FrmAppHelper::is_style_editor_page() ) {
101 - unset( $args['id'] ); // Avoid passing style into form switcher on style page.
109 + // Avoid passing style into form switcher on style page.
110 + unset( $args['id'] );
102 111 $query_args = array(
103 112 'page' => 'formidable-styles',
104 113 );
105 114 if ( $frm_action ) {
@@ -116,10 +125,10 @@
116 125 $form_id = $selected->id;
117 126 $selected = $selected->name;
118 127 }
119 128
120 - $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected;
121 - $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name );
129 + $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected;
130 + $name = '' === $name ? self::get_no_title_text() : strip_tags( $name );
122 131 $truncated_name = FrmAppHelper::truncate( $name, 25 );
123 132
124 133 if ( count( $forms ) < 2 ) {
125 134 ?>
@@ -151,8 +160,10 @@
151 160 array(
152 161 'input_id' => 'dropform',
153 162 'placeholder' => __( 'Search Forms', 'formidable' ),
154 163 'tosearch' => 'frm-dropdown-form',
164 + // Specify a value to avoid the $_REQUEST['s'] default value.
165 + 'value' => '',
155 166 )
156 167 );
157 168 ?>
158 169 </li>
@@ -171,9 +182,9 @@
171 182 $args['form'] = $form->id;
172 183 }
173 184
174 185 $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args );
175 - $form_name = empty( $form->name ) ? __( '(no title)', 'formidable' ) : $form->name;
186 + $form_name = empty( $form->name ) ? self::get_no_title_text() : $form->name;
176 187 ?>
177 188 <li class="frm-dropdown-form">
178 189 <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between">
179 190 <?php echo esc_html( $form_name ); ?>
@@ -190,9 +201,9 @@
190 201 </a>
191 202 </li>
192 203 <?php
193 204 unset( $form );
194 - }
205 + }//end foreach
195 206 ?>
196 207 </ul>
197 208 </div>
198 209 <?php
@@ -197,21 +208,11 @@
197 208 </div>
198 209 <?php
199 210 }
200 211
201 - /**
202 - * @since 3.05
203 - * @deprecated 4.0
204 - *
205 - * @param array $values - The form array
206 - */
207 - public static function builder_submit_button( $values ) {
208 - FrmDeprecated::builder_submit_button( $values );
209 - }
210 -
211 212 public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
212 - echo ( $sort_col == $col ) ? 'sorted' : 'sortable';
213 - echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc';
213 + echo $sort_col == $col ? 'sorted' : 'sortable';
214 + echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc';
214 215 }
215 216
216 217 /**
217 218 * @since 3.0
@@ -254,14 +255,16 @@
254 255 $settings_args['current_form'] = $args['form']->id;
255 256 }
256 257
257 258 $frm_settings = FrmAppHelper::get_settings( $settings_args );
258 - $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
259 + $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
259 260 return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args );
260 261 }
261 262
262 263 /**
263 264 * @param array $atts {
265 + * The success message details.
266 + *
264 267 * @type string $message
265 268 * @type stdClass $form
266 269 * @type int $entry_id
267 270 * @type string $class
@@ -284,9 +287,9 @@
284 287 if ( ! empty( $values ) ) {
285 288 $post_values = $values;
286 289 } else {
287 290 $values = array();
288 - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
291 + $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 292 }
290 293
291 294 $defaults = array(
292 295 'name' => '',
@@ -315,9 +318,9 @@
315 318 }
316 319 unset( $defaults );
317 320
318 321 if ( ! isset( $values['form_key'] ) ) {
319 - $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
322 + $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
320 323 }
321 324
322 325 $values = self::fill_default_opts( $values, false, $post_values );
323 326 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -347,17 +350,17 @@
347 350 $defaults = self::get_default_opts();
348 351 foreach ( $defaults as $var => $default ) {
349 352 if ( is_array( $default ) ) {
350 353 if ( ! isset( $values[ $var ] ) ) {
351 - $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
354 + $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
352 355 }
353 356
354 357 foreach ( $default as $k => $v ) {
355 - $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 );
358 + $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 );
356 359
357 360 if ( is_array( $v ) ) {
358 361 foreach ( $v as $k1 => $v1 ) {
359 - $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 );
362 + $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 );
360 363 unset( $k1, $v1 );
361 364 }
362 365 }
363 366
@@ -363,13 +366,13 @@
363 366
364 367 unset( $k, $v );
365 368 }
366 369 } else {
367 - $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
370 + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default );
368 371 }
369 372
370 373 unset( $var, $default );
371 - }
374 + }//end foreach
372 375
373 376 return $values;
374 377 }
375 378
@@ -401,12 +404,11 @@
401 404 );
402 405 }
403 406
404 407 /**
408 + * @since 2.0.6
405 409 * @param array $options
406 410 * @param array $values
407 - *
408 - * @since 2.0.6
409 411 */
410 412 public static function fill_form_options( &$options, $values ) {
411 413 $defaults = self::get_default_opts();
412 414 foreach ( $defaults as $var => $default ) {
@@ -418,20 +420,20 @@
418 420 /**
419 421 * @param string $loc
420 422 */
421 423 public static function get_default_html( $loc ) {
422 - if ( $loc == 'submit' ) {
424 + if ( $loc === 'submit' ) {
423 425 $draft_link = self::get_draft_link();
424 426 $start_over = self::get_start_over_shortcode();
425 427 $default_html = <<<SUBMIT_HTML
426 -<div class="frm_submit">
428 +<div class="frm_submit frm_flex">
429 +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
427 430 [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button]
428 -<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
429 431 $draft_link
430 432 $start_over
431 433 </div>
432 434 SUBMIT_HTML;
433 - } elseif ( $loc == 'before' ) {
435 + } elseif ( $loc === 'before' ) {
434 436 $default_html = <<<BEFORE_HTML
435 437 <legend class="frm_screen_reader">[form_name]</legend>
436 438 [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
437 439 [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
@@ -443,9 +445,9 @@
443 445 return $default_html;
444 446 }
445 447
446 448 public static function get_draft_link() {
447 - $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
449 + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
448 450
449 451 return $link;
450 452 }
451 453
@@ -478,10 +480,10 @@
478 480
479 481 $classes = apply_filters( 'frm_submit_button_class', array(), $form );
480 482 if ( ! empty( $classes ) ) {
481 483 $classes = implode( ' ', $classes );
482 - $button_class = ' class="frm_button_submit';
483 - if ( strpos( $button_parts[0], $button_class ) !== false ) {
484 + $button_class = 'frm_button_submit';
485 + if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
484 486 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
485 487 } else {
486 488 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
487 489 }
@@ -496,51 +498,51 @@
496 498 * @since 4.0
497 499 */
498 500 public static function html_shortcodes() {
499 501 $codes = array(
500 - 'id' => array(
502 + 'id' => array(
501 503 'label' => __( 'Field ID', 'formidable' ),
502 504 'class' => 'show_field_custom_html',
503 505 ),
504 - 'key' => array(
506 + 'key' => array(
505 507 'label' => __( 'Field Key', 'formidable' ),
506 508 'class' => 'show_field_custom_html',
507 509 ),
508 - 'field_name' => array(
510 + 'field_name' => array(
509 511 'label' => __( 'Field Name', 'formidable' ),
510 512 'class' => 'show_field_custom_html',
511 513 ),
512 - 'description' => array(
514 + 'description' => array(
513 515 'label' => __( 'Field Description', 'formidable' ),
514 516 'class' => 'show_field_custom_html',
515 517 ),
516 - 'label_position' => array(
518 + 'label_position' => array(
517 519 'label' => __( 'Label Position', 'formidable' ),
518 520 'class' => 'show_field_custom_html',
519 521 ),
520 - 'required_label' => array(
522 + 'required_label' => array(
521 523 'label' => __( 'Required Label', 'formidable' ),
522 524 'class' => 'show_field_custom_html',
523 525 ),
524 - 'input' => array(
526 + 'input' => array(
525 527 'label' => __( 'Input Field', 'formidable' ),
526 528 'class' => 'show_field_custom_html',
527 529 ),
528 - 'input opt=1' => array(
530 + 'input opt=1' => array(
529 531 'label' => __( 'Single Option', 'formidable' ),
530 532 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
531 533 'class' => 'show_field_custom_html',
532 534 ),
533 - 'input label=0' => array(
535 + 'input label=0' => array(
534 536 'label' => __( 'Hide Option Label', 'formidable' ),
535 537 'class' => 'show_field_custom_html',
536 538 ),
537 - 'required_class' => array(
539 + 'required_class' => array(
538 540 'label' => __( 'Required Class', 'formidable' ),
539 541 'title' => __( 'Add class name if field is required', 'formidable' ),
540 542 'class' => 'show_field_custom_html',
541 543 ),
542 - 'error_class' => array(
544 + 'error_class' => array(
543 545 'label' => __( 'Error Class', 'formidable' ),
544 546 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
545 547 'class' => 'show_field_custom_html',
546 548 ),
@@ -561,13 +563,13 @@
561 563 'label' => __( 'Delete Entry Link', 'formidable' ),
562 564 'class' => 'show_before_html show_after_html',
563 565 ),
564 566
565 - 'button_label' => array(
567 + 'button_label' => array(
566 568 'label' => __( 'Button Label', 'formidable' ),
567 569 'class' => 'show_submit_html',
568 570 ),
569 - 'button_action' => array(
571 + 'button_action' => array(
570 572 'label' => __( 'Button Hook', 'formidable' ),
571 573 'class' => 'show_submit_html',
572 574 ),
573 575 );
@@ -579,13 +581,15 @@
579 581 }
580 582
581 583 /**
582 584 * @since 4.0
585 + *
583 586 * @param array $args
587 + * @return void
584 588 */
585 589 public static function insert_opt_html( $args ) {
586 590 $class = isset( $args['class'] ) ? $args['class'] : '';
587 - $fields = FrmField::all_field_selection();
591 + $fields = self::get_field_type_data_for_insert_opt_html();
588 592 $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
589 593
590 594 self::prepare_field_type( $field );
591 595
@@ -600,22 +604,35 @@
600 604
601 605 if ( 'url' === $args['type'] ) {
602 606 $class .= ' frm_insert_url';
603 607 }
608 +
609 + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 );
610 + if ( isset( $field['icon'] ) ) {
611 + $icon = FrmAppHelper::icon_by_class(
612 + $field['icon'],
613 + array(
614 + 'aria-hidden' => 'true',
615 + 'echo' => false,
616 + )
617 + );
618 + } else {
619 + $icon = '';
620 + }
604 621 ?>
605 622 <li class="<?php echo esc_attr( $class ); ?>">
606 - <a href="javascript:void(0)" class="frmids frm_insert_code"
607 - data-code="<?php echo esc_attr( $args['id'] ); ?>">
608 - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
609 - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
623 + <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>">
624 + <?php
625 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
626 + echo esc_html( $truncated_name );
627 + ?>
610 628 <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
611 629 </a>
612 - <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden"
613 - data-code="<?php echo esc_attr( $args['key'] ); ?>">
614 - <?php if ( isset( $field['icon'] ) ) { ?>
615 - <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
616 - <?php } ?>
617 - <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
630 + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>">
631 + <?php
632 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
633 + echo esc_html( $truncated_name );
634 + ?>
618 635 <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
619 636 </a>
620 637 </li>
621 638 <?php
@@ -621,8 +638,23 @@
621 638 <?php
622 639 }
623 640
624 641 /**
642 + * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up.
643 + * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection.
644 + *
645 + * @since 6.10
646 + *
647 + * @return array
648 + */
649 + private static function get_field_type_data_for_insert_opt_html() {
650 + if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) {
651 + self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection();
652 + }
653 + return self::$field_type_data_for_insert_opt_html;
654 + }
655 +
656 + /**
625 657 * @since 4.0
626 658 * @param array $args
627 659 */
628 660 public static function insert_code_html( $args ) {
@@ -654,8 +686,11 @@
654 686 * Some field types in add-ons may have been added with only
655 687 * a field type and name.
656 688 *
657 689 * @since 4.0
690 + *
691 + * @param array|string $field
692 + * @return void
658 693 */
659 694 public static function prepare_field_type( &$field ) {
660 695 if ( ! is_array( $field ) ) {
661 696 $field = array(
@@ -669,9 +704,11 @@
669 704 * Automatically add end section fields if they don't exist (2.0 migration)
670 705 *
671 706 * @since 2.0
672 707 *
673 - * @param boolean $reset_fields
708 + * @param object $form
709 + * @param array $fields
710 + * @param bool $reset_fields
674 711 */
675 712 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
676 713 if ( empty( $fields ) ) {
677 714 return;
@@ -683,9 +720,9 @@
683 720 $add_order = 0;
684 721 $last_field = false;
685 722 foreach ( $fields as $field ) {
686 723 if ( $prev_order === $field->field_order ) {
687 - $add_order ++;
724 + ++$add_order;
688 725 }
689 726
690 727 if ( $add_order ) {
691 728 $reset_fields = true;
@@ -712,14 +749,14 @@
712 749 }
713 750
714 751 // There is already an end section here, so there is no need to create one.
715 752 $open = false;
716 - }
753 + }//end switch
717 754 $prev_order = $field->field_order;
718 755
719 756 $last_field = $field;
720 757 unset( $field );
721 - }
758 + }//end foreach
722 759
723 760 self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
724 761 }
725 762
@@ -735,14 +772,14 @@
735 772 $end_section_values['field_order'] = $field->field_order + 1;
736 773
737 774 FrmField::create( $end_section_values );
738 775
739 - if ( $move == 'move' ) {
776 + if ( $move === 'move' ) {
740 777 // bump the order of current field unless we're at the end of the form
741 778 FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
742 779 }
743 780
744 - $add_order += 2;
781 + $add_order += 2;
745 782 $open = false;
746 783 $reset_fields = true;
747 784 }
748 785
@@ -756,9 +793,9 @@
756 793 if ( $code === 'form_name' ) {
757 794 $replace_with = $form->name;
758 795 } elseif ( $code === 'form_description' ) {
759 796 $replace_with = FrmAppHelper::use_wpautop( $form->description );
760 - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
797 + } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) {
761 798 $replace_with = FrmAppHelper::simple_get( 'entry' );
762 799 } else {
763 800 $replace_with = '';
764 801 }
@@ -765,12 +802,12 @@
765 802
766 803 FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
767 804 }
768 805
769 - //replace [form_key]
806 + // Replace [form_key].
770 807 $html = str_replace( '[form_key]', $form->form_key, $html );
771 808
772 - //replace [frmurl]
809 + // Replace [frmurl].
773 810 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
774 811
775 812 if ( strpos( $html, '[button_label]' ) ) {
776 813 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -813,18 +850,23 @@
813 850 * If the Formidable styling isn't being loaded,
814 851 * use inline styling to hide the element
815 852 *
816 853 * @since 2.03.05
854 + *
855 + * @return void
817 856 */
818 857 public static function maybe_hide_inline() {
819 858 $frm_settings = FrmAppHelper::get_settings();
820 - if ( $frm_settings->load_style == 'none' ) {
859 + if ( $frm_settings->load_style === 'none' ) {
821 860 echo ' style="display:none;"';
822 - } elseif ( $frm_settings->load_style == 'dynamic' ) {
861 + } elseif ( $frm_settings->load_style === 'dynamic' ) {
823 862 FrmStylesController::enqueue_style();
824 863 }
825 864 }
826 865
866 + /**
867 + * @return string|null
868 + */
827 869 public static function get_form_style_class( $form = false ) {
828 870 $style = self::get_form_style( $form );
829 871 $class = ' with_frm_style';
830 872
@@ -830,11 +872,10 @@
830 872
831 873 if ( empty( $style ) ) {
832 874 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
833 875 return $class;
834 - } else {
835 - return;
836 876 }
877 + return;
837 878 }
838 879
839 880 // If submit button needs to be inline or centered.
840 881 if ( is_object( $form ) ) {
@@ -879,9 +920,9 @@
879 920
880 921 /**
881 922 * Returns appropriate class if form has top labels
882 923 *
883 - * @param $form
924 + * @param array $form
884 925 *
885 926 * @return string
886 927 */
887 928 private static function maybe_align_fields_top( $form ) {
@@ -890,9 +931,9 @@
890 931
891 932 /**
892 933 * Determine if a form has fields with top labels so submit button can be aligned properly
893 934 *
894 - * @param $form
935 + * @param array $form
895 936 *
896 937 * @return bool
897 938 */
898 939 private static function form_has_top_labels( $form ) {
@@ -904,9 +945,10 @@
904 945 if ( count( $fields ) <= 0 ) {
905 946 return false;
906 947 }
907 948
908 - $fields = array_reverse( $fields ); // start from the fields closest to the submit button
949 + // Start from the fields closest to the submit button.
950 + $fields = array_reverse( $fields );
909 951 foreach ( $fields as $field ) {
910 952 $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
911 953 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
912 954 if ( $has_input ) {
@@ -919,10 +961,10 @@
919 961
920 962 /**
921 963 * Check if a field's label position is set to "top"
922 964 *
923 - * @param $field
924 - * @param $form
965 + * @param array $field
966 + * @param bool|object|string $form
925 967 *
926 968 * @return bool
927 969 */
928 970 private static function field_has_top_label( $field, $form ) {
@@ -931,10 +973,9 @@
931 973 return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
932 974 }
933 975
934 976 /**
935 - * @param object|string|boolean $form
936 - *
977 + * @param array|bool|object|string $form
937 978 * @return string
938 979 */
939 980 public static function get_form_style( $form ) {
940 981 $style = 1;
@@ -939,12 +980,14 @@
939 980 public static function get_form_style( $form ) {
940 981 $style = 1;
941 982 if ( empty( $form ) || 'default' === $form ) {
942 983 return $style;
943 - } elseif ( is_object( $form ) && $form->parent_form_id ) {
984 + }
985 +
986 + if ( is_object( $form ) && $form->parent_form_id ) {
944 987 // get the parent form if this is a child
945 988 $form = $form->parent_form_id;
946 - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
989 + } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
947 990 $form = $form['parent_form_id'];
948 991 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
949 992 $style = $form['custom_style'];
950 993 }
@@ -952,9 +995,9 @@
952 995 if ( $form && is_string( $form ) ) {
953 996 $form = FrmForm::getOne( $form );
954 997 }
955 998
956 - $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
999 + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
957 1000
958 1001 return $style;
959 1002 }
960 1003
@@ -960,11 +1003,10 @@
960 1003
961 1004 /**
962 1005 * Display the validation error messages when an entry is submitted
963 1006 *
964 - * @param array $args - includes img, errors
965 - *
966 1007 * @since 2.0.6
1008 + * @param array $args Includes img, errors.
967 1009 */
968 1010 public static function show_errors( $args ) {
969 1011 $invalid_msg = self::get_invalid_error_message( $args );
970 1012
@@ -988,11 +1030,10 @@
988 1030 * Display the error message in the front-end along with the image if set
989 1031 * The image was removed from the styling settings, but it may still be set with a hook
990 1032 * If the message in the global settings is empty, show every validation message in the error box
991 1033 *
992 - * @param array $args - includes img, errors, and show_img
993 - *
994 1034 * @since 2.0.6
1035 + * @param array $args Includes img, errors, and show_img.
995 1036 */
996 1037 public static function show_error( $args ) {
997 1038 // remove any blank messages
998 1039 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -998,9 +1039,9 @@
998 1039 $args['errors'] = array_filter( (array) $args['errors'] );
999 1040
1000 1041 $line_break_first = $args['show_img'];
1001 1042 foreach ( $args['errors'] as $error_key => $error ) {
1002 - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key == 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1043 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1003 1044 continue;
1004 1045 }
1005 1046
1006 1047 $id = str_replace( 'field', 'field_', $error_key );
@@ -1006,9 +1047,9 @@
1006 1047 $id = str_replace( 'field', 'field_', $error_key );
1007 1048 echo '<div id="' . esc_attr( $id ) . '_error">';
1008 1049
1009 1050 if ( $args['show_img'] && ! empty( $args['img'] ) ) {
1010 - echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />';
1051 + echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />';
1011 1052 } else {
1012 1053 $args['show_img'] = true;
1013 1054 }
1014 1055
@@ -1031,21 +1072,8 @@
1031 1072
1032 1073 /**
1033 1074 * @since 3.0
1034 1075 */
1035 - public static function actions_dropdown( $atts ) {
1036 - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
1037 - $status = $atts['status'];
1038 - $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1039 - $trash_link = self::delete_trash_info( $form_id, $status );
1040 - $links = self::get_action_links( $form_id, $status );
1041 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
1042 - }
1043 - }
1044 -
1045 - /**
1046 - * @since 3.0
1047 - */
1048 1076 public static function get_action_links( $form_id, $form ) {
1049 1077 if ( ! is_object( $form ) ) {
1050 1078 $form = FrmForm::getOne( $form_id );
1051 1079 }
@@ -1074,13 +1102,17 @@
1074 1102 );
1075 1103 }
1076 1104
1077 1105 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
1078 - }
1106 + }//end if
1079 1107
1080 1108 return $actions;
1081 1109 }
1082 1110
1111 + /**
1112 + * @param int|object|string $data
1113 + * @return string
1114 + */
1083 1115 public static function edit_form_link( $data ) {
1084 1116 $form_id = self::get_form_id_from_data( $data );
1085 1117
1086 1118 if ( ! $form_id ) {
@@ -1091,19 +1123,34 @@
1091 1123 $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1092 1124 return $link;
1093 1125 }
1094 1126
1127 + /**
1128 + * Returns a text used when no title is set.
1129 + *
1130 + * @since 6.16.1
1131 + *
1132 + * @return string
1133 + */
1134 + public static function get_no_title_text() {
1135 + return __( '(no title)', 'formidable' );
1136 + }
1137 +
1138 + /**
1139 + * @param int|object|string $data
1140 + * @return string
1141 + */
1095 1142 public static function edit_form_link_label( $data ) {
1096 1143 $name = self::get_form_name_from_data( $data );
1097 1144 if ( ! $name ) {
1098 - return __( '(no title)', 'formidable' );
1145 + return self::get_no_title_text();
1099 1146 }
1100 1147 return FrmAppHelper::truncate( $name, 40 );
1101 1148 }
1102 1149
1103 1150 /**
1104 - * @param mixed data
1105 - * @return int
1151 + * @param int|object|string $data
1152 + * @return int|string
1106 1153 */
1107 1154 private static function get_form_id_from_data( $data ) {
1108 1155 if ( is_object( $data ) ) {
1109 1156 $form_id = $data->id;
@@ -1148,11 +1195,11 @@
1148 1195 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1149 1196 }
1150 1197
1151 1198 $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1152 - if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1199 + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1153 1200 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1154 - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1201 + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1155 1202 }
1156 1203
1157 1204 $link .= '>' . $label . '</a>';
1158 1205 }
@@ -1165,9 +1212,9 @@
1165 1212 */
1166 1213 public static function delete_trash_info( $id, $status ) {
1167 1214 $labels = self::delete_trash_links( $id );
1168 1215
1169 - if ( 'trash' == $status ) {
1216 + if ( 'trash' === $status ) {
1170 1217 $info = $labels['restore'];
1171 1218 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1172 1219 if ( EMPTY_TRASH_DAYS ) {
1173 1220 $info = $labels['trash'];
@@ -1183,9 +1230,9 @@
1183 1230
1184 1231 /**
1185 1232 * @since 3.0
1186 1233 */
1187 - private static function delete_trash_links( $id ) {
1234 + public static function delete_trash_links( $id ) {
1188 1235 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1189 1236 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1190 1237
1191 1238 return array(
@@ -1222,33 +1269,33 @@
1222 1269 * @since 3.0
1223 1270 */
1224 1271 public static function css_classes() {
1225 1272 $classes = array(
1226 - 'frm_total' => array(
1273 + 'frm_total' => array(
1227 1274 'label' => __( 'Total', 'formidable' ),
1228 1275 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1229 1276 ),
1230 - 'frm_total_big' => array(
1277 + 'frm_total_big' => array(
1231 1278 'label' => __( 'Big Total', 'formidable' ),
1232 1279 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1233 1280 ),
1234 - 'frm_scroll_box' => array(
1281 + 'frm_scroll_box' => array(
1235 1282 'label' => __( 'Scroll Box', 'formidable' ),
1236 1283 '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' ),
1237 1284 ),
1238 - 'frm_first' => array(
1285 + 'frm_first' => array(
1239 1286 'label' => __( 'First', 'formidable' ),
1240 1287 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1241 1288 ),
1242 - 'frm_alignright' => __( 'Right', 'formidable' ),
1243 - 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1244 - 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1245 - 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1289 + 'frm_alignright' => __( 'Right', 'formidable' ),
1290 + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1291 + 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1292 + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1246 1293 'frm_color_block' => array(
1247 1294 'label' => __( 'Color Block', 'formidable' ),
1248 1295 'title' => __( 'Add a background color to the field or section.', 'formidable' ),
1249 1296 ),
1250 - 'frm_capitalize' => array(
1297 + 'frm_capitalize' => array(
1251 1298 'label' => __( 'Capitalize', 'formidable' ),
1252 1299 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1253 1300 ),
1254 1301 );
@@ -1291,9 +1338,9 @@
1291 1338 'trash' => __( 'Trash', 'formidable' ),
1292 1339 'publish' => __( 'Published', 'formidable' ),
1293 1340 );
1294 1341
1295 - if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1342 + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1296 1343 $status = 'publish';
1297 1344 }
1298 1345
1299 1346 $name = $nice_names[ $status ];
@@ -1301,101 +1348,94 @@
1301 1348 return $name;
1302 1349 }
1303 1350
1304 1351 /**
1305 - * @param array $categories
1352 + * Renders a template icon based on the given categories.
1353 + *
1354 + * @param array $categories The categories to render the icon for.
1306 1355 * @param array $atts {
1307 - * @type string $html 'span' or 'div'.
1308 - * @type boolean $bg Whether to add a bg color or not.
1356 + * Optional. An array of attributes for rendering.
1357 + * @type string $html 'span' or 'div'. Default 'span'.
1358 + * @type bool $bg Whether to add a background color or not. Default false.
1309 1359 * }
1310 1360 *
1311 1361 * @return void
1312 1362 */
1313 1363 public static function template_icon( $categories, $atts = array() ) {
1364 + // Define defaults.
1314 1365 $defaults = array(
1315 - 'html' => 'span',
1316 - 'bg' => false,
1366 + 'bg' => true,
1317 1367 );
1318 - $atts = array_merge( $defaults, $atts );
1368 + $atts = array_merge( $defaults, $atts );
1319 1369
1320 - $ignore = self::ignore_template_categories();
1370 + // Filter out ignored categories.
1371 + $ignore = self::get_license_types();
1321 1372 $categories = array_diff( $categories, $ignore );
1322 1373
1374 + // Define icons mapping.
1323 1375 $icons = array(
1324 - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1325 - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1326 - 'User Registration' => array( 'register', 'var(--pink)' ),
1376 + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1377 + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1378 + 'User Registration' => array( 'register', 'var(--pink)' ),
1327 1379 'Registration and Signup' => array( 'register', 'var(--pink)' ),
1328 - 'PayPal' => array( 'paypal' ),
1329 - 'Stripe' => array( 'credit_card', 'var(--green)' ),
1330 - 'Twilio' => array( 'sms' ),
1331 - 'Payment' => array( 'credit_card' ),
1332 - 'Order Form' => array( 'product' ),
1333 - 'Finance' => array( 'total' ),
1334 - 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1335 - 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1336 - 'Real Estate' => array( 'house' ),
1337 - 'Nonprofit' => array( 'heart_solid' ),
1338 - 'Calculator' => array( 'calculator', 'var(--purple)' ),
1339 - 'Quiz' => array( 'percent' ),
1340 - 'Registrations' => array( 'address_card' ),
1341 - 'Customer Service' => array( 'users_solid' ),
1342 - 'Education' => array( 'pencil' ),
1343 - 'Marketing' => array( 'eye' ),
1344 - 'Feedback' => array( 'smile' ),
1345 - 'Business Operations' => array( 'case' ),
1346 - 'Contact Form' => array( 'email' ),
1347 - 'Conversational Forms' => array( 'chat_forms' ),
1348 - 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1349 - 'Application' => array( 'align_right' ),
1350 - 'Signature' => array( 'signature' ),
1351 - '' => array( 'align_right' ),
1380 + 'PayPal' => array( 'paypal' ),
1381 + 'Stripe' => array( 'credit_card', 'var(--green)' ),
1382 + 'Twilio' => array( 'sms' ),
1383 + 'Payment' => array( 'credit_card' ),
1384 + 'Order Form' => array( 'product' ),
1385 + 'Finance' => array( 'total' ),
1386 + 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1387 + 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1388 + 'Real Estate' => array( 'house' ),
1389 + 'Nonprofit' => array( 'heart_solid' ),
1390 + 'Calculator' => array( 'calculator', 'var(--purple)' ),
1391 + 'Quiz' => array( 'percent' ),
1392 + 'Registrations' => array( 'address_card' ),
1393 + 'Customer Service' => array( 'users_solid' ),
1394 + 'Education' => array( 'pencil' ),
1395 + 'Marketing' => array( 'eye' ),
1396 + 'Feedback' => array( 'smile' ),
1397 + 'Business Operations' => array( 'case' ),
1398 + 'Contact Form' => array( 'email' ),
1399 + 'Conversational Forms' => array( 'chat_forms' ),
1400 + 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1401 + 'Application' => array( 'align_right' ),
1402 + 'Signature' => array( 'signature' ),
1403 + '' => array( 'align_right' ),
1352 1404 );
1353 1405
1354 - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' );
1355 -
1406 + // Determine the icon to be used.
1356 1407 $icon = $icons[''];
1357 -
1358 1408 if ( count( $categories ) === 1 ) {
1359 1409 $category = reset( $categories );
1360 1410 $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1361 1411 } elseif ( ! empty( $categories ) ) {
1362 - foreach ( $icons as $cat => $icon ) {
1363 - if ( ! in_array( $cat, $categories ) ) {
1364 - unset( $icons[ $cat ] );
1365 - }
1366 - }
1367 - $icon = reset( $icons );
1412 + $icons = array_intersect_key( $icons, array_flip( $categories ) );
1413 + $icon = reset( $icons );
1368 1414 }
1369 1415
1370 - $bg = isset( $icon[1] ) ? $icon[1] : '';
1416 + // Prepare variables for output.
1417 + $icon_name = $icon[0];
1418 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1371 1419
1372 - if ( $atts['html'] === 'div' ) {
1373 - echo '<div class="frm-category-icon frm-icon-wrapper" role="button"';
1374 - } else {
1375 - echo '<span class="frm-inner-circle"';
1420 + // Render the icon.
1421 + echo '<span class="frm-category-icon frm-icon-wrapper"';
1422 + if ( $bg_color && $atts['bg'] ) {
1423 + echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1376 1424 }
1377 - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"';
1378 1425 echo '>';
1379 -
1380 - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' );
1381 - echo '<span class="frm_hidden">';
1382 - FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' );
1426 + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' );
1383 1427 echo '</span>';
1384 - echo '</' . esc_attr( $atts['html'] ) . '>';
1385 1428 }
1386 1429
1387 1430 /**
1388 - * @since 4.03.01
1431 + * Get template install link.
1389 1432 *
1390 - * @return array<string>
1391 - */
1392 - public static function ignore_template_categories() {
1393 - return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
1394 - }
1395 -
1396 - /**
1397 1433 * @since 4.02
1434 + *
1435 + * @param array $template Template details.
1436 + * @param array $args Additional arguments.
1437 + * @return array The link attributes.
1398 1438 */
1399 1439 public static function get_template_install_link( $template, $args ) {
1400 1440 $defaults = array(
1401 1441 'class' => 'install-now',
@@ -1431,9 +1471,8 @@
1431 1471 *
1432 1472 * @since 4.02.02
1433 1473 *
1434 1474 * @param array $args
1435 - *
1436 1475 * @return bool
1437 1476 */
1438 1477 public static function plan_is_allowed( $args ) {
1439 1478 if ( empty( $args['license_type'] ) ) {
@@ -1439,20 +1478,22 @@
1439 1478 if ( empty( $args['license_type'] ) ) {
1440 1479 return false;
1441 1480 }
1442 1481
1443 - $included = $args['license_type'] === strtolower( $args['plan_required'] );
1482 + $plans = array( 'free', 'personal', 'business', 'elite' );
1483 + $license_type = strtolower( $args['license_type'] );
1484 + $plan_required = strtolower( $args['plan_required'] );
1485 + $included = $license_type === $plan_required;
1444 1486
1445 - $plans = array( 'free', 'personal', 'business', 'elite' );
1446 - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) {
1487 + if ( $included || ! in_array( $plan_required, $plans, true ) ) {
1447 1488 return $included;
1448 1489 }
1449 1490
1450 1491 foreach ( $plans as $plan ) {
1451 - if ( $included || $plan === $args['license_type'] ) {
1492 + if ( $included || $plan === $license_type ) {
1452 1493 break;
1453 1494 }
1454 - $included = $plan === strtolower( $args['plan_required'] );
1495 + $included = $plan === $plan_required;
1455 1496 }
1456 1497
1457 1498 return $included;
1458 1499 }
@@ -1457,16 +1498,8 @@
1457 1498 return $included;
1458 1499 }
1459 1500
1460 1501 /**
1461 - * @since 4.02
1462 - */
1463 - public static function template_install_html( $link, $class = '' ) {
1464 - $link['class'] .= ' ' . $class;
1465 - echo '<a ' . esc_attr( $link['href'] ) . '="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link['class'] ) . ' " aria-label="' . esc_attr( $link['label'] ) . '"' . ( $link['atts'] ? ' target="_blank" rel="noopener"' : '' ) . '>';
1466 - }
1467 -
1468 - /**
1469 1502 * If a template or add-on cannot be installed, show a message
1470 1503 * about which plan is required.
1471 1504 *
1472 1505 * @since 4.0
@@ -1477,9 +1510,9 @@
1477 1510 }
1478 1511
1479 1512 ?>
1480 1513 <p class="frm_plan_required">
1481 - <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1514 + <?php esc_html_e( 'Plan required:', 'formidable' ); ?>
1482 1515 <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1483 1516 <?php echo esc_html( $requires ); ?>
1484 1517 </a>
1485 1518 </p>
@@ -1489,9 +1522,9 @@
1489 1522 /**
1490 1523 * @since 4.0
1491 1524 *
1492 1525 * @param array $item
1493 - * @return string|false
1526 + * @return false|string
1494 1527 */
1495 1528 public static function get_plan_required( &$item ) {
1496 1529 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1530 return false;
@@ -1496,18 +1529,15 @@
1496 1529 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1530 return false;
1498 1531 }
1499 1532
1500 - $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1533 + $plans = self::get_license_types();
1501 1534
1502 1535 foreach ( $item['categories'] as $k => $category ) {
1503 1536 if ( in_array( $category, $plans, true ) ) {
1504 1537 unset( $item['categories'][ $k ] );
1505 1538
1506 - if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1507 - // Show the current package name.
1508 - $category = 'Plus';
1509 - }
1539 + $category = self::convert_legacy_package_names( $category );
1510 1540
1511 1541 return $category;
1512 1542 }
1513 1543 }
@@ -1515,8 +1545,51 @@
1515 1545 return false;
1516 1546 }
1517 1547
1518 1548 /**
1549 + * Converts legacy package names to the current standard package name.
1550 + *
1551 + * @since 6.15
1552 + * @param string $package_name
1553 + * @return string The updated package name.
1554 + */
1555 + public static function convert_legacy_package_names( $package_name ) {
1556 + if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) {
1557 + $package_name = 'Plus';
1558 + }
1559 +
1560 + return $package_name;
1561 + }
1562 +
1563 + /**
1564 + * Get the license types.
1565 + *
1566 + * @since 6.15
1567 + *
1568 + * @param array $args
1569 + * @return array
1570 + */
1571 + public static function get_license_types( $args = array() ) {
1572 + $defaults = array(
1573 + 'include_all' => true,
1574 + 'case_lower' => false,
1575 + );
1576 + $args = wp_parse_args( $args, $defaults );
1577 +
1578 + $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' );
1579 +
1580 + if ( $args['include_all'] ) {
1581 + $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types );
1582 + }
1583 +
1584 + if ( $args['case_lower'] ) {
1585 + $license_types = array_map( 'strtolower', $license_types );
1586 + }
1587 +
1588 + return $license_types;
1589 + }
1590 +
1591 + /**
1519 1592 * Checks for warnings to be displayed after form settings are saved.
1520 1593 *
1521 1594 * @since 4.04
1522 1595 *
@@ -1552,9 +1625,9 @@
1552 1625
1553 1626 $options = $values['options'];
1554 1627 FrmAppHelper::sanitize_with_html( $options );
1555 1628
1556 - if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1629 + if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1557 1630 return false;
1558 1631 }
1559 1632
1560 1633 $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
@@ -1671,34 +1744,8 @@
1671 1744 );
1672 1745 }
1673 1746
1674 1747 /**
1675 - * Check an array of templates, determine how many the logged in user can use
1676 - *
1677 - * @param array $templates
1678 - * @param array $args
1679 - * @return int
1680 - */
1681 - public static function available_count( $templates, $args ) {
1682 - return array_reduce(
1683 - $templates,
1684 - function( $total, $template ) use ( $args ) {
1685 - if ( ! empty( $template['url'] ) ) {
1686 - return $total + 1;
1687 - }
1688 -
1689 - $args['plan_required'] = self::get_plan_required( $template );
1690 - if ( self::plan_is_allowed( $args ) ) {
1691 - return $total + 1;
1692 - }
1693 -
1694 - return $total;
1695 - },
1696 - 0
1697 - );
1698 - }
1699 -
1700 - /**
1701 1748 * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined.
1702 1749 * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL.
1703 1750 *
1704 1751 * @since 5.0.16
@@ -1747,9 +1794,9 @@
1747 1794 }
1748 1795 $new_shortcode .= ' sanitize_url=1]';
1749 1796
1750 1797 $query = str_replace( $shortcode, $new_shortcode, $query );
1751 - }
1798 + }//end foreach
1752 1799
1753 1800 if ( $query === $original_query ) {
1754 1801 return $url;
1755 1802 }
@@ -1766,6 +1813,62 @@
1766 1813 * @return bool
1767 1814 */
1768 1815 public static function should_use_pro_for_ajax_submit() {
1769 1816 return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' );
1817 + }
1818 +
1819 + /**
1820 + * Outputs the appropriate button text in the publish box.
1821 + *
1822 + * @return void
1823 + */
1824 + public static function publish_box_button_text() {
1825 + $is_new_template = FrmAppHelper::simple_get( 'new_template' );
1826 + $action = FrmAppHelper::simple_get( 'frm_action' );
1827 +
1828 + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) {
1829 + esc_html_e( 'Save', 'formidable' );
1830 + } else {
1831 + esc_html_e( 'Update', 'formidable' );
1832 + }
1833 + }
1834 +
1835 + /**
1836 + * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ].
1837 + * This allows shortcodes inside of the layout classes setting.
1838 + *
1839 + * @since 6.16
1840 + *
1841 + * @param string $classname
1842 + * @return string
1843 + */
1844 + public static function sanitize_layout_class( $classname ) {
1845 + // Strip out any percent-encoded characters.
1846 + $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
1847 +
1848 + // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'.
1849 + $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1850 +
1851 + return $sanitized;
1852 + }
1853 +
1854 + /**
1855 + * @since 3.0
1856 + * @deprecated 6.11
1857 + *
1858 + * @param array $atts
1859 + * @return void
1860 + */
1861 + public static function actions_dropdown( $atts ) {
1862 + _deprecated_function( __METHOD__, '6.11' );
1863 +
1864 + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
1865 + return;
1866 + }
1867 +
1868 + $status = $atts['status'];
1869 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1870 + $trash_link = self::delete_trash_info( $form_id, $status );
1871 + $links = self::get_action_links( $form_id, $status );
1872 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php';
1770 1873 }
1771 1874 }