PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 +346 -242 6.46.19 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 || is_null( $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,25 +208,18 @@
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
219 + *
220 + * @param array|string $field_type
221 + * @return string
218 222 */
219 223 public static function get_field_link_name( $field_type ) {
220 224 if ( is_array( $field_type ) ) {
221 225 $field_label = $field_type['name'];
@@ -227,8 +231,11 @@
227 231 }
228 232
229 233 /**
230 234 * @since 3.0
235 + *
236 + * @param array|string $field_type
237 + * @return string
231 238 */
232 239 public static function get_field_link_icon( $field_type ) {
233 240 if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) {
234 241 $icon = $field_type['icon'];
@@ -254,14 +261,16 @@
254 261 $settings_args['current_form'] = $args['form']->id;
255 262 }
256 263
257 264 $frm_settings = FrmAppHelper::get_settings( $settings_args );
258 - $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
265 + $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
259 266 return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args );
260 267 }
261 268
262 269 /**
263 270 * @param array $atts {
271 + * The success message details.
272 + *
264 273 * @type string $message
265 274 * @type stdClass $form
266 275 * @type int $entry_id
267 276 * @type string $class
@@ -284,9 +293,9 @@
284 293 if ( ! empty( $values ) ) {
285 294 $post_values = $values;
286 295 } else {
287 296 $values = array();
288 - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
297 + $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 298 }
290 299
291 300 $defaults = array(
292 301 'name' => '',
@@ -315,9 +324,9 @@
315 324 }
316 325 unset( $defaults );
317 326
318 327 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' );
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' );
320 329 }
321 330
322 331 $values = self::fill_default_opts( $values, false, $post_values );
323 332 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -347,17 +356,17 @@
347 356 $defaults = self::get_default_opts();
348 357 foreach ( $defaults as $var => $default ) {
349 358 if ( is_array( $default ) ) {
350 359 if ( ! isset( $values[ $var ] ) ) {
351 - $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
360 + $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
352 361 }
353 362
354 363 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 );
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 );
356 365
357 366 if ( is_array( $v ) ) {
358 367 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 );
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 );
360 369 unset( $k1, $v1 );
361 370 }
362 371 }
363 372
@@ -363,13 +372,13 @@
363 372
364 373 unset( $k, $v );
365 374 }
366 375 } else {
367 - $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
376 + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default );
368 377 }
369 378
370 379 unset( $var, $default );
371 - }
380 + }//end foreach
372 381
373 382 return $values;
374 383 }
375 384
@@ -401,12 +410,11 @@
401 410 );
402 411 }
403 412
404 413 /**
414 + * @since 2.0.6
405 415 * @param array $options
406 416 * @param array $values
407 - *
408 - * @since 2.0.6
409 417 */
410 418 public static function fill_form_options( &$options, $values ) {
411 419 $defaults = self::get_default_opts();
412 420 foreach ( $defaults as $var => $default ) {
@@ -418,20 +426,20 @@
418 426 /**
419 427 * @param string $loc
420 428 */
421 429 public static function get_default_html( $loc ) {
422 - if ( $loc == 'submit' ) {
430 + if ( $loc === 'submit' ) {
423 431 $draft_link = self::get_draft_link();
424 432 $start_over = self::get_start_over_shortcode();
425 433 $default_html = <<<SUBMIT_HTML
426 -<div class="frm_submit">
434 +<div class="frm_submit frm_flex">
435 +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
427 436 [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 437 $draft_link
430 438 $start_over
431 439 </div>
432 440 SUBMIT_HTML;
433 - } elseif ( $loc == 'before' ) {
441 + } elseif ( $loc === 'before' ) {
434 442 $default_html = <<<BEFORE_HTML
435 443 <legend class="frm_screen_reader">[form_name]</legend>
436 444 [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
437 445 [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
@@ -443,9 +451,9 @@
443 451 return $default_html;
444 452 }
445 453
446 454 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]';
455 + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
448 456
449 457 return $link;
450 458 }
451 459
@@ -478,10 +486,10 @@
478 486
479 487 $classes = apply_filters( 'frm_submit_button_class', array(), $form );
480 488 if ( ! empty( $classes ) ) {
481 489 $classes = implode( ' ', $classes );
482 - $button_class = ' class="frm_button_submit';
483 - if ( strpos( $button_parts[0], $button_class ) !== false ) {
490 + $button_class = 'frm_button_submit';
491 + if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
484 492 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
485 493 } else {
486 494 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
487 495 }
@@ -496,51 +504,51 @@
496 504 * @since 4.0
497 505 */
498 506 public static function html_shortcodes() {
499 507 $codes = array(
500 - 'id' => array(
508 + 'id' => array(
501 509 'label' => __( 'Field ID', 'formidable' ),
502 510 'class' => 'show_field_custom_html',
503 511 ),
504 - 'key' => array(
512 + 'key' => array(
505 513 'label' => __( 'Field Key', 'formidable' ),
506 514 'class' => 'show_field_custom_html',
507 515 ),
508 - 'field_name' => array(
516 + 'field_name' => array(
509 517 'label' => __( 'Field Name', 'formidable' ),
510 518 'class' => 'show_field_custom_html',
511 519 ),
512 - 'description' => array(
520 + 'description' => array(
513 521 'label' => __( 'Field Description', 'formidable' ),
514 522 'class' => 'show_field_custom_html',
515 523 ),
516 - 'label_position' => array(
524 + 'label_position' => array(
517 525 'label' => __( 'Label Position', 'formidable' ),
518 526 'class' => 'show_field_custom_html',
519 527 ),
520 - 'required_label' => array(
528 + 'required_label' => array(
521 529 'label' => __( 'Required Label', 'formidable' ),
522 530 'class' => 'show_field_custom_html',
523 531 ),
524 - 'input' => array(
532 + 'input' => array(
525 533 'label' => __( 'Input Field', 'formidable' ),
526 534 'class' => 'show_field_custom_html',
527 535 ),
528 - 'input opt=1' => array(
536 + 'input opt=1' => array(
529 537 'label' => __( 'Single Option', 'formidable' ),
530 538 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
531 539 'class' => 'show_field_custom_html',
532 540 ),
533 - 'input label=0' => array(
541 + 'input label=0' => array(
534 542 'label' => __( 'Hide Option Label', 'formidable' ),
535 543 'class' => 'show_field_custom_html',
536 544 ),
537 - 'required_class' => array(
545 + 'required_class' => array(
538 546 'label' => __( 'Required Class', 'formidable' ),
539 547 'title' => __( 'Add class name if field is required', 'formidable' ),
540 548 'class' => 'show_field_custom_html',
541 549 ),
542 - 'error_class' => array(
550 + 'error_class' => array(
543 551 'label' => __( 'Error Class', 'formidable' ),
544 552 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
545 553 'class' => 'show_field_custom_html',
546 554 ),
@@ -561,13 +569,13 @@
561 569 'label' => __( 'Delete Entry Link', 'formidable' ),
562 570 'class' => 'show_before_html show_after_html',
563 571 ),
564 572
565 - 'button_label' => array(
573 + 'button_label' => array(
566 574 'label' => __( 'Button Label', 'formidable' ),
567 575 'class' => 'show_submit_html',
568 576 ),
569 - 'button_action' => array(
577 + 'button_action' => array(
570 578 'label' => __( 'Button Hook', 'formidable' ),
571 579 'class' => 'show_submit_html',
572 580 ),
573 581 );
@@ -579,13 +587,15 @@
579 587 }
580 588
581 589 /**
582 590 * @since 4.0
591 + *
583 592 * @param array $args
593 + * @return void
584 594 */
585 595 public static function insert_opt_html( $args ) {
586 596 $class = isset( $args['class'] ) ? $args['class'] : '';
587 - $fields = FrmField::all_field_selection();
597 + $fields = self::get_field_type_data_for_insert_opt_html();
588 598 $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
589 599
590 600 self::prepare_field_type( $field );
591 601
@@ -600,22 +610,35 @@
600 610
601 611 if ( 'url' === $args['type'] ) {
602 612 $class .= ' frm_insert_url';
603 613 }
614 +
615 + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 );
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 + }
604 627 ?>
605 628 <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 ) ); ?>
629 + <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>">
630 + <?php
631 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
632 + echo esc_html( $truncated_name );
633 + ?>
610 634 <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
611 635 </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 ) ); ?>
636 + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>">
637 + <?php
638 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
639 + echo esc_html( $truncated_name );
640 + ?>
618 641 <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
619 642 </a>
620 643 </li>
621 644 <?php
@@ -621,8 +644,23 @@
621 644 <?php
622 645 }
623 646
624 647 /**
648 + * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up.
649 + * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection.
650 + *
651 + * @since 6.10
652 + *
653 + * @return array
654 + */
655 + private static function get_field_type_data_for_insert_opt_html() {
656 + if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) {
657 + self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection();
658 + }
659 + return self::$field_type_data_for_insert_opt_html;
660 + }
661 +
662 + /**
625 663 * @since 4.0
626 664 * @param array $args
627 665 */
628 666 public static function insert_code_html( $args ) {
@@ -654,8 +692,11 @@
654 692 * Some field types in add-ons may have been added with only
655 693 * a field type and name.
656 694 *
657 695 * @since 4.0
696 + *
697 + * @param array|string $field
698 + * @return void
658 699 */
659 700 public static function prepare_field_type( &$field ) {
660 701 if ( ! is_array( $field ) ) {
661 702 $field = array(
@@ -669,9 +710,11 @@
669 710 * Automatically add end section fields if they don't exist (2.0 migration)
670 711 *
671 712 * @since 2.0
672 713 *
673 - * @param boolean $reset_fields
714 + * @param object $form
715 + * @param array $fields
716 + * @param bool $reset_fields
674 717 */
675 718 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
676 719 if ( empty( $fields ) ) {
677 720 return;
@@ -683,9 +726,9 @@
683 726 $add_order = 0;
684 727 $last_field = false;
685 728 foreach ( $fields as $field ) {
686 729 if ( $prev_order === $field->field_order ) {
687 - $add_order ++;
730 + ++$add_order;
688 731 }
689 732
690 733 if ( $add_order ) {
691 734 $reset_fields = true;
@@ -712,14 +755,14 @@
712 755 }
713 756
714 757 // There is already an end section here, so there is no need to create one.
715 758 $open = false;
716 - }
759 + }//end switch
717 760 $prev_order = $field->field_order;
718 761
719 762 $last_field = $field;
720 763 unset( $field );
721 - }
764 + }//end foreach
722 765
723 766 self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
724 767 }
725 768
@@ -735,14 +778,14 @@
735 778 $end_section_values['field_order'] = $field->field_order + 1;
736 779
737 780 FrmField::create( $end_section_values );
738 781
739 - if ( $move == 'move' ) {
782 + if ( $move === 'move' ) {
740 783 // bump the order of current field unless we're at the end of the form
741 784 FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
742 785 }
743 786
744 - $add_order += 2;
787 + $add_order += 2;
745 788 $open = false;
746 789 $reset_fields = true;
747 790 }
748 791
@@ -756,9 +799,9 @@
756 799 if ( $code === 'form_name' ) {
757 800 $replace_with = $form->name;
758 801 } elseif ( $code === 'form_description' ) {
759 802 $replace_with = FrmAppHelper::use_wpautop( $form->description );
760 - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
803 + } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) {
761 804 $replace_with = FrmAppHelper::simple_get( 'entry' );
762 805 } else {
763 806 $replace_with = '';
764 807 }
@@ -765,12 +808,12 @@
765 808
766 809 FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
767 810 }
768 811
769 - //replace [form_key]
812 + // Replace [form_key].
770 813 $html = str_replace( '[form_key]', $form->form_key, $html );
771 814
772 - //replace [frmurl]
815 + // Replace [frmurl].
773 816 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
774 817
775 818 if ( strpos( $html, '[button_label]' ) ) {
776 819 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -813,18 +856,23 @@
813 856 * If the Formidable styling isn't being loaded,
814 857 * use inline styling to hide the element
815 858 *
816 859 * @since 2.03.05
860 + *
861 + * @return void
817 862 */
818 863 public static function maybe_hide_inline() {
819 864 $frm_settings = FrmAppHelper::get_settings();
820 - if ( $frm_settings->load_style == 'none' ) {
865 + if ( $frm_settings->load_style === 'none' ) {
821 866 echo ' style="display:none;"';
822 - } elseif ( $frm_settings->load_style == 'dynamic' ) {
867 + } elseif ( $frm_settings->load_style === 'dynamic' ) {
823 868 FrmStylesController::enqueue_style();
824 869 }
825 870 }
826 871
872 + /**
873 + * @return string|null
874 + */
827 875 public static function get_form_style_class( $form = false ) {
828 876 $style = self::get_form_style( $form );
829 877 $class = ' with_frm_style';
830 878
@@ -830,11 +878,10 @@
830 878
831 879 if ( empty( $style ) ) {
832 880 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
833 881 return $class;
834 - } else {
835 - return;
836 882 }
883 + return;
837 884 }
838 885
839 886 // If submit button needs to be inline or centered.
840 887 if ( is_object( $form ) ) {
@@ -879,9 +926,9 @@
879 926
880 927 /**
881 928 * Returns appropriate class if form has top labels
882 929 *
883 - * @param $form
930 + * @param array $form
884 931 *
885 932 * @return string
886 933 */
887 934 private static function maybe_align_fields_top( $form ) {
@@ -890,9 +937,9 @@
890 937
891 938 /**
892 939 * Determine if a form has fields with top labels so submit button can be aligned properly
893 940 *
894 - * @param $form
941 + * @param array $form
895 942 *
896 943 * @return bool
897 944 */
898 945 private static function form_has_top_labels( $form ) {
@@ -904,9 +951,10 @@
904 951 if ( count( $fields ) <= 0 ) {
905 952 return false;
906 953 }
907 954
908 - $fields = array_reverse( $fields ); // start from the fields closest to the submit button
955 + // Start from the fields closest to the submit button.
956 + $fields = array_reverse( $fields );
909 957 foreach ( $fields as $field ) {
910 958 $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
911 959 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
912 960 if ( $has_input ) {
@@ -919,10 +967,10 @@
919 967
920 968 /**
921 969 * Check if a field's label position is set to "top"
922 970 *
923 - * @param $field
924 - * @param $form
971 + * @param array $field
972 + * @param bool|object|string $form
925 973 *
926 974 * @return bool
927 975 */
928 976 private static function field_has_top_label( $field, $form ) {
@@ -931,10 +979,9 @@
931 979 return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
932 980 }
933 981
934 982 /**
935 - * @param object|string|boolean $form
936 - *
983 + * @param array|bool|object|string $form
937 984 * @return string
938 985 */
939 986 public static function get_form_style( $form ) {
940 987 $style = 1;
@@ -939,12 +986,14 @@
939 986 public static function get_form_style( $form ) {
940 987 $style = 1;
941 988 if ( empty( $form ) || 'default' === $form ) {
942 989 return $style;
943 - } elseif ( is_object( $form ) && $form->parent_form_id ) {
990 + }
991 +
992 + if ( is_object( $form ) && $form->parent_form_id ) {
944 993 // get the parent form if this is a child
945 994 $form = $form->parent_form_id;
946 - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
995 + } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
947 996 $form = $form['parent_form_id'];
948 997 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
949 998 $style = $form['custom_style'];
950 999 }
@@ -952,9 +1001,9 @@
952 1001 if ( $form && is_string( $form ) ) {
953 1002 $form = FrmForm::getOne( $form );
954 1003 }
955 1004
956 - $style = ( $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;
957 1006
958 1007 return $style;
959 1008 }
960 1009
@@ -960,11 +1009,10 @@
960 1009
961 1010 /**
962 1011 * Display the validation error messages when an entry is submitted
963 1012 *
964 - * @param array $args - includes img, errors
965 - *
966 1013 * @since 2.0.6
1014 + * @param array $args Includes img, errors.
967 1015 */
968 1016 public static function show_errors( $args ) {
969 1017 $invalid_msg = self::get_invalid_error_message( $args );
970 1018
@@ -988,11 +1036,10 @@
988 1036 * Display the error message in the front-end along with the image if set
989 1037 * The image was removed from the styling settings, but it may still be set with a hook
990 1038 * If the message in the global settings is empty, show every validation message in the error box
991 1039 *
992 - * @param array $args - includes img, errors, and show_img
993 - *
994 1040 * @since 2.0.6
1041 + * @param array $args Includes img, errors, and show_img.
995 1042 */
996 1043 public static function show_error( $args ) {
997 1044 // remove any blank messages
998 1045 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -998,9 +1045,9 @@
998 1045 $args['errors'] = array_filter( (array) $args['errors'] );
999 1046
1000 1047 $line_break_first = $args['show_img'];
1001 1048 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 ) ) {
1049 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1003 1050 continue;
1004 1051 }
1005 1052
1006 1053 $id = str_replace( 'field', 'field_', $error_key );
@@ -1006,9 +1053,9 @@
1006 1053 $id = str_replace( 'field', 'field_', $error_key );
1007 1054 echo '<div id="' . esc_attr( $id ) . '_error">';
1008 1055
1009 1056 if ( $args['show_img'] && ! empty( $args['img'] ) ) {
1010 - echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />';
1057 + echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />';
1011 1058 } else {
1012 1059 $args['show_img'] = true;
1013 1060 }
1014 1061
@@ -1031,21 +1078,8 @@
1031 1078
1032 1079 /**
1033 1080 * @since 3.0
1034 1081 */
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 1082 public static function get_action_links( $form_id, $form ) {
1049 1083 if ( ! is_object( $form ) ) {
1050 1084 $form = FrmForm::getOne( $form_id );
1051 1085 }
@@ -1074,13 +1108,17 @@
1074 1108 );
1075 1109 }
1076 1110
1077 1111 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
1078 - }
1112 + }//end if
1079 1113
1080 1114 return $actions;
1081 1115 }
1082 1116
1117 + /**
1118 + * @param int|object|string $data
1119 + * @return string
1120 + */
1083 1121 public static function edit_form_link( $data ) {
1084 1122 $form_id = self::get_form_id_from_data( $data );
1085 1123
1086 1124 if ( ! $form_id ) {
@@ -1091,19 +1129,34 @@
1091 1129 $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1092 1130 return $link;
1093 1131 }
1094 1132
1133 + /**
1134 + * Returns a text used when no title is set.
1135 + *
1136 + * @since 6.16.1
1137 + *
1138 + * @return string
1139 + */
1140 + public static function get_no_title_text() {
1141 + return __( '(no title)', 'formidable' );
1142 + }
1143 +
1144 + /**
1145 + * @param int|object|string $data
1146 + * @return string
1147 + */
1095 1148 public static function edit_form_link_label( $data ) {
1096 1149 $name = self::get_form_name_from_data( $data );
1097 1150 if ( ! $name ) {
1098 - return __( '(no title)', 'formidable' );
1151 + return self::get_no_title_text();
1099 1152 }
1100 1153 return FrmAppHelper::truncate( $name, 40 );
1101 1154 }
1102 1155
1103 1156 /**
1104 - * @param mixed data
1105 - * @return int
1157 + * @param int|object|string $data
1158 + * @return int|string
1106 1159 */
1107 1160 private static function get_form_id_from_data( $data ) {
1108 1161 if ( is_object( $data ) ) {
1109 1162 $form_id = $data->id;
@@ -1148,11 +1201,11 @@
1148 1201 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1149 1202 }
1150 1203
1151 1204 $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1152 - if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1205 + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1153 1206 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1154 - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1207 + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1155 1208 }
1156 1209
1157 1210 $link .= '>' . $label . '</a>';
1158 1211 }
@@ -1165,9 +1218,9 @@
1165 1218 */
1166 1219 public static function delete_trash_info( $id, $status ) {
1167 1220 $labels = self::delete_trash_links( $id );
1168 1221
1169 - if ( 'trash' == $status ) {
1222 + if ( 'trash' === $status ) {
1170 1223 $info = $labels['restore'];
1171 1224 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1172 1225 if ( EMPTY_TRASH_DAYS ) {
1173 1226 $info = $labels['trash'];
@@ -1183,9 +1236,9 @@
1183 1236
1184 1237 /**
1185 1238 * @since 3.0
1186 1239 */
1187 - private static function delete_trash_links( $id ) {
1240 + public static function delete_trash_links( $id ) {
1188 1241 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1189 1242 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1190 1243
1191 1244 return array(
@@ -1222,33 +1275,33 @@
1222 1275 * @since 3.0
1223 1276 */
1224 1277 public static function css_classes() {
1225 1278 $classes = array(
1226 - 'frm_total' => array(
1279 + 'frm_total' => array(
1227 1280 'label' => __( 'Total', 'formidable' ),
1228 1281 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1229 1282 ),
1230 - 'frm_total_big' => array(
1283 + 'frm_total_big' => array(
1231 1284 'label' => __( 'Big Total', 'formidable' ),
1232 1285 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1233 1286 ),
1234 - 'frm_scroll_box' => array(
1287 + 'frm_scroll_box' => array(
1235 1288 'label' => __( 'Scroll Box', 'formidable' ),
1236 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' ),
1237 1290 ),
1238 - 'frm_first' => array(
1291 + 'frm_first' => array(
1239 1292 'label' => __( 'First', 'formidable' ),
1240 1293 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1241 1294 ),
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' ),
1295 + 'frm_alignright' => __( 'Right', 'formidable' ),
1296 + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1297 + 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1298 + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1246 1299 'frm_color_block' => array(
1247 1300 'label' => __( 'Color Block', 'formidable' ),
1248 1301 'title' => __( 'Add a background color to the field or section.', 'formidable' ),
1249 1302 ),
1250 - 'frm_capitalize' => array(
1303 + 'frm_capitalize' => array(
1251 1304 'label' => __( 'Capitalize', 'formidable' ),
1252 1305 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1253 1306 ),
1254 1307 );
@@ -1291,9 +1344,9 @@
1291 1344 'trash' => __( 'Trash', 'formidable' ),
1292 1345 'publish' => __( 'Published', 'formidable' ),
1293 1346 );
1294 1347
1295 - if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1348 + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1296 1349 $status = 'publish';
1297 1350 }
1298 1351
1299 1352 $name = $nice_names[ $status ];
@@ -1301,101 +1354,94 @@
1301 1354 return $name;
1302 1355 }
1303 1356
1304 1357 /**
1305 - * @param array $categories
1358 + * Renders a template icon based on the given categories.
1359 + *
1360 + * @param array $categories The categories to render the icon for.
1306 1361 * @param array $atts {
1307 - * @type string $html 'span' or 'div'.
1308 - * @type boolean $bg Whether to add a bg color or not.
1362 + * Optional. An array of attributes for rendering.
1363 + * @type string $html 'span' or 'div'. Default 'span'.
1364 + * @type bool $bg Whether to add a background color or not. Default false.
1309 1365 * }
1310 1366 *
1311 1367 * @return void
1312 1368 */
1313 1369 public static function template_icon( $categories, $atts = array() ) {
1370 + // Define defaults.
1314 1371 $defaults = array(
1315 - 'html' => 'span',
1316 - 'bg' => false,
1372 + 'bg' => true,
1317 1373 );
1318 - $atts = array_merge( $defaults, $atts );
1374 + $atts = array_merge( $defaults, $atts );
1319 1375
1320 - $ignore = self::ignore_template_categories();
1376 + // Filter out ignored categories.
1377 + $ignore = self::get_license_types();
1321 1378 $categories = array_diff( $categories, $ignore );
1322 1379
1380 + // Define icons mapping.
1323 1381 $icons = array(
1324 - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1325 - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1326 - 'User Registration' => array( 'register', 'var(--pink)' ),
1382 + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1383 + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1384 + 'User Registration' => array( 'register', 'var(--pink)' ),
1327 1385 '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' ),
1386 + 'PayPal' => array( 'paypal' ),
1387 + 'Stripe' => array( 'credit_card', 'var(--green)' ),
1388 + 'Twilio' => array( 'sms' ),
1389 + 'Payment' => array( 'credit_card' ),
1390 + 'Order Form' => array( 'product' ),
1391 + 'Finance' => array( 'total' ),
1392 + 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1393 + 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1394 + 'Real Estate' => array( 'house' ),
1395 + 'Nonprofit' => array( 'heart_solid' ),
1396 + 'Calculator' => array( 'calculator', 'var(--purple)' ),
1397 + 'Quiz' => array( 'percent' ),
1398 + 'Registrations' => array( 'address_card' ),
1399 + 'Customer Service' => array( 'users_solid' ),
1400 + 'Education' => array( 'pencil' ),
1401 + 'Marketing' => array( 'eye' ),
1402 + 'Feedback' => array( 'smile' ),
1403 + 'Business Operations' => array( 'case' ),
1404 + 'Contact Form' => array( 'email' ),
1405 + 'Conversational Forms' => array( 'chat_forms' ),
1406 + 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1407 + 'Application' => array( 'align_right' ),
1408 + 'Signature' => array( 'signature' ),
1409 + '' => array( 'align_right' ),
1352 1410 );
1353 1411
1354 - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' );
1355 -
1412 + // Determine the icon to be used.
1356 1413 $icon = $icons[''];
1357 -
1358 1414 if ( count( $categories ) === 1 ) {
1359 1415 $category = reset( $categories );
1360 1416 $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1361 1417 } 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 );
1418 + $icons = array_intersect_key( $icons, array_flip( $categories ) );
1419 + $icon = reset( $icons );
1368 1420 }
1369 1421
1370 - $bg = isset( $icon[1] ) ? $icon[1] : '';
1422 + // Prepare variables for output.
1423 + $icon_name = $icon[0];
1424 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1371 1425
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"';
1426 + // Render the icon.
1427 + echo '<span class="frm-category-icon frm-icon-wrapper"';
1428 + if ( $bg_color && $atts['bg'] ) {
1429 + echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1376 1430 }
1377 - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"';
1378 1431 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' );
1432 + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' );
1383 1433 echo '</span>';
1384 - echo '</' . esc_attr( $atts['html'] ) . '>';
1385 1434 }
1386 1435
1387 1436 /**
1388 - * @since 4.03.01
1437 + * Get template install link.
1389 1438 *
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 1439 * @since 4.02
1440 + *
1441 + * @param array $template Template details.
1442 + * @param array $args Additional arguments.
1443 + * @return array The link attributes.
1398 1444 */
1399 1445 public static function get_template_install_link( $template, $args ) {
1400 1446 $defaults = array(
1401 1447 'class' => 'install-now',
@@ -1410,13 +1456,8 @@
1410 1456 'class' => 'frm-install-template',
1411 1457 'href' => 'rel',
1412 1458 'atts' => '',
1413 1459 );
1414 - } elseif ( self::plan_is_allowed( $args ) ) {
1415 - $link = array(
1416 - 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'],
1417 - 'label' => __( 'Renew', 'formidable' ),
1418 - );
1419 1460 } else {
1420 1461 $link = array(
1421 1462 'url' => $args['pricing'],
1422 1463 'label' => __( 'Upgrade', 'formidable' ),
@@ -1431,9 +1472,8 @@
1431 1472 *
1432 1473 * @since 4.02.02
1433 1474 *
1434 1475 * @param array $args
1435 - *
1436 1476 * @return bool
1437 1477 */
1438 1478 public static function plan_is_allowed( $args ) {
1439 1479 if ( empty( $args['license_type'] ) ) {
@@ -1439,20 +1479,22 @@
1439 1479 if ( empty( $args['license_type'] ) ) {
1440 1480 return false;
1441 1481 }
1442 1482
1443 - $included = $args['license_type'] === strtolower( $args['plan_required'] );
1483 + $plans = array( 'free', 'personal', 'business', 'elite' );
1484 + $license_type = strtolower( $args['license_type'] );
1485 + $plan_required = strtolower( $args['plan_required'] );
1486 + $included = $license_type === $plan_required;
1444 1487
1445 - $plans = array( 'free', 'personal', 'business', 'elite' );
1446 - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) {
1488 + if ( $included || ! in_array( $plan_required, $plans, true ) ) {
1447 1489 return $included;
1448 1490 }
1449 1491
1450 1492 foreach ( $plans as $plan ) {
1451 - if ( $included || $plan === $args['license_type'] ) {
1493 + if ( $included || $plan === $license_type ) {
1452 1494 break;
1453 1495 }
1454 - $included = $plan === strtolower( $args['plan_required'] );
1496 + $included = $plan === $plan_required;
1455 1497 }
1456 1498
1457 1499 return $included;
1458 1500 }
@@ -1457,16 +1499,8 @@
1457 1499 return $included;
1458 1500 }
1459 1501
1460 1502 /**
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 1503 * If a template or add-on cannot be installed, show a message
1470 1504 * about which plan is required.
1471 1505 *
1472 1506 * @since 4.0
@@ -1477,9 +1511,9 @@
1477 1511 }
1478 1512
1479 1513 ?>
1480 1514 <p class="frm_plan_required">
1481 - <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1515 + <?php esc_html_e( 'Plan required:', 'formidable' ); ?>
1482 1516 <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1483 1517 <?php echo esc_html( $requires ); ?>
1484 1518 </a>
1485 1519 </p>
@@ -1489,9 +1523,9 @@
1489 1523 /**
1490 1524 * @since 4.0
1491 1525 *
1492 1526 * @param array $item
1493 - * @return string|false
1527 + * @return false|string
1494 1528 */
1495 1529 public static function get_plan_required( &$item ) {
1496 1530 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1531 return false;
@@ -1496,18 +1530,15 @@
1496 1530 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1531 return false;
1498 1532 }
1499 1533
1500 - $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1534 + $plans = self::get_license_types();
1501 1535
1502 1536 foreach ( $item['categories'] as $k => $category ) {
1503 1537 if ( in_array( $category, $plans, true ) ) {
1504 1538 unset( $item['categories'][ $k ] );
1505 1539
1506 - if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1507 - // Show the current package name.
1508 - $category = 'Plus';
1509 - }
1540 + $category = self::convert_legacy_package_names( $category );
1510 1541
1511 1542 return $category;
1512 1543 }
1513 1544 }
@@ -1515,8 +1546,51 @@
1515 1546 return false;
1516 1547 }
1517 1548
1518 1549 /**
1550 + * Converts legacy package names to the current standard package name.
1551 + *
1552 + * @since 6.15
1553 + * @param string $package_name
1554 + * @return string The updated package name.
1555 + */
1556 + public static function convert_legacy_package_names( $package_name ) {
1557 + if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) {
1558 + $package_name = 'Plus';
1559 + }
1560 +
1561 + return $package_name;
1562 + }
1563 +
1564 + /**
1565 + * Get the license types.
1566 + *
1567 + * @since 6.15
1568 + *
1569 + * @param array $args
1570 + * @return array
1571 + */
1572 + public static function get_license_types( $args = array() ) {
1573 + $defaults = array(
1574 + 'include_all' => true,
1575 + 'case_lower' => false,
1576 + );
1577 + $args = wp_parse_args( $args, $defaults );
1578 +
1579 + $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' );
1580 +
1581 + if ( $args['include_all'] ) {
1582 + $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types );
1583 + }
1584 +
1585 + if ( $args['case_lower'] ) {
1586 + $license_types = array_map( 'strtolower', $license_types );
1587 + }
1588 +
1589 + return $license_types;
1590 + }
1591 +
1592 + /**
1519 1593 * Checks for warnings to be displayed after form settings are saved.
1520 1594 *
1521 1595 * @since 4.04
1522 1596 *
@@ -1552,9 +1626,9 @@
1552 1626
1553 1627 $options = $values['options'];
1554 1628 FrmAppHelper::sanitize_with_html( $options );
1555 1629
1556 - if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1630 + if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1557 1631 return false;
1558 1632 }
1559 1633
1560 1634 $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
@@ -1671,34 +1745,8 @@
1671 1745 );
1672 1746 }
1673 1747
1674 1748 /**
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 1749 * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined.
1702 1750 * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL.
1703 1751 *
1704 1752 * @since 5.0.16
@@ -1747,9 +1795,9 @@
1747 1795 }
1748 1796 $new_shortcode .= ' sanitize_url=1]';
1749 1797
1750 1798 $query = str_replace( $shortcode, $new_shortcode, $query );
1751 - }
1799 + }//end foreach
1752 1800
1753 1801 if ( $query === $original_query ) {
1754 1802 return $url;
1755 1803 }
@@ -1766,6 +1814,62 @@
1766 1814 * @return bool
1767 1815 */
1768 1816 public static function should_use_pro_for_ajax_submit() {
1769 1817 return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' );
1818 + }
1819 +
1820 + /**
1821 + * Outputs the appropriate button text in the publish box.
1822 + *
1823 + * @return void
1824 + */
1825 + public static function publish_box_button_text() {
1826 + $is_new_template = FrmAppHelper::simple_get( 'new_template' );
1827 + $action = FrmAppHelper::simple_get( 'frm_action' );
1828 +
1829 + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) {
1830 + esc_html_e( 'Save', 'formidable' );
1831 + } else {
1832 + esc_html_e( 'Update', 'formidable' );
1833 + }
1834 + }
1835 +
1836 + /**
1837 + * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ].
1838 + * This allows shortcodes inside of the layout classes setting.
1839 + *
1840 + * @since 6.16
1841 + *
1842 + * @param string $classname
1843 + * @return string
1844 + */
1845 + public static function sanitize_layout_class( $classname ) {
1846 + // Strip out any percent-encoded characters.
1847 + $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
1848 +
1849 + // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'.
1850 + $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1851 +
1852 + return $sanitized;
1853 + }
1854 +
1855 + /**
1856 + * @since 3.0
1857 + * @deprecated 6.11
1858 + *
1859 + * @param array $atts
1860 + * @return void
1861 + */
1862 + public static function actions_dropdown( $atts ) {
1863 + _deprecated_function( __METHOD__, '6.11' );
1864 +
1865 + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
1866 + return;
1867 + }
1868 +
1869 + $status = $atts['status'];
1870 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1871 + $trash_link = self::delete_trash_info( $form_id, $status );
1872 + $links = self::get_action_links( $form_id, $status );
1873 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php';
1770 1874 }
1771 1875 }