PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 +474 -246 6.36.24 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
@@ -269,9 +278,29 @@
269 278 * @return string
270 279 */
271 280 public static function get_success_message( $atts ) {
272 281 $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
273 - $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) );
282 +
283 + // Only autop if the message includes line breaks.
284 + $autop = strpos( $message, "\n" ) !== false;
285 +
286 + /**
287 + * Filters whether to autop the success message.
288 + * This is false by default if the message does not include line breaks.
289 + *
290 + * @since 6.23
291 + *
292 + * @param bool $autop
293 + * @param string $message
294 + * @param object $form
295 + */
296 + $autop = (bool) apply_filters( 'frm_wpautop_success_message', $autop, $message, $atts['form'] );
297 +
298 + if ( $autop ) {
299 + $message = FrmAppHelper::use_wpautop( $message );
300 + }
301 +
302 + $message = do_shortcode( $message );
274 303 $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
275 304 return $message;
276 305 }
277 306
@@ -284,9 +313,9 @@
284 313 if ( ! empty( $values ) ) {
285 314 $post_values = $values;
286 315 } else {
287 316 $values = array();
288 - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
317 + $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 318 }
290 319
291 320 $defaults = array(
292 321 'name' => '',
@@ -315,9 +344,9 @@
315 344 }
316 345 unset( $defaults );
317 346
318 347 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' );
348 + $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 349 }
321 350
322 351 $values = self::fill_default_opts( $values, false, $post_values );
323 352 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -347,17 +376,17 @@
347 376 $defaults = self::get_default_opts();
348 377 foreach ( $defaults as $var => $default ) {
349 378 if ( is_array( $default ) ) {
350 379 if ( ! isset( $values[ $var ] ) ) {
351 - $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
380 + $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
352 381 }
353 382
354 383 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 );
384 + $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 385
357 386 if ( is_array( $v ) ) {
358 387 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 );
388 + $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 389 unset( $k1, $v1 );
361 390 }
362 391 }
363 392
@@ -363,13 +392,13 @@
363 392
364 393 unset( $k, $v );
365 394 }
366 395 } else {
367 - $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
396 + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default );
368 397 }
369 398
370 399 unset( $var, $default );
371 - }
400 + }//end foreach
372 401
373 402 return $values;
374 403 }
375 404
@@ -384,9 +413,9 @@
384 413 'success_action' => 'message',
385 414 'success_msg' => $frm_settings->success_msg,
386 415 'show_form' => 0,
387 416 'akismet' => '',
388 - 'honeypot' => 'basic',
417 + 'stopforumspam' => 0,
389 418 'antispam' => 0,
390 419 'no_save' => 0,
391 420 'ajax_load' => 0,
392 421 'js_validate' => 0,
@@ -401,12 +430,11 @@
401 430 );
402 431 }
403 432
404 433 /**
434 + * @since 2.0.6
405 435 * @param array $options
406 436 * @param array $values
407 - *
408 - * @since 2.0.6
409 437 */
410 438 public static function fill_form_options( &$options, $values ) {
411 439 $defaults = self::get_default_opts();
412 440 foreach ( $defaults as $var => $default ) {
@@ -418,20 +446,20 @@
418 446 /**
419 447 * @param string $loc
420 448 */
421 449 public static function get_default_html( $loc ) {
422 - if ( $loc == 'submit' ) {
450 + if ( $loc === 'submit' ) {
423 451 $draft_link = self::get_draft_link();
424 452 $start_over = self::get_start_over_shortcode();
425 453 $default_html = <<<SUBMIT_HTML
426 -<div class="frm_submit">
454 +<div class="frm_submit frm_flex">
455 +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
427 456 [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 457 $draft_link
430 458 $start_over
431 459 </div>
432 460 SUBMIT_HTML;
433 - } elseif ( $loc == 'before' ) {
461 + } elseif ( $loc === 'before' ) {
434 462 $default_html = <<<BEFORE_HTML
435 463 <legend class="frm_screen_reader">[form_name]</legend>
436 464 [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
437 465 [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
@@ -443,9 +471,9 @@
443 471 return $default_html;
444 472 }
445 473
446 474 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]';
475 + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
448 476
449 477 return $link;
450 478 }
451 479
@@ -478,10 +506,10 @@
478 506
479 507 $classes = apply_filters( 'frm_submit_button_class', array(), $form );
480 508 if ( ! empty( $classes ) ) {
481 509 $classes = implode( ' ', $classes );
482 - $button_class = ' class="frm_button_submit';
483 - if ( strpos( $button_parts[0], $button_class ) !== false ) {
510 + $button_class = 'frm_button_submit';
511 + if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
484 512 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
485 513 } else {
486 514 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
487 515 }
@@ -496,51 +524,51 @@
496 524 * @since 4.0
497 525 */
498 526 public static function html_shortcodes() {
499 527 $codes = array(
500 - 'id' => array(
528 + 'id' => array(
501 529 'label' => __( 'Field ID', 'formidable' ),
502 530 'class' => 'show_field_custom_html',
503 531 ),
504 - 'key' => array(
532 + 'key' => array(
505 533 'label' => __( 'Field Key', 'formidable' ),
506 534 'class' => 'show_field_custom_html',
507 535 ),
508 - 'field_name' => array(
536 + 'field_name' => array(
509 537 'label' => __( 'Field Name', 'formidable' ),
510 538 'class' => 'show_field_custom_html',
511 539 ),
512 - 'description' => array(
540 + 'description' => array(
513 541 'label' => __( 'Field Description', 'formidable' ),
514 542 'class' => 'show_field_custom_html',
515 543 ),
516 - 'label_position' => array(
544 + 'label_position' => array(
517 545 'label' => __( 'Label Position', 'formidable' ),
518 546 'class' => 'show_field_custom_html',
519 547 ),
520 - 'required_label' => array(
548 + 'required_label' => array(
521 549 'label' => __( 'Required Label', 'formidable' ),
522 550 'class' => 'show_field_custom_html',
523 551 ),
524 - 'input' => array(
552 + 'input' => array(
525 553 'label' => __( 'Input Field', 'formidable' ),
526 554 'class' => 'show_field_custom_html',
527 555 ),
528 - 'input opt=1' => array(
556 + 'input opt=1' => array(
529 557 'label' => __( 'Single Option', 'formidable' ),
530 558 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
531 559 'class' => 'show_field_custom_html',
532 560 ),
533 - 'input label=0' => array(
561 + 'input label=0' => array(
534 562 'label' => __( 'Hide Option Label', 'formidable' ),
535 563 'class' => 'show_field_custom_html',
536 564 ),
537 - 'required_class' => array(
565 + 'required_class' => array(
538 566 'label' => __( 'Required Class', 'formidable' ),
539 567 'title' => __( 'Add class name if field is required', 'formidable' ),
540 568 'class' => 'show_field_custom_html',
541 569 ),
542 - 'error_class' => array(
570 + 'error_class' => array(
543 571 'label' => __( 'Error Class', 'formidable' ),
544 572 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
545 573 'class' => 'show_field_custom_html',
546 574 ),
@@ -561,13 +589,13 @@
561 589 'label' => __( 'Delete Entry Link', 'formidable' ),
562 590 'class' => 'show_before_html show_after_html',
563 591 ),
564 592
565 - 'button_label' => array(
593 + 'button_label' => array(
566 594 'label' => __( 'Button Label', 'formidable' ),
567 595 'class' => 'show_submit_html',
568 596 ),
569 - 'button_action' => array(
597 + 'button_action' => array(
570 598 'label' => __( 'Button Hook', 'formidable' ),
571 599 'class' => 'show_submit_html',
572 600 ),
573 601 );
@@ -579,13 +607,15 @@
579 607 }
580 608
581 609 /**
582 610 * @since 4.0
611 + *
583 612 * @param array $args
613 + * @return void
584 614 */
585 615 public static function insert_opt_html( $args ) {
586 616 $class = isset( $args['class'] ) ? $args['class'] : '';
587 - $fields = FrmField::all_field_selection();
617 + $fields = self::get_field_type_data_for_insert_opt_html();
588 618 $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
589 619
590 620 self::prepare_field_type( $field );
591 621
@@ -600,22 +630,35 @@
600 630
601 631 if ( 'url' === $args['type'] ) {
602 632 $class .= ' frm_insert_url';
603 633 }
634 +
635 + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 );
636 + if ( isset( $field['icon'] ) ) {
637 + $icon = FrmAppHelper::icon_by_class(
638 + $field['icon'],
639 + array(
640 + 'aria-hidden' => 'true',
641 + 'echo' => false,
642 + )
643 + );
644 + } else {
645 + $icon = '';
646 + }
604 647 ?>
605 648 <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 ) ); ?>
649 + <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>">
650 + <?php
651 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
652 + echo esc_html( $truncated_name );
653 + ?>
610 654 <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
611 655 </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 ) ); ?>
656 + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>">
657 + <?php
658 + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
659 + echo esc_html( $truncated_name );
660 + ?>
618 661 <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
619 662 </a>
620 663 </li>
621 664 <?php
@@ -621,8 +664,23 @@
621 664 <?php
622 665 }
623 666
624 667 /**
668 + * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up.
669 + * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection.
670 + *
671 + * @since 6.10
672 + *
673 + * @return array
674 + */
675 + private static function get_field_type_data_for_insert_opt_html() {
676 + if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) {
677 + self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection();
678 + }
679 + return self::$field_type_data_for_insert_opt_html;
680 + }
681 +
682 + /**
625 683 * @since 4.0
626 684 * @param array $args
627 685 */
628 686 public static function insert_code_html( $args ) {
@@ -654,8 +712,11 @@
654 712 * Some field types in add-ons may have been added with only
655 713 * a field type and name.
656 714 *
657 715 * @since 4.0
716 + *
717 + * @param array|string $field
718 + * @return void
658 719 */
659 720 public static function prepare_field_type( &$field ) {
660 721 if ( ! is_array( $field ) ) {
661 722 $field = array(
@@ -669,9 +730,11 @@
669 730 * Automatically add end section fields if they don't exist (2.0 migration)
670 731 *
671 732 * @since 2.0
672 733 *
673 - * @param boolean $reset_fields
734 + * @param object $form
735 + * @param array $fields
736 + * @param bool $reset_fields
674 737 */
675 738 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
676 739 if ( empty( $fields ) ) {
677 740 return;
@@ -683,9 +746,9 @@
683 746 $add_order = 0;
684 747 $last_field = false;
685 748 foreach ( $fields as $field ) {
686 749 if ( $prev_order === $field->field_order ) {
687 - $add_order ++;
750 + ++$add_order;
688 751 }
689 752
690 753 if ( $add_order ) {
691 754 $reset_fields = true;
@@ -712,14 +775,14 @@
712 775 }
713 776
714 777 // There is already an end section here, so there is no need to create one.
715 778 $open = false;
716 - }
779 + }//end switch
717 780 $prev_order = $field->field_order;
718 781
719 782 $last_field = $field;
720 783 unset( $field );
721 - }
784 + }//end foreach
722 785
723 786 self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
724 787 }
725 788
@@ -735,14 +798,14 @@
735 798 $end_section_values['field_order'] = $field->field_order + 1;
736 799
737 800 FrmField::create( $end_section_values );
738 801
739 - if ( $move == 'move' ) {
802 + if ( $move === 'move' ) {
740 803 // bump the order of current field unless we're at the end of the form
741 804 FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
742 805 }
743 806
744 - $add_order += 2;
807 + $add_order += 2;
745 808 $open = false;
746 809 $reset_fields = true;
747 810 }
748 811
@@ -756,9 +819,9 @@
756 819 if ( $code === 'form_name' ) {
757 820 $replace_with = $form->name;
758 821 } elseif ( $code === 'form_description' ) {
759 822 $replace_with = FrmAppHelper::use_wpautop( $form->description );
760 - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
823 + } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) {
761 824 $replace_with = FrmAppHelper::simple_get( 'entry' );
762 825 } else {
763 826 $replace_with = '';
764 827 }
@@ -765,12 +828,12 @@
765 828
766 829 FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
767 830 }
768 831
769 - //replace [form_key]
832 + // Replace [form_key].
770 833 $html = str_replace( '[form_key]', $form->form_key, $html );
771 834
772 - //replace [frmurl]
835 + // Replace [frmurl].
773 836 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
774 837
775 838 if ( strpos( $html, '[button_label]' ) ) {
776 839 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -813,18 +876,23 @@
813 876 * If the Formidable styling isn't being loaded,
814 877 * use inline styling to hide the element
815 878 *
816 879 * @since 2.03.05
880 + *
881 + * @return void
817 882 */
818 883 public static function maybe_hide_inline() {
819 884 $frm_settings = FrmAppHelper::get_settings();
820 - if ( $frm_settings->load_style == 'none' ) {
885 + if ( $frm_settings->load_style === 'none' ) {
821 886 echo ' style="display:none;"';
822 - } elseif ( $frm_settings->load_style == 'dynamic' ) {
887 + } elseif ( $frm_settings->load_style === 'dynamic' ) {
823 888 FrmStylesController::enqueue_style();
824 889 }
825 890 }
826 891
892 + /**
893 + * @return string|null
894 + */
827 895 public static function get_form_style_class( $form = false ) {
828 896 $style = self::get_form_style( $form );
829 897 $class = ' with_frm_style';
830 898
@@ -830,11 +898,10 @@
830 898
831 899 if ( empty( $style ) ) {
832 900 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
833 901 return $class;
834 - } else {
835 - return;
836 902 }
903 + return;
837 904 }
838 905
839 906 // If submit button needs to be inline or centered.
840 907 if ( is_object( $form ) ) {
@@ -879,9 +946,9 @@
879 946
880 947 /**
881 948 * Returns appropriate class if form has top labels
882 949 *
883 - * @param $form
950 + * @param array $form
884 951 *
885 952 * @return string
886 953 */
887 954 private static function maybe_align_fields_top( $form ) {
@@ -890,9 +957,9 @@
890 957
891 958 /**
892 959 * Determine if a form has fields with top labels so submit button can be aligned properly
893 960 *
894 - * @param $form
961 + * @param array $form
895 962 *
896 963 * @return bool
897 964 */
898 965 private static function form_has_top_labels( $form ) {
@@ -904,9 +971,10 @@
904 971 if ( count( $fields ) <= 0 ) {
905 972 return false;
906 973 }
907 974
908 - $fields = array_reverse( $fields ); // start from the fields closest to the submit button
975 + // Start from the fields closest to the submit button.
976 + $fields = array_reverse( $fields );
909 977 foreach ( $fields as $field ) {
910 978 $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
911 979 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
912 980 if ( $has_input ) {
@@ -919,10 +987,10 @@
919 987
920 988 /**
921 989 * Check if a field's label position is set to "top"
922 990 *
923 - * @param $field
924 - * @param $form
991 + * @param array $field
992 + * @param bool|object|string $form
925 993 *
926 994 * @return bool
927 995 */
928 996 private static function field_has_top_label( $field, $form ) {
@@ -931,10 +999,9 @@
931 999 return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
932 1000 }
933 1001
934 1002 /**
935 - * @param object|string|boolean $form
936 - *
1003 + * @param array|bool|int|object|string $form
937 1004 * @return string
938 1005 */
939 1006 public static function get_form_style( $form ) {
940 1007 $style = 1;
@@ -939,22 +1006,24 @@
939 1006 public static function get_form_style( $form ) {
940 1007 $style = 1;
941 1008 if ( empty( $form ) || 'default' === $form ) {
942 1009 return $style;
943 - } elseif ( is_object( $form ) && $form->parent_form_id ) {
1010 + }
1011 +
1012 + if ( is_object( $form ) && $form->parent_form_id ) {
944 1013 // get the parent form if this is a child
945 1014 $form = $form->parent_form_id;
946 - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
1015 + } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
947 1016 $form = $form['parent_form_id'];
948 1017 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
949 1018 $style = $form['custom_style'];
950 1019 }
951 1020
952 - if ( $form && is_string( $form ) ) {
1021 + if ( $form && ( is_string( $form ) || is_int( $form ) ) ) {
953 1022 $form = FrmForm::getOne( $form );
954 1023 }
955 1024
956 - $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
1025 + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
957 1026
958 1027 return $style;
959 1028 }
960 1029
@@ -960,11 +1029,10 @@
960 1029
961 1030 /**
962 1031 * Display the validation error messages when an entry is submitted
963 1032 *
964 - * @param array $args - includes img, errors
965 - *
966 1033 * @since 2.0.6
1034 + * @param array $args Includes img, errors.
967 1035 */
968 1036 public static function show_errors( $args ) {
969 1037 $invalid_msg = self::get_invalid_error_message( $args );
970 1038
@@ -988,11 +1056,10 @@
988 1056 * Display the error message in the front-end along with the image if set
989 1057 * The image was removed from the styling settings, but it may still be set with a hook
990 1058 * If the message in the global settings is empty, show every validation message in the error box
991 1059 *
992 - * @param array $args - includes img, errors, and show_img
993 - *
994 1060 * @since 2.0.6
1061 + * @param array $args Includes img, errors, and show_img.
995 1062 */
996 1063 public static function show_error( $args ) {
997 1064 // remove any blank messages
998 1065 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -998,9 +1065,9 @@
998 1065 $args['errors'] = array_filter( (array) $args['errors'] );
999 1066
1000 1067 $line_break_first = $args['show_img'];
1001 1068 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 ) ) {
1069 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1003 1070 continue;
1004 1071 }
1005 1072
1006 1073 $id = str_replace( 'field', 'field_', $error_key );
@@ -1006,9 +1073,9 @@
1006 1073 $id = str_replace( 'field', 'field_', $error_key );
1007 1074 echo '<div id="' . esc_attr( $id ) . '_error">';
1008 1075
1009 1076 if ( $args['show_img'] && ! empty( $args['img'] ) ) {
1010 - echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />';
1077 + echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />';
1011 1078 } else {
1012 1079 $args['show_img'] = true;
1013 1080 }
1014 1081
@@ -1031,21 +1098,8 @@
1031 1098
1032 1099 /**
1033 1100 * @since 3.0
1034 1101 */
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 1102 public static function get_action_links( $form_id, $form ) {
1049 1103 if ( ! is_object( $form ) ) {
1050 1104 $form = FrmForm::getOne( $form_id );
1051 1105 }
@@ -1074,13 +1128,17 @@
1074 1128 );
1075 1129 }
1076 1130
1077 1131 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
1078 - }
1132 + }//end if
1079 1133
1080 1134 return $actions;
1081 1135 }
1082 1136
1137 + /**
1138 + * @param int|object|string $data
1139 + * @return string
1140 + */
1083 1141 public static function edit_form_link( $data ) {
1084 1142 $form_id = self::get_form_id_from_data( $data );
1085 1143
1086 1144 if ( ! $form_id ) {
@@ -1091,19 +1149,34 @@
1091 1149 $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1092 1150 return $link;
1093 1151 }
1094 1152
1153 + /**
1154 + * Returns a text used when no title is set.
1155 + *
1156 + * @since 6.16.1
1157 + *
1158 + * @return string
1159 + */
1160 + public static function get_no_title_text() {
1161 + return __( '(no title)', 'formidable' );
1162 + }
1163 +
1164 + /**
1165 + * @param int|object|string $data
1166 + * @return string
1167 + */
1095 1168 public static function edit_form_link_label( $data ) {
1096 1169 $name = self::get_form_name_from_data( $data );
1097 1170 if ( ! $name ) {
1098 - return __( '(no title)', 'formidable' );
1171 + return self::get_no_title_text();
1099 1172 }
1100 1173 return FrmAppHelper::truncate( $name, 40 );
1101 1174 }
1102 1175
1103 1176 /**
1104 - * @param mixed data
1105 - * @return int
1177 + * @param int|object|string $data
1178 + * @return int|string
1106 1179 */
1107 1180 private static function get_form_id_from_data( $data ) {
1108 1181 if ( is_object( $data ) ) {
1109 1182 $form_id = $data->id;
@@ -1148,11 +1221,11 @@
1148 1221 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1149 1222 }
1150 1223
1151 1224 $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1152 - if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1225 + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1153 1226 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1154 - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1227 + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1155 1228 }
1156 1229
1157 1230 $link .= '>' . $label . '</a>';
1158 1231 }
@@ -1165,9 +1238,9 @@
1165 1238 */
1166 1239 public static function delete_trash_info( $id, $status ) {
1167 1240 $labels = self::delete_trash_links( $id );
1168 1241
1169 - if ( 'trash' == $status ) {
1242 + if ( 'trash' === $status ) {
1170 1243 $info = $labels['restore'];
1171 1244 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1172 1245 if ( EMPTY_TRASH_DAYS ) {
1173 1246 $info = $labels['trash'];
@@ -1183,9 +1256,9 @@
1183 1256
1184 1257 /**
1185 1258 * @since 3.0
1186 1259 */
1187 - private static function delete_trash_links( $id ) {
1260 + public static function delete_trash_links( $id ) {
1188 1261 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1189 1262 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1190 1263
1191 1264 return array(
@@ -1222,33 +1295,33 @@
1222 1295 * @since 3.0
1223 1296 */
1224 1297 public static function css_classes() {
1225 1298 $classes = array(
1226 - 'frm_total' => array(
1299 + 'frm_total' => array(
1227 1300 'label' => __( 'Total', 'formidable' ),
1228 1301 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1229 1302 ),
1230 - 'frm_total_big' => array(
1303 + 'frm_total_big' => array(
1231 1304 'label' => __( 'Big Total', 'formidable' ),
1232 1305 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1233 1306 ),
1234 - 'frm_scroll_box' => array(
1307 + 'frm_scroll_box' => array(
1235 1308 'label' => __( 'Scroll Box', 'formidable' ),
1236 1309 '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 1310 ),
1238 - 'frm_first' => array(
1311 + 'frm_first' => array(
1239 1312 'label' => __( 'First', 'formidable' ),
1240 1313 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1241 1314 ),
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' ),
1315 + 'frm_alignright' => __( 'Right', 'formidable' ),
1316 + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1317 + 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1318 + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1246 1319 'frm_color_block' => array(
1247 1320 'label' => __( 'Color Block', 'formidable' ),
1248 1321 'title' => __( 'Add a background color to the field or section.', 'formidable' ),
1249 1322 ),
1250 - 'frm_capitalize' => array(
1323 + 'frm_capitalize' => array(
1251 1324 'label' => __( 'Capitalize', 'formidable' ),
1252 1325 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1253 1326 ),
1254 1327 );
@@ -1291,9 +1364,9 @@
1291 1364 'trash' => __( 'Trash', 'formidable' ),
1292 1365 'publish' => __( 'Published', 'formidable' ),
1293 1366 );
1294 1367
1295 - if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1368 + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1296 1369 $status = 'publish';
1297 1370 }
1298 1371
1299 1372 $name = $nice_names[ $status ];
@@ -1301,101 +1374,94 @@
1301 1374 return $name;
1302 1375 }
1303 1376
1304 1377 /**
1305 - * @param array $categories
1378 + * Renders a template icon based on the given categories.
1379 + *
1380 + * @param array $categories The categories to render the icon for.
1306 1381 * @param array $atts {
1307 - * @type string $html 'span' or 'div'.
1308 - * @type boolean $bg Whether to add a bg color or not.
1382 + * Optional. An array of attributes for rendering.
1383 + * @type string $html 'span' or 'div'. Default 'span'.
1384 + * @type bool $bg Whether to add a background color or not. Default false.
1309 1385 * }
1310 1386 *
1311 1387 * @return void
1312 1388 */
1313 1389 public static function template_icon( $categories, $atts = array() ) {
1390 + // Define defaults.
1314 1391 $defaults = array(
1315 - 'html' => 'span',
1316 - 'bg' => false,
1392 + 'bg' => true,
1317 1393 );
1318 - $atts = array_merge( $defaults, $atts );
1394 + $atts = array_merge( $defaults, $atts );
1319 1395
1320 - $ignore = self::ignore_template_categories();
1396 + // Filter out ignored categories.
1397 + $ignore = self::get_license_types();
1321 1398 $categories = array_diff( $categories, $ignore );
1322 1399
1400 + // Define icons mapping.
1323 1401 $icons = array(
1324 - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1325 - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1326 - 'User Registration' => array( 'register', 'var(--pink)' ),
1402 + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1403 + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1404 + 'User Registration' => array( 'register', 'var(--pink)' ),
1327 1405 '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' ),
1406 + 'PayPal' => array( 'paypal' ),
1407 + 'Stripe' => array( 'credit_card', 'var(--green)' ),
1408 + 'Twilio' => array( 'sms' ),
1409 + 'Payment' => array( 'credit_card' ),
1410 + 'Order Form' => array( 'product' ),
1411 + 'Finance' => array( 'total' ),
1412 + 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1413 + 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1414 + 'Real Estate' => array( 'house' ),
1415 + 'Nonprofit' => array( 'heart_solid' ),
1416 + 'Calculator' => array( 'calculator', 'var(--purple)' ),
1417 + 'Quiz' => array( 'percent' ),
1418 + 'Registrations' => array( 'address_card' ),
1419 + 'Customer Service' => array( 'users_solid' ),
1420 + 'Education' => array( 'pencil' ),
1421 + 'Marketing' => array( 'eye' ),
1422 + 'Feedback' => array( 'smile' ),
1423 + 'Business Operations' => array( 'case' ),
1424 + 'Contact Form' => array( 'email' ),
1425 + 'Conversational Forms' => array( 'chat_forms' ),
1426 + 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1427 + 'Application' => array( 'align_right' ),
1428 + 'Signature' => array( 'signature' ),
1429 + '' => array( 'align_right' ),
1352 1430 );
1353 1431
1354 - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' );
1355 -
1432 + // Determine the icon to be used.
1356 1433 $icon = $icons[''];
1357 -
1358 1434 if ( count( $categories ) === 1 ) {
1359 1435 $category = reset( $categories );
1360 1436 $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1361 1437 } 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 );
1438 + $icons = array_intersect_key( $icons, array_flip( $categories ) );
1439 + $icon = reset( $icons );
1368 1440 }
1369 1441
1370 - $bg = isset( $icon[1] ) ? $icon[1] : '';
1442 + // Prepare variables for output.
1443 + $icon_name = $icon[0];
1444 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1371 1445
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"';
1446 + // Render the icon.
1447 + echo '<span class="frm-category-icon frm-icon-wrapper"';
1448 + if ( $bg_color && $atts['bg'] ) {
1449 + echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1376 1450 }
1377 - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"';
1378 1451 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' );
1452 + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' );
1383 1453 echo '</span>';
1384 - echo '</' . esc_attr( $atts['html'] ) . '>';
1385 1454 }
1386 1455
1387 1456 /**
1388 - * @since 4.03.01
1457 + * Get template install link.
1389 1458 *
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 1459 * @since 4.02
1460 + *
1461 + * @param array $template Template details.
1462 + * @param array $args Additional arguments.
1463 + * @return array The link attributes.
1398 1464 */
1399 1465 public static function get_template_install_link( $template, $args ) {
1400 1466 $defaults = array(
1401 1467 'class' => 'install-now',
@@ -1410,13 +1476,8 @@
1410 1476 'class' => 'frm-install-template',
1411 1477 'href' => 'rel',
1412 1478 'atts' => '',
1413 1479 );
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 1480 } else {
1420 1481 $link = array(
1421 1482 'url' => $args['pricing'],
1422 1483 'label' => __( 'Upgrade', 'formidable' ),
@@ -1431,9 +1492,8 @@
1431 1492 *
1432 1493 * @since 4.02.02
1433 1494 *
1434 1495 * @param array $args
1435 - *
1436 1496 * @return bool
1437 1497 */
1438 1498 public static function plan_is_allowed( $args ) {
1439 1499 if ( empty( $args['license_type'] ) ) {
@@ -1439,20 +1499,22 @@
1439 1499 if ( empty( $args['license_type'] ) ) {
1440 1500 return false;
1441 1501 }
1442 1502
1443 - $included = $args['license_type'] === strtolower( $args['plan_required'] );
1503 + $plans = array( 'free', 'personal', 'business', 'elite' );
1504 + $license_type = strtolower( $args['license_type'] );
1505 + $plan_required = strtolower( $args['plan_required'] );
1506 + $included = $license_type === $plan_required;
1444 1507
1445 - $plans = array( 'free', 'personal', 'business', 'elite' );
1446 - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) {
1508 + if ( $included || ! in_array( $plan_required, $plans, true ) ) {
1447 1509 return $included;
1448 1510 }
1449 1511
1450 1512 foreach ( $plans as $plan ) {
1451 - if ( $included || $plan === $args['license_type'] ) {
1513 + if ( $included || $plan === $license_type ) {
1452 1514 break;
1453 1515 }
1454 - $included = $plan === strtolower( $args['plan_required'] );
1516 + $included = $plan === $plan_required;
1455 1517 }
1456 1518
1457 1519 return $included;
1458 1520 }
@@ -1457,16 +1519,8 @@
1457 1519 return $included;
1458 1520 }
1459 1521
1460 1522 /**
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 1523 * If a template or add-on cannot be installed, show a message
1470 1524 * about which plan is required.
1471 1525 *
1472 1526 * @since 4.0
@@ -1477,9 +1531,9 @@
1477 1531 }
1478 1532
1479 1533 ?>
1480 1534 <p class="frm_plan_required">
1481 - <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1535 + <?php esc_html_e( 'Plan required:', 'formidable' ); ?>
1482 1536 <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1483 1537 <?php echo esc_html( $requires ); ?>
1484 1538 </a>
1485 1539 </p>
@@ -1489,9 +1543,9 @@
1489 1543 /**
1490 1544 * @since 4.0
1491 1545 *
1492 1546 * @param array $item
1493 - * @return string|false
1547 + * @return false|string
1494 1548 */
1495 1549 public static function get_plan_required( &$item ) {
1496 1550 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1551 return false;
@@ -1496,18 +1550,15 @@
1496 1550 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1497 1551 return false;
1498 1552 }
1499 1553
1500 - $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1554 + $plans = self::get_license_types();
1501 1555
1502 1556 foreach ( $item['categories'] as $k => $category ) {
1503 1557 if ( in_array( $category, $plans, true ) ) {
1504 1558 unset( $item['categories'][ $k ] );
1505 1559
1506 - if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1507 - // Show the current package name.
1508 - $category = 'Plus';
1509 - }
1560 + $category = self::convert_legacy_package_names( $category );
1510 1561
1511 1562 return $category;
1512 1563 }
1513 1564 }
@@ -1515,8 +1566,51 @@
1515 1566 return false;
1516 1567 }
1517 1568
1518 1569 /**
1570 + * Converts legacy package names to the current standard package name.
1571 + *
1572 + * @since 6.15
1573 + * @param string $package_name
1574 + * @return string The updated package name.
1575 + */
1576 + public static function convert_legacy_package_names( $package_name ) {
1577 + if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) {
1578 + $package_name = 'Plus';
1579 + }
1580 +
1581 + return $package_name;
1582 + }
1583 +
1584 + /**
1585 + * Get the license types.
1586 + *
1587 + * @since 6.15
1588 + *
1589 + * @param array $args
1590 + * @return array
1591 + */
1592 + public static function get_license_types( $args = array() ) {
1593 + $defaults = array(
1594 + 'include_all' => true,
1595 + 'case_lower' => false,
1596 + );
1597 + $args = wp_parse_args( $args, $defaults );
1598 +
1599 + $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' );
1600 +
1601 + if ( $args['include_all'] ) {
1602 + $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types );
1603 + }
1604 +
1605 + if ( $args['case_lower'] ) {
1606 + $license_types = array_map( 'strtolower', $license_types );
1607 + }
1608 +
1609 + return $license_types;
1610 + }
1611 +
1612 + /**
1519 1613 * Checks for warnings to be displayed after form settings are saved.
1520 1614 *
1521 1615 * @since 4.04
1522 1616 *
@@ -1552,9 +1646,9 @@
1552 1646
1553 1647 $options = $values['options'];
1554 1648 FrmAppHelper::sanitize_with_html( $options );
1555 1649
1556 - if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1650 + if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1557 1651 return false;
1558 1652 }
1559 1653
1560 1654 $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
@@ -1671,34 +1765,8 @@
1671 1765 );
1672 1766 }
1673 1767
1674 1768 /**
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 1769 * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined.
1702 1770 * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL.
1703 1771 *
1704 1772 * @since 5.0.16
@@ -1747,9 +1815,9 @@
1747 1815 }
1748 1816 $new_shortcode .= ' sanitize_url=1]';
1749 1817
1750 1818 $query = str_replace( $shortcode, $new_shortcode, $query );
1751 - }
1819 + }//end foreach
1752 1820
1753 1821 if ( $query === $original_query ) {
1754 1822 return $url;
1755 1823 }
@@ -1757,15 +1825,175 @@
1757 1825 return str_replace( $original_query, $query, $url );
1758 1826 }
1759 1827
1760 1828 /**
1829 + * Outputs the appropriate button text in the publish box.
1830 + *
1831 + * @return void
1832 + */
1833 + public static function publish_box_button_text() {
1834 + $is_new_template = FrmAppHelper::simple_get( 'new_template' );
1835 + $action = FrmAppHelper::simple_get( 'frm_action' );
1836 +
1837 + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) {
1838 + esc_html_e( 'Save', 'formidable' );
1839 + } else {
1840 + esc_html_e( 'Update', 'formidable' );
1841 + }
1842 + }
1843 +
1844 + /**
1845 + * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ].
1846 + * This allows shortcodes inside of the layout classes setting.
1847 + *
1848 + * @since 6.16
1849 + *
1850 + * @param string $classname
1851 + * @return string
1852 + */
1853 + public static function sanitize_layout_class( $classname ) {
1854 + // Strip out any percent-encoded characters.
1855 + $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
1856 +
1857 + // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'.
1858 + $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1859 +
1860 + return $sanitized;
1861 + }
1862 +
1863 + /**
1864 + * Returns true if the preview should be blocked.
1865 + *
1866 + * @since 6.20
1867 + *
1868 + * @param string $form_key
1869 + * @return bool
1870 + */
1871 + public static function should_block_preview( $form_key ) {
1872 + $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' );
1873 + /**
1874 + * Filters whether the form preview should be blocked.
1875 + *
1876 + * @since 6.20
1877 + *
1878 + * @param bool $should_block
1879 + * @param string $form_key
1880 + */
1881 + $should_block = (bool) apply_filters( 'frm_block_preview', $should_block, $form_key );
1882 + return $should_block;
1883 + }
1884 +
1885 + /**
1886 + * Checks if the form is loaded by API.
1887 + *
1888 + * @since 6.21
1889 + *
1890 + * @return bool
1891 + */
1892 + public static function form_is_loaded_by_api() {
1893 + global $frm_vars;
1894 + if ( ! empty( $frm_vars['inplace_edit'] ) ) {
1895 + return true;
1896 + }
1897 + return self::is_formidable_api_form() || self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview();
1898 + }
1899 +
1900 + /**
1901 + * @since 6.21
1902 + *
1903 + * @return bool
1904 + */
1905 + private static function is_visual_views_preview() {
1906 + return 'frm_views_process_box_preview' === FrmAppHelper::get_post_param( 'action' );
1907 + }
1908 +
1909 + /**
1910 + * @since 6.21
1911 + *
1912 + * @return bool
1913 + */
1914 + private static function is_elementor_ajax() {
1915 + return 'elementor_ajax' === FrmAppHelper::get_post_param( 'action' );
1916 + }
1917 +
1918 + /**
1919 + * @since 6.21
1920 + *
1921 + * @return bool
1922 + */
1923 + private static function is_gutenberg_editor() {
1924 + $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
1925 + if ( false !== strpos( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) {
1926 + return true;
1927 + }
1928 +
1929 + global $pagenow;
1930 + if ( 'post.php' === $pagenow ) {
1931 + return true;
1932 + }
1933 +
1934 + return false;
1935 + }
1936 +
1937 + /**
1938 + * @since 6.21
1939 + *
1940 + * @return bool
1941 + */
1942 + private static function is_formidable_api_form() {
1943 + if ( ! class_exists( 'FrmAPIAppController' ) ) {
1944 + return false;
1945 + }
1946 +
1947 + $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
1948 + if ( false !== strpos( $url, '/wp-json/frm/v2/forms/' ) ) {
1949 + // Prevent the honeypot from appearing for an API loaded form.
1950 + // This is to prevent conflicts where the script is not working.
1951 + return true;
1952 + }
1953 +
1954 + if ( is_callable( 'FrmProFormState::get_from_request' ) ) {
1955 + $api = FrmProFormState::get_from_request( 'a', 0 );
1956 +
1957 + if ( $api ) {
1958 + return true;
1959 + }
1960 + }
1961 +
1962 + return false;
1963 + }
1964 +
1965 + /**
1966 + * @since 3.0
1967 + * @deprecated 6.11
1968 + *
1969 + * @param array $atts
1970 + * @return void
1971 + */
1972 + public static function actions_dropdown( $atts ) {
1973 + _deprecated_function( __METHOD__, '6.11' );
1974 +
1975 + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
1976 + return;
1977 + }
1978 +
1979 + $status = $atts['status'];
1980 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1981 + $trash_link = self::delete_trash_info( $form_id, $status );
1982 + $links = self::get_action_links( $form_id, $status );
1983 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php';
1984 + }
1985 +
1986 + /**
1761 1987 * Check if Pro isn't up to date yet.
1762 1988 * If Pro is active but using a version earlier than v6.2 fallback to Pro for AJAX submit (so things don't all happen twice).
1763 1989 *
1764 1990 * @since 6.2
1991 + * @deprecated 6.20
1765 1992 *
1766 1993 * @return bool
1767 1994 */
1768 1995 public static function should_use_pro_for_ajax_submit() {
1769 - return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' );
1996 + _deprecated_function( __METHOD__, '6.20' );
1997 + return false;
1770 1998 }
1771 1999 }