| @@ -30,11 +30,9 @@ | ||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | public static function get_direct_link( $key, $form = false ) { |
| 33 | 33 | $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) ); |
| 34 | - $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 35 | - | |
| 36 | - return $target_url; | |
| 34 | + return apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | 37 | /** |
| 40 | 38 | * @param string $field_name |
| @@ -69,22 +67,24 @@ | ||
| 69 | 67 | $add_html = array(); |
| 70 | 68 | self::add_html_attr( $args['onchange'], 'onchange', $add_html ); |
| 71 | 69 | self::add_html_attr( $args['class'], 'class', $add_html ); |
| 72 | 70 | |
| 71 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 73 | 72 | ?> |
| 74 | 73 | <select name="<?php echo esc_attr( $field_name ); ?>" |
| 75 | 74 | id="<?php echo esc_attr( $args['field_id'] ); ?>" |
| 76 | 75 | <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 77 | 76 | <?php if ( $args['blank'] ) { ?> |
| 78 | - <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 77 | + <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; // phpcs:ignore Universal.Operators.StrictComparisons ?></option> | |
| 79 | 78 | <?php } ?> |
| 80 | 79 | <?php foreach ( $forms as $form ) { ?> |
| 81 | 80 | <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> |
| 82 | - <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> | |
| 81 | + <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 83 | 82 | </option> |
| 84 | 83 | <?php } ?> |
| 85 | 84 | </select> |
| 86 | 85 | <?php |
| 86 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * @since 2.0.6 |
| @@ -95,10 +95,10 @@ | ||
| 95 | 95 | * |
| 96 | 96 | * @return void |
| 97 | 97 | */ |
| 98 | 98 | public static function add_html_attr( $class, $param, &$add_html ) { |
| 99 | - if ( ! empty( $class ) ) { | |
| 100 | - $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"'; | |
| 99 | + if ( $class ) { | |
| 100 | + $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( sanitize_text_field( $class ) ) . '"'; | |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| @@ -105,9 +105,9 @@ | ||
| 105 | 105 | * @param false|object|string $selected - The label for the placeholder, or the form object. |
| 106 | 106 | * |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - public static function form_switcher( $selected = false ) { | |
| 109 | + public static function form_switcher( $selected = false ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 110 | 110 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 111 | 111 | $forms = FrmForm::get_published_forms( $where ); |
| 112 | 112 | |
| 113 | 113 | $args = array( |
| @@ -155,8 +155,9 @@ | ||
| 155 | 155 | $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected; |
| 156 | 156 | $name = '' === $name || is_null( $name ) ? self::get_no_title_text() : strip_tags( $name ); |
| 157 | 157 | $truncated_name = FrmAppHelper::truncate( $name, 25 ); |
| 158 | 158 | |
| 159 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 159 | 160 | if ( count( $forms ) < 2 ) { |
| 160 | 161 | ?> |
| 161 | 162 | <div id="frm_bs_dropdown"> |
| 162 | 163 | <h1> |
| @@ -209,9 +210,9 @@ | ||
| 209 | 210 | $args['form'] = $form->id; |
| 210 | 211 | } |
| 211 | 212 | |
| 212 | 213 | $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ); |
| 213 | - $form_name = empty( $form->name ) ? self::get_no_title_text() : $form->name; | |
| 214 | + $form_name = ! empty( $form->name ) ? $form->name : self::get_no_title_text(); | |
| 214 | 215 | ?> |
| 215 | 216 | <li class="frm-dropdown-form"> |
| 216 | 217 | <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between"> |
| 217 | 218 | <?php echo esc_html( $form_name ); ?> |
| @@ -233,8 +234,9 @@ | ||
| 233 | 234 | ?> |
| 234 | 235 | </ul> |
| 235 | 236 | </div> |
| 236 | 237 | <?php |
| 238 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 237 | 239 | } |
| 238 | 240 | |
| 239 | 241 | /** |
| 240 | 242 | * @param string $col |
| @@ -243,10 +245,10 @@ | ||
| 243 | 245 | * |
| 244 | 246 | * @return void |
| 245 | 247 | */ |
| 246 | 248 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 247 | - echo $sort_col == $col ? 'sorted' : 'sortable'; | |
| 248 | - echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; | |
| 249 | + echo $sort_col == $col ? 'sorted' : 'sortable'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 250 | + echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 249 | 251 | } |
| 250 | 252 | |
| 251 | 253 | /** |
| 252 | 254 | * @since 3.0 |
| @@ -255,15 +257,9 @@ | ||
| 255 | 257 | * |
| 256 | 258 | * @return string |
| 257 | 259 | */ |
| 258 | 260 | public static function get_field_link_name( $field_type ) { |
| 259 | - if ( is_array( $field_type ) ) { | |
| 260 | - $field_label = $field_type['name']; | |
| 261 | - } else { | |
| 262 | - $field_label = $field_type; | |
| 263 | - } | |
| 264 | - | |
| 265 | - return $field_label; | |
| 261 | + return is_array( $field_type ) ? $field_type['name'] : $field_type; | |
| 266 | 262 | } |
| 267 | 263 | |
| 268 | 264 | /** |
| 269 | 265 | * @since 3.0 |
| @@ -272,15 +268,9 @@ | ||
| 272 | 268 | * |
| 273 | 269 | * @return string |
| 274 | 270 | */ |
| 275 | 271 | public static function get_field_link_icon( $field_type ) { |
| 276 | - if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) { | |
| 277 | - $icon = $field_type['icon']; | |
| 278 | - } else { | |
| 279 | - $icon = 'frm_icon_font frm_pencil_icon'; | |
| 280 | - } | |
| 281 | - | |
| 282 | - return $icon; | |
| 272 | + return is_array( $field_type ) && isset( $field_type['icon'] ) ? $field_type['icon'] : 'frmfont frm_pencil_icon'; | |
| 283 | 273 | } |
| 284 | 274 | |
| 285 | 275 | /** |
| 286 | 276 | * Get the invalid form error message |
| @@ -318,9 +308,9 @@ | ||
| 318 | 308 | public static function get_success_message( $atts ) { |
| 319 | 309 | $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] ); |
| 320 | 310 | |
| 321 | 311 | // Only autop if the message includes line breaks. |
| 322 | - $autop = strpos( $message, "\n" ) !== false; | |
| 312 | + $autop = str_contains( $message, "\n" ); | |
| 323 | 313 | |
| 324 | 314 | /** |
| 325 | 315 | * Filters whether to autop the success message. |
| 326 | 316 | * This is false by default if the message does not include line breaks. |
| @@ -337,10 +327,9 @@ | ||
| 337 | 327 | $message = FrmAppHelper::use_wpautop( $message ); |
| 338 | 328 | } |
| 339 | 329 | |
| 340 | 330 | $message = do_shortcode( $message ); |
| 341 | - $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 342 | - return $message; | |
| 331 | + return '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 343 | 332 | } |
| 344 | 333 | |
| 345 | 334 | /** |
| 346 | 335 | * Used when a form is created |
| @@ -351,9 +340,9 @@ | ||
| 351 | 340 | */ |
| 352 | 341 | public static function setup_new_vars( $values = array() ) { |
| 353 | 342 | global $wpdb; |
| 354 | 343 | |
| 355 | - if ( ! empty( $values ) ) { | |
| 344 | + if ( $values ) { | |
| 356 | 345 | $post_values = $values; |
| 357 | 346 | } else { |
| 358 | 347 | $values = array(); |
| 359 | 348 | $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -388,9 +377,9 @@ | ||
| 388 | 377 | } |
| 389 | 378 | unset( $defaults ); |
| 390 | 379 | |
| 391 | 380 | if ( ! isset( $values['form_key'] ) ) { |
| 392 | - $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); | |
| 381 | + $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 393 | 382 | } |
| 394 | 383 | |
| 395 | 384 | $values = self::fill_default_opts( $values, false, $post_values ); |
| 396 | 385 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| @@ -407,9 +396,9 @@ | ||
| 407 | 396 | * |
| 408 | 397 | * @return array |
| 409 | 398 | */ |
| 410 | 399 | public static function setup_edit_vars( $values, $record, $post_values = array() ) { |
| 411 | - if ( empty( $post_values ) ) { | |
| 400 | + if ( ! $post_values ) { | |
| 412 | 401 | $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 413 | 402 | } |
| 414 | 403 | |
| 415 | 404 | $values['form_key'] = $post_values['form_key'] ?? $record->form_key; |
| @@ -427,13 +416,11 @@ | ||
| 427 | 416 | * @param array|false $post_values |
| 428 | 417 | * |
| 429 | 418 | * @return array |
| 430 | 419 | */ |
| 431 | - public static function fill_default_opts( $values, $record, $post_values ) { | |
| 420 | + public static function fill_default_opts( $values, $record, $post_values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 432 | 421 | |
| 433 | - $defaults = self::get_default_opts(); | |
| 434 | - | |
| 435 | - foreach ( $defaults as $var => $default ) { | |
| 422 | + foreach ( self::get_default_opts() as $var => $default ) { | |
| 436 | 423 | if ( is_array( $default ) ) { |
| 437 | 424 | if ( ! isset( $values[ $var ] ) ) { |
| 438 | 425 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 439 | 426 | } |
| @@ -438,13 +425,13 @@ | ||
| 438 | 425 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 439 | 426 | } |
| 440 | 427 | |
| 441 | 428 | foreach ( $default as $k => $v ) { |
| 442 | - $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 ); | |
| 429 | + $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 443 | 430 | |
| 444 | 431 | if ( is_array( $v ) ) { |
| 445 | 432 | foreach ( $v as $k1 => $v1 ) { |
| 446 | - $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 ); | |
| 433 | + $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 447 | 434 | unset( $k1, $v1 ); |
| 448 | 435 | } |
| 449 | 436 | } |
| 450 | 437 | |
| @@ -450,9 +437,9 @@ | ||
| 450 | 437 | |
| 451 | 438 | unset( $k, $v ); |
| 452 | 439 | } |
| 453 | 440 | } else { |
| 454 | - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); | |
| 441 | + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 455 | 442 | } |
| 456 | 443 | |
| 457 | 444 | unset( $var, $default ); |
| 458 | 445 | }//end foreach |
| @@ -496,11 +483,9 @@ | ||
| 496 | 483 | * |
| 497 | 484 | * @return void |
| 498 | 485 | */ |
| 499 | 486 | public static function fill_form_options( &$options, $values ) { |
| 500 | - $defaults = self::get_default_opts(); | |
| 501 | - | |
| 502 | - foreach ( $defaults as $var => $default ) { | |
| 487 | + foreach ( self::get_default_opts() as $var => $default ) { | |
| 503 | 488 | $options[ $var ] = $values['options'][ $var ] ?? $default; |
| 504 | 489 | unset( $var, $default ); |
| 505 | 490 | } |
| 506 | 491 | } |
| @@ -538,11 +523,9 @@ | ||
| 538 | 523 | /** |
| 539 | 524 | * @return string |
| 540 | 525 | */ |
| 541 | 526 | public static function get_draft_link() { |
| 542 | - $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 543 | - | |
| 544 | - return $link; | |
| 527 | + return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 545 | 528 | } |
| 546 | 529 | |
| 547 | 530 | /** |
| 548 | 531 | * Gets start over button shortcode. |
| @@ -566,9 +549,9 @@ | ||
| 566 | 549 | */ |
| 567 | 550 | public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) { |
| 568 | 551 | $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values ); |
| 569 | 552 | |
| 570 | - if ( ! strpos( $button, '[button_action]' ) ) { | |
| 553 | + if ( ! str_contains( $button, '[button_action]' ) ) { | |
| 571 | 554 | echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 572 | 555 | return; |
| 573 | 556 | } |
| 574 | 557 | |
| @@ -581,12 +564,11 @@ | ||
| 581 | 564 | $button = FrmAppHelper::kses_submit_button( $button ); |
| 582 | 565 | } |
| 583 | 566 | |
| 584 | 567 | $button_parts = explode( '[button_action]', $button ); |
| 568 | + $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 585 | 569 | |
| 586 | - $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 587 | - | |
| 588 | - if ( ! empty( $classes ) ) { | |
| 570 | + if ( $classes ) { | |
| 589 | 571 | $classes = implode( ' ', $classes ); |
| 590 | 572 | $button_class = 'frm_button_submit'; |
| 591 | 573 | |
| 592 | 574 | if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) { |
| @@ -691,9 +673,12 @@ | ||
| 691 | 673 | |
| 692 | 674 | /** |
| 693 | 675 | * @since 4.0 |
| 694 | 676 | * |
| 695 | - * @param array $args | |
| 677 | + * @param array $args Includes 'id', 'key', 'name', 'type' and 'class'. Optionally 'id_label' | |
| 678 | + * and 'key_label' to show something other than the id or key, and | |
| 679 | + * 'name_suffix'/'key_suffix' for text appended after the name or key is | |
| 680 | + * truncated, so a shortcode option like ' show=first' survives the truncation. | |
| 696 | 681 | * |
| 697 | 682 | * @return void |
| 698 | 683 | */ |
| 699 | 684 | public static function insert_opt_html( $args ) { |
| @@ -716,39 +701,45 @@ | ||
| 716 | 701 | if ( 'url' === $args['type'] ) { |
| 717 | 702 | $class .= ' frm_insert_url'; |
| 718 | 703 | } |
| 719 | 704 | |
| 720 | - $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ); | |
| 705 | + $full_name = $args['name'] . ( $args['name_suffix'] ?? '' ); | |
| 706 | + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ) . ( $args['name_suffix'] ?? '' ); | |
| 721 | 707 | |
| 722 | - if ( isset( $field['icon'] ) ) { | |
| 723 | - $icon = FrmAppHelper::icon_by_class( | |
| 724 | - $field['icon'], | |
| 725 | - array( | |
| 726 | - 'aria-hidden' => 'true', | |
| 727 | - 'echo' => false, | |
| 728 | - ) | |
| 729 | - ); | |
| 730 | - } else { | |
| 731 | - $icon = ''; | |
| 732 | - } | |
| 708 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 733 | 709 | ?> |
| 734 | 710 | <li class="<?php echo esc_attr( $class ); ?>"> |
| 735 | 711 | <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>"> |
| 736 | 712 | <?php |
| 737 | - echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 738 | - echo esc_html( $truncated_name ); | |
| 713 | + if ( isset( $field['icon'] ) ) { | |
| 714 | + FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 715 | + } | |
| 716 | + | |
| 717 | + printf( | |
| 718 | + '<span title="%s">%s</span>', | |
| 719 | + esc_attr( $full_name ), | |
| 720 | + esc_html( $truncated_name ) | |
| 721 | + ); | |
| 739 | 722 | ?> |
| 740 | - <span>[<?php echo esc_attr( $args['id_label'] ?? $args['id'] ); ?>]</span> | |
| 723 | + <span>[<?php echo esc_html( $args['id_label'] ?? $args['id'] ); ?>]</span> | |
| 741 | 724 | </a> |
| 742 | 725 | <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>"> |
| 743 | 726 | <?php |
| 744 | - echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 745 | - echo esc_html( $truncated_name ); | |
| 727 | + if ( isset( $field['icon'] ) ) { | |
| 728 | + FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 729 | + } | |
| 730 | + | |
| 731 | + printf( | |
| 732 | + '<span title="%s">%s</span>', | |
| 733 | + esc_attr( $full_name ), | |
| 734 | + esc_html( $truncated_name ) | |
| 735 | + ); | |
| 746 | 736 | ?> |
| 747 | - <span>[<?php echo esc_attr( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) ); ?>]</span> | |
| 737 | + <span>[<?php echo esc_html( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) . ( $args['key_suffix'] ?? '' ) ); ?>]</span> | |
| 748 | 738 | </a> |
| 749 | 739 | </li> |
| 750 | 740 | <?php |
| 741 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 751 | 742 | } |
| 752 | 743 | |
| 753 | 744 | /** |
| 754 | 745 | * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up. |
| @@ -782,20 +773,22 @@ | ||
| 782 | 773 | |
| 783 | 774 | $args = array_merge( $defaults, $args ); |
| 784 | 775 | $has_tooltip = ! empty( $args['title'] ); |
| 785 | 776 | |
| 777 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 786 | 778 | ?> |
| 787 | 779 | <li class="<?php echo esc_attr( $args['class'] ); ?>"> |
| 788 | 780 | <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>" |
| 789 | 781 | <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?> |
| 790 | 782 | data-code="<?php echo esc_attr( $args['code'] ); ?>"> |
| 791 | - <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 783 | + <?php echo esc_html( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 792 | 784 | <span> |
| 793 | - [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 785 | + [<?php echo esc_html( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 794 | 786 | </span> |
| 795 | 787 | </a> |
| 796 | 788 | </li> |
| 797 | 789 | <?php |
| 790 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 798 | 791 | } |
| 799 | 792 | |
| 800 | 793 | /** |
| 801 | 794 | * Some field types in add-ons may have been added with only |
| @@ -810,9 +803,9 @@ | ||
| 810 | 803 | public static function prepare_field_type( &$field ) { |
| 811 | 804 | if ( ! is_array( $field ) ) { |
| 812 | 805 | $field = array( |
| 813 | 806 | 'name' => $field, |
| 814 | - 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 807 | + 'icon' => 'frmfont frm_pencil_icon', | |
| 815 | 808 | ); |
| 816 | 809 | } |
| 817 | 810 | } |
| 818 | 811 | |
| @@ -827,9 +820,9 @@ | ||
| 827 | 820 | * |
| 828 | 821 | * @return void |
| 829 | 822 | */ |
| 830 | 823 | public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { |
| 831 | - if ( empty( $fields ) ) { | |
| 824 | + if ( ! $fields ) { | |
| 832 | 825 | return; |
| 833 | 826 | } |
| 834 | 827 | |
| 835 | 828 | $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) ); |
| @@ -901,9 +894,9 @@ | ||
| 901 | 894 | |
| 902 | 895 | FrmField::create( $end_section_values ); |
| 903 | 896 | |
| 904 | 897 | if ( $move === 'move' ) { |
| 905 | - // bump the order of current field unless we're at the end of the form | |
| 898 | + // Bump the order of current field unless we're at the end of the form | |
| 906 | 899 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 907 | 900 | } |
| 908 | 901 | |
| 909 | 902 | $add_order += 2; |
| @@ -932,14 +925,14 @@ | ||
| 932 | 925 | $replace_with = $form->name; |
| 933 | 926 | } elseif ( $code === 'form_description' ) { |
| 934 | 927 | $replace_with = FrmAppHelper::use_wpautop( $form->description ); |
| 935 | 928 | } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) { |
| 936 | - $replace_with = FrmAppHelper::simple_get( 'entry' ); | |
| 929 | + $replace_with = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); | |
| 937 | 930 | } else { |
| 938 | 931 | $replace_with = ''; |
| 939 | 932 | } |
| 940 | 933 | |
| 941 | - FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); | |
| 934 | + FrmShortcodeHelper::remove_inline_conditions( FrmAppHelper::is_true( $show ) && $replace_with != '', $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 942 | 935 | } |
| 943 | 936 | |
| 944 | 937 | // Replace [form_key]. |
| 945 | 938 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| @@ -946,9 +939,9 @@ | ||
| 946 | 939 | |
| 947 | 940 | // Replace [frmurl]. |
| 948 | 941 | $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html ); |
| 949 | 942 | |
| 950 | - if ( strpos( $html, '[button_label]' ) ) { | |
| 943 | + if ( str_contains( $html, '[button_label]' ) ) { | |
| 951 | 944 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| 952 | 945 | $submit_label = apply_filters( 'frm_submit_button', $title, $form ); |
| 953 | 946 | $submit_label = esc_attr( do_shortcode( $submit_label ) ); |
| 954 | 947 | $html = str_replace( '[button_label]', $submit_label, $html ); |
| @@ -955,22 +948,22 @@ | ||
| 955 | 948 | } |
| 956 | 949 | |
| 957 | 950 | $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values ); |
| 958 | 951 | |
| 959 | - if ( strpos( $html, '[if back_button]' ) ) { | |
| 952 | + if ( str_contains( $html, '[if back_button]' ) ) { | |
| 960 | 953 | $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html ); |
| 961 | 954 | } |
| 962 | 955 | |
| 963 | - if ( strpos( $html, '[if save_draft]' ) ) { | |
| 956 | + if ( str_contains( $html, '[if save_draft]' ) ) { | |
| 964 | 957 | $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html ); |
| 965 | 958 | } |
| 966 | 959 | |
| 967 | - if ( strpos( $html, '[if start_over]' ) ) { | |
| 960 | + if ( str_contains( $html, '[if start_over]' ) ) { | |
| 968 | 961 | $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html ); |
| 969 | 962 | } |
| 970 | 963 | |
| 971 | 964 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 972 | - $html = do_shortcode( $html ); | |
| 965 | + return do_shortcode( $html ); | |
| 973 | 966 | } |
| 974 | 967 | |
| 975 | 968 | return $html; |
| 976 | 969 | } |
| @@ -1015,13 +1008,10 @@ | ||
| 1015 | 1008 | public static function get_form_style_class( $form = false ) { |
| 1016 | 1009 | $style = self::get_form_style( $form ); |
| 1017 | 1010 | $class = ' with_frm_style'; |
| 1018 | 1011 | |
| 1019 | - if ( empty( $style ) ) { | |
| 1020 | - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { | |
| 1021 | - return $class; | |
| 1022 | - } | |
| 1023 | - return; | |
| 1012 | + if ( ! $style ) { | |
| 1013 | + return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null; | |
| 1024 | 1014 | } |
| 1025 | 1015 | |
| 1026 | 1016 | // If submit button needs to be inline or centered. |
| 1027 | 1017 | if ( is_object( $form ) ) { |
| @@ -1042,11 +1032,9 @@ | ||
| 1042 | 1032 | } elseif ( 'center' === $submit_align ) { |
| 1043 | 1033 | $class .= ' frm_center_submit'; |
| 1044 | 1034 | } |
| 1045 | 1035 | |
| 1046 | - $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 1047 | - | |
| 1048 | - return $class; | |
| 1036 | + return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 1049 | 1037 | } |
| 1050 | 1038 | |
| 1051 | 1039 | /** |
| 1052 | 1040 | * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work. |
| @@ -1057,13 +1045,13 @@ | ||
| 1057 | 1045 | * |
| 1058 | 1046 | * @return bool |
| 1059 | 1047 | */ |
| 1060 | 1048 | private static function form_should_be_inline_and_missing_class( $form ) { |
| 1061 | - if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 1062 | - // not missing class, avoid adding it twice. | |
| 1049 | + if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 1050 | + // Not missing class, avoid adding it twice. | |
| 1063 | 1051 | return false; |
| 1064 | 1052 | } |
| 1065 | - return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' ); | |
| 1053 | + return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' ); | |
| 1066 | 1054 | } |
| 1067 | 1055 | |
| 1068 | 1056 | /** |
| 1069 | 1057 | * Returns appropriate class if form has top labels |
| @@ -1118,26 +1106,25 @@ | ||
| 1118 | 1106 | * @return bool |
| 1119 | 1107 | */ |
| 1120 | 1108 | private static function field_has_top_label( $field, $form ) { |
| 1121 | 1109 | $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form ); |
| 1122 | - | |
| 1123 | - return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); | |
| 1110 | + return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true ); | |
| 1124 | 1111 | } |
| 1125 | 1112 | |
| 1126 | 1113 | /** |
| 1127 | 1114 | * @param array|bool|int|object|string $form |
| 1128 | 1115 | * |
| 1129 | - * @return string | |
| 1116 | + * @return int|string | |
| 1130 | 1117 | */ |
| 1131 | 1118 | public static function get_form_style( $form ) { |
| 1132 | 1119 | $style = 1; |
| 1133 | 1120 | |
| 1134 | - if ( empty( $form ) || 'default' === $form ) { | |
| 1121 | + if ( ! $form || 'default' === $form ) { | |
| 1135 | 1122 | return $style; |
| 1136 | 1123 | } |
| 1137 | 1124 | |
| 1138 | 1125 | if ( is_object( $form ) && $form->parent_form_id ) { |
| 1139 | - // get the parent form if this is a child | |
| 1126 | + // Get the parent form if this is a child | |
| 1140 | 1127 | $form = $form->parent_form_id; |
| 1141 | 1128 | } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) { |
| 1142 | 1129 | $form = $form['parent_form_id']; |
| 1143 | 1130 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| @@ -1147,11 +1134,9 @@ | ||
| 1147 | 1134 | if ( $form && ( is_string( $form ) || is_int( $form ) ) ) { |
| 1148 | 1135 | $form = FrmForm::getOne( $form ); |
| 1149 | 1136 | } |
| 1150 | 1137 | |
| 1151 | - $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 1152 | - | |
| 1153 | - return $style; | |
| 1138 | + return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 1154 | 1139 | } |
| 1155 | 1140 | |
| 1156 | 1141 | /** |
| 1157 | 1142 | * Display the validation error messages when an entry is submitted |
| @@ -1164,13 +1149,13 @@ | ||
| 1164 | 1149 | */ |
| 1165 | 1150 | public static function show_errors( $args ) { |
| 1166 | 1151 | $invalid_msg = self::get_invalid_error_message( $args ); |
| 1167 | 1152 | |
| 1168 | - if ( empty( $invalid_msg ) ) { | |
| 1169 | - $show_img = false; | |
| 1170 | - } else { | |
| 1153 | + if ( $invalid_msg ) { | |
| 1171 | 1154 | echo wp_kses_post( $invalid_msg ); |
| 1172 | 1155 | $show_img = true; |
| 1156 | + } else { | |
| 1157 | + $show_img = false; | |
| 1173 | 1158 | } |
| 1174 | 1159 | |
| 1175 | 1160 | self::show_error( |
| 1176 | 1161 | array( |
| @@ -1192,15 +1177,15 @@ | ||
| 1192 | 1177 | * |
| 1193 | 1178 | * @return void |
| 1194 | 1179 | */ |
| 1195 | 1180 | public static function show_error( $args ) { |
| 1196 | - // remove any blank messages | |
| 1181 | + // Remove any blank messages | |
| 1197 | 1182 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| 1198 | 1183 | |
| 1199 | 1184 | $line_break_first = $args['show_img']; |
| 1200 | 1185 | |
| 1201 | 1186 | foreach ( $args['errors'] as $error_key => $error ) { |
| 1202 | - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1187 | + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) { | |
| 1203 | 1188 | continue; |
| 1204 | 1189 | } |
| 1205 | 1190 | |
| 1206 | 1191 | $id = str_replace( 'field', 'field_', $error_key ); |
| @@ -1225,8 +1210,9 @@ | ||
| 1225 | 1210 | */ |
| 1226 | 1211 | public static function maybe_get_scroll_js( $id ) { |
| 1227 | 1212 | $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) ); |
| 1228 | 1213 | |
| 1214 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1229 | 1215 | if ( $offset != - 1 ) { |
| 1230 | 1216 | self::get_scroll_js( $id ); |
| 1231 | 1217 | } |
| 1232 | 1218 | } |
| @@ -1255,9 +1241,9 @@ | ||
| 1255 | 1241 | |
| 1256 | 1242 | $actions = array(); |
| 1257 | 1243 | $trash_links = self::delete_trash_links( $form_id ); |
| 1258 | 1244 | |
| 1259 | - if ( 'trash' == $form->status ) { | |
| 1245 | + if ( 'trash' === $form->status ) { | |
| 1260 | 1246 | $actions['restore'] = $trash_links['restore']; |
| 1261 | 1247 | |
| 1262 | 1248 | if ( current_user_can( 'frm_delete_forms' ) ) { |
| 1263 | 1249 | $actions['trash'] = $trash_links['delete']; |
| @@ -1268,15 +1254,15 @@ | ||
| 1268 | 1254 | if ( $form->is_template ) { |
| 1269 | 1255 | $actions['frm_duplicate'] = array( |
| 1270 | 1256 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1271 | 1257 | 'label' => __( 'Create Form from Template', 'formidable' ), |
| 1272 | - 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1258 | + 'icon' => 'frmfont frm_clone_icon', | |
| 1273 | 1259 | ); |
| 1274 | 1260 | } else { |
| 1275 | 1261 | $actions['duplicate'] = array( |
| 1276 | 1262 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1277 | - 'label' => __( 'Duplicate Form', 'formidable' ), | |
| 1278 | - 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1263 | + 'label' => __( 'Duplicate', 'formidable' ), | |
| 1264 | + 'icon' => 'frmfont frm_clone_icon', | |
| 1279 | 1265 | ); |
| 1280 | 1266 | } |
| 1281 | 1267 | |
| 1282 | 1268 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| @@ -1297,10 +1283,9 @@ | ||
| 1297 | 1283 | return ''; |
| 1298 | 1284 | } |
| 1299 | 1285 | |
| 1300 | 1286 | $label = self::edit_form_link_label( $data ); |
| 1301 | - $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1302 | - return $link; | |
| 1287 | + return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1303 | 1288 | } |
| 1304 | 1289 | |
| 1305 | 1290 | /** |
| 1306 | 1291 | * Returns a text used when no title is set. |
| @@ -1323,8 +1308,9 @@ | ||
| 1323 | 1308 | |
| 1324 | 1309 | if ( ! $name ) { |
| 1325 | 1310 | return self::get_no_title_text(); |
| 1326 | 1311 | } |
| 1312 | + | |
| 1327 | 1313 | return FrmAppHelper::truncate( $name, 40 ); |
| 1328 | 1314 | } |
| 1329 | 1315 | |
| 1330 | 1316 | /** |
| @@ -1332,14 +1318,9 @@ | ||
| 1332 | 1318 | * |
| 1333 | 1319 | * @return int|string |
| 1334 | 1320 | */ |
| 1335 | 1321 | private static function get_form_id_from_data( $data ) { |
| 1336 | - if ( is_object( $data ) ) { | |
| 1337 | - $form_id = $data->id; | |
| 1338 | - } else { | |
| 1339 | - $form_id = $data; | |
| 1340 | - } | |
| 1341 | - return $form_id; | |
| 1322 | + return is_object( $data ) ? $data->id : $data; | |
| 1342 | 1323 | } |
| 1343 | 1324 | |
| 1344 | 1325 | /** |
| 1345 | 1326 | * @param mixed $data |
| @@ -1347,14 +1328,13 @@ | ||
| 1347 | 1328 | * @return string |
| 1348 | 1329 | */ |
| 1349 | 1330 | private static function get_form_name_from_data( $data ) { |
| 1350 | 1331 | if ( is_object( $data ) ) { |
| 1351 | - $form_name = $data->name; | |
| 1352 | - } else { | |
| 1353 | - $form_id = $data; | |
| 1354 | - $form_name = FrmForm::getName( $form_id ); | |
| 1332 | + return $data->name; | |
| 1355 | 1333 | } |
| 1356 | - return $form_name; | |
| 1334 | + | |
| 1335 | + $form_id = $data; | |
| 1336 | + return FrmForm::getName( $form_id ); | |
| 1357 | 1337 | } |
| 1358 | 1338 | |
| 1359 | 1339 | /** |
| 1360 | 1340 | * @param int $id |
| @@ -1364,9 +1344,8 @@ | ||
| 1364 | 1344 | * @return string |
| 1365 | 1345 | */ |
| 1366 | 1346 | public static function delete_trash_link( $id, $status, $length = 'label' ) { |
| 1367 | 1347 | $link_details = self::delete_trash_info( $id, $status ); |
| 1368 | - | |
| 1369 | 1348 | return self::format_link_html( $link_details, $length ); |
| 1370 | 1349 | } |
| 1371 | 1350 | |
| 1372 | 1351 | /** |
| @@ -1379,30 +1358,30 @@ | ||
| 1379 | 1358 | */ |
| 1380 | 1359 | public static function format_link_html( $link_details, $length = 'label' ) { |
| 1381 | 1360 | $link = ''; |
| 1382 | 1361 | |
| 1383 | - if ( ! empty( $link_details ) ) { | |
| 1384 | - $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1362 | + if ( ! $link_details ) { | |
| 1363 | + return $link; | |
| 1364 | + } | |
| 1385 | 1365 | |
| 1386 | - if ( isset( $link_details['data'] ) ) { | |
| 1387 | - foreach ( $link_details['data'] as $data => $value ) { | |
| 1388 | - $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1389 | - } | |
| 1390 | - } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1391 | - $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1366 | + $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1367 | + | |
| 1368 | + if ( isset( $link_details['data'] ) ) { | |
| 1369 | + foreach ( $link_details['data'] as $data => $value ) { | |
| 1370 | + $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1392 | 1371 | } |
| 1372 | + } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1373 | + $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1374 | + } | |
| 1393 | 1375 | |
| 1394 | - $label = ( $link_details[ $length ] ?? $link_details['label'] ); | |
| 1376 | + $label = $link_details[ $length ] ?? $link_details['label']; | |
| 1395 | 1377 | |
| 1396 | - if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1397 | - $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1398 | - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1399 | - } | |
| 1400 | - | |
| 1401 | - $link .= '>' . $label . '</a>'; | |
| 1378 | + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1379 | + $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1380 | + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1402 | 1381 | } |
| 1403 | 1382 | |
| 1404 | - return $link; | |
| 1383 | + return $link . ( '>' . $label . '</a>' ); | |
| 1405 | 1384 | } |
| 1406 | 1385 | |
| 1407 | 1386 | /** |
| 1408 | 1387 | * @since 3.0 |
| @@ -1417,13 +1396,9 @@ | ||
| 1417 | 1396 | |
| 1418 | 1397 | if ( 'trash' === $status ) { |
| 1419 | 1398 | $info = $labels['restore']; |
| 1420 | 1399 | } elseif ( current_user_can( 'frm_delete_forms' ) ) { |
| 1421 | - if ( EMPTY_TRASH_DAYS ) { | |
| 1422 | - $info = $labels['trash']; | |
| 1423 | - } else { | |
| 1424 | - $info = $labels['delete']; | |
| 1425 | - } | |
| 1400 | + $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete']; | |
| 1426 | 1401 | } else { |
| 1427 | 1402 | $info = array(); |
| 1428 | 1403 | } |
| 1429 | 1404 | |
| @@ -1450,9 +1425,9 @@ | ||
| 1450 | 1425 | 'trash' => array( |
| 1451 | 1426 | 'label' => __( 'Move Form to Trash', 'formidable' ), |
| 1452 | 1427 | 'short' => __( 'Trash', 'formidable' ), |
| 1453 | 1428 | 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ), |
| 1454 | - 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1429 | + 'icon' => 'frmfont frm_delete_icon', | |
| 1455 | 1430 | 'data' => array( |
| 1456 | 1431 | 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ), |
| 1457 | 1432 | 'frmverify-btn' => 'frm-button-red', |
| 1458 | 1433 | ), |
| @@ -1461,9 +1436,9 @@ | ||
| 1461 | 1436 | 'label' => __( 'Delete Permanently', 'formidable' ), |
| 1462 | 1437 | 'short' => __( 'Delete', 'formidable' ), |
| 1463 | 1438 | 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), |
| 1464 | 1439 | 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ), |
| 1465 | - 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1440 | + 'icon' => 'frmfont frm_delete_icon', | |
| 1466 | 1441 | 'data' => array( |
| 1467 | 1442 | 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ), |
| 1468 | 1443 | 'frmverify-btn' => 'frm-button-red', |
| 1469 | 1444 | ), |
| @@ -1487,9 +1462,9 @@ | ||
| 1487 | 1462 | 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), |
| 1488 | 1463 | ), |
| 1489 | 1464 | 'frm_scroll_box' => array( |
| 1490 | 1465 | 'label' => __( 'Scroll Box', 'formidable' ), |
| 1491 | - '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' ), | |
| 1466 | + 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1492 | 1467 | ), |
| 1493 | 1468 | 'frm_first' => array( |
| 1494 | 1469 | 'label' => __( 'First', 'formidable' ), |
| 1495 | 1470 | 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), |
| @@ -1537,9 +1512,9 @@ | ||
| 1537 | 1512 | */ |
| 1538 | 1513 | public static function style_class_label( $style, $class ) { |
| 1539 | 1514 | $label = ''; |
| 1540 | 1515 | |
| 1541 | - if ( empty( $style ) ) { | |
| 1516 | + if ( ! $style ) { | |
| 1542 | 1517 | $label = $class; |
| 1543 | 1518 | } elseif ( ! is_array( $style ) ) { |
| 1544 | 1519 | $label = $style; |
| 1545 | 1520 | } elseif ( isset( $style['label'] ) ) { |
| @@ -1560,15 +1535,13 @@ | ||
| 1560 | 1535 | 'trash' => __( 'Trash', 'formidable' ), |
| 1561 | 1536 | 'publish' => __( 'Published', 'formidable' ), |
| 1562 | 1537 | ); |
| 1563 | 1538 | |
| 1564 | - if ( ! in_array( $status, array_keys( $nice_names ), true ) ) { | |
| 1539 | + if ( ! array_key_exists( $status, $nice_names ) ) { | |
| 1565 | 1540 | $status = 'publish'; |
| 1566 | 1541 | } |
| 1567 | 1542 | |
| 1568 | - $name = $nice_names[ $status ]; | |
| 1569 | - | |
| 1570 | - return $name; | |
| 1543 | + return $nice_names[ $status ]; | |
| 1571 | 1544 | } |
| 1572 | 1545 | |
| 1573 | 1546 | /** |
| 1574 | 1547 | * Renders a template icon based on the given categories. |
| @@ -1631,9 +1604,9 @@ | ||
| 1631 | 1604 | |
| 1632 | 1605 | if ( count( $categories ) === 1 ) { |
| 1633 | 1606 | $category = reset( $categories ); |
| 1634 | 1607 | $icon = $icons[ $category ] ?? $icon; |
| 1635 | - } elseif ( ! empty( $categories ) ) { | |
| 1608 | + } elseif ( $categories ) { | |
| 1636 | 1609 | $icons = array_intersect_key( $icons, array_flip( $categories ) ); |
| 1637 | 1610 | $icon = reset( $icons ); |
| 1638 | 1611 | } |
| 1639 | 1612 | |
| @@ -1646,10 +1619,11 @@ | ||
| 1646 | 1619 | |
| 1647 | 1620 | if ( $bg_color && $atts['bg'] ) { |
| 1648 | 1621 | echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; |
| 1649 | 1622 | } |
| 1623 | + | |
| 1650 | 1624 | echo '>'; |
| 1651 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1625 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1652 | 1626 | echo '</span>'; |
| 1653 | 1627 | } |
| 1654 | 1628 | |
| 1655 | 1629 | /** |
| @@ -1732,12 +1706,13 @@ | ||
| 1732 | 1706 | * |
| 1733 | 1707 | * @return void |
| 1734 | 1708 | */ |
| 1735 | 1709 | public static function show_plan_required( $requires, $link ) { |
| 1736 | - if ( empty( $requires ) ) { | |
| 1710 | + if ( ! $requires ) { | |
| 1737 | 1711 | return; |
| 1738 | 1712 | } |
| 1739 | 1713 | |
| 1714 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1740 | 1715 | ?> |
| 1741 | 1716 | <p class="frm_plan_required"> |
| 1742 | 1717 | <?php esc_html_e( 'Plan required:', 'formidable' ); ?> |
| 1743 | 1718 | <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener"> |
| @@ -1744,8 +1719,9 @@ | ||
| 1744 | 1719 | <?php echo esc_html( $requires ); ?> |
| 1745 | 1720 | </a> |
| 1746 | 1721 | </p> |
| 1747 | 1722 | <?php |
| 1723 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1748 | 1724 | } |
| 1749 | 1725 | |
| 1750 | 1726 | /** |
| 1751 | 1727 | * @since 4.0 |
| @@ -1763,12 +1739,9 @@ | ||
| 1763 | 1739 | |
| 1764 | 1740 | foreach ( $item['categories'] as $k => $category ) { |
| 1765 | 1741 | if ( in_array( $category, $plans, true ) ) { |
| 1766 | 1742 | unset( $item['categories'][ $k ] ); |
| 1767 | - | |
| 1768 | - $category = self::convert_legacy_package_names( $category ); | |
| 1769 | - | |
| 1770 | - return $category; | |
| 1743 | + return self::convert_legacy_package_names( $category ); | |
| 1771 | 1744 | } |
| 1772 | 1745 | } |
| 1773 | 1746 | |
| 1774 | 1747 | return false; |
| @@ -1784,9 +1757,9 @@ | ||
| 1784 | 1757 | * @return string The updated package name. |
| 1785 | 1758 | */ |
| 1786 | 1759 | public static function convert_legacy_package_names( $package_name ) { |
| 1787 | 1760 | if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) { |
| 1788 | - $package_name = 'Plus'; | |
| 1761 | + return 'Plus'; | |
| 1789 | 1762 | } |
| 1790 | 1763 | |
| 1791 | 1764 | return $package_name; |
| 1792 | 1765 | } |
| @@ -1800,14 +1773,13 @@ | ||
| 1800 | 1773 | * |
| 1801 | 1774 | * @return array |
| 1802 | 1775 | */ |
| 1803 | 1776 | public static function get_license_types( $args = array() ) { |
| 1804 | - $defaults = array( | |
| 1777 | + $defaults = array( | |
| 1805 | 1778 | 'include_all' => true, |
| 1806 | 1779 | 'case_lower' => false, |
| 1807 | 1780 | ); |
| 1808 | - $args = wp_parse_args( $args, $defaults ); | |
| 1809 | - | |
| 1781 | + $args = wp_parse_args( $args, $defaults ); | |
| 1810 | 1782 | $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' ); |
| 1811 | 1783 | |
| 1812 | 1784 | if ( $args['include_all'] ) { |
| 1813 | 1785 | $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); |
| @@ -1813,9 +1785,9 @@ | ||
| 1813 | 1785 | $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); |
| 1814 | 1786 | } |
| 1815 | 1787 | |
| 1816 | 1788 | if ( $args['case_lower'] ) { |
| 1817 | - $license_types = array_map( 'strtolower', $license_types ); | |
| 1789 | + return array_map( 'strtolower', $license_types ); | |
| 1818 | 1790 | } |
| 1819 | 1791 | |
| 1820 | 1792 | return $license_types; |
| 1821 | 1793 | } |
| @@ -1829,10 +1801,9 @@ | ||
| 1829 | 1801 | * |
| 1830 | 1802 | * @return array An array of warnings or an empty array. |
| 1831 | 1803 | */ |
| 1832 | 1804 | public static function check_for_warnings( $values ) { |
| 1833 | - $warnings = array(); | |
| 1834 | - | |
| 1805 | + $warnings = array(); | |
| 1835 | 1806 | $redirect_warning = self::check_redirect_url_for_unsafe_params( $values ); |
| 1836 | 1807 | |
| 1837 | 1808 | if ( $redirect_warning ) { |
| 1838 | 1809 | $warnings[] = $redirect_warning; |
| @@ -1881,12 +1852,12 @@ | ||
| 1881 | 1852 | |
| 1882 | 1853 | if ( empty( $redirect_components['query'] ) ) { |
| 1883 | 1854 | return array(); |
| 1884 | 1855 | } |
| 1856 | + | |
| 1885 | 1857 | parse_str( $redirect_components['query'], $redirect_params ); |
| 1886 | 1858 | $redirect_param_names = array_keys( $redirect_params ); |
| 1887 | - $reserved_words = self::reserved_words(); | |
| 1888 | - $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words ); | |
| 1859 | + $unsafe_params_in_redirect = array_intersect( $redirect_param_names, self::reserved_words() ); | |
| 1889 | 1860 | |
| 1890 | 1861 | return array_values( $unsafe_params_in_redirect ); |
| 1891 | 1862 | } |
| 1892 | 1863 | |
| @@ -1899,26 +1870,27 @@ | ||
| 1899 | 1870 | * |
| 1900 | 1871 | * @return bool|string A string with an unsafe param message or false. |
| 1901 | 1872 | */ |
| 1902 | 1873 | private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) { |
| 1903 | - $count = count( $unsafe_params_in_redirect ); | |
| 1904 | - $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1905 | - $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1906 | - $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1874 | + $count = count( $unsafe_params_in_redirect ); | |
| 1907 | 1875 | |
| 1908 | 1876 | if ( $count === 0 ) { |
| 1909 | 1877 | return false; |
| 1910 | 1878 | } |
| 1911 | 1879 | |
| 1912 | - if ( $count == 1 ) { | |
| 1880 | + $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1881 | + $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1882 | + $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1883 | + | |
| 1884 | + if ( $count === 1 ) { | |
| 1913 | 1885 | /* translators: %s: the name of a single parameter in the redirect URL */ |
| 1914 | - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; | |
| 1886 | + return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1915 | 1887 | } |
| 1916 | 1888 | |
| 1917 | 1889 | $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect ); |
| 1918 | 1890 | |
| 1919 | 1891 | /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */ |
| 1920 | - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; | |
| 1892 | + return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1921 | 1893 | } |
| 1922 | 1894 | |
| 1923 | 1895 | /** |
| 1924 | 1896 | * Returns an array of common reserved words in WordPress. |
| @@ -1988,9 +1960,9 @@ | ||
| 1988 | 1960 | * |
| 1989 | 1961 | * @return string |
| 1990 | 1962 | */ |
| 1991 | 1963 | public static function maybe_add_sanitize_url_attr( $url, $form_id ) { |
| 1992 | - if ( false === strpos( $url, '[' ) ) { | |
| 1964 | + if ( ! str_contains( $url, '[' ) ) { | |
| 1993 | 1965 | // Do nothing if no shortcodes are detected. |
| 1994 | 1966 | return $url; |
| 1995 | 1967 | } |
| 1996 | 1968 | |
| @@ -2002,11 +1974,10 @@ | ||
| 2002 | 1974 | } |
| 2003 | 1975 | |
| 2004 | 1976 | $original_query = $parsed['query']; |
| 2005 | 1977 | $query = $parsed['query']; |
| 1978 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 2006 | 1979 | |
| 2007 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 2008 | - | |
| 2009 | 1980 | if ( empty( $shortcodes[0] ) ) { |
| 2010 | 1981 | // No shortcodes found, do nothing. |
| 2011 | 1982 | return $url; |
| 2012 | 1983 | } |
| @@ -2018,9 +1989,9 @@ | ||
| 2018 | 1989 | // Skip if shortcodes. |
| 2019 | 1990 | continue; |
| 2020 | 1991 | } |
| 2021 | 1992 | |
| 2022 | - if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) { | |
| 1993 | + if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) { | |
| 2023 | 1994 | // A sanitize option is already set so leave it alone. |
| 2024 | 1995 | continue; |
| 2025 | 1996 | } |
| 2026 | 1997 | |
| @@ -2030,10 +2001,9 @@ | ||
| 2030 | 2001 | $new_shortcode .= ' ' . $options; |
| 2031 | 2002 | } |
| 2032 | 2003 | |
| 2033 | 2004 | $new_shortcode .= ' sanitize_url=1]'; |
| 2034 | - | |
| 2035 | - $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 2005 | + $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 2036 | 2006 | }//end foreach |
| 2037 | 2007 | |
| 2038 | 2008 | if ( $query === $original_query ) { |
| 2039 | 2009 | return $url; |
| @@ -2072,11 +2042,9 @@ | ||
| 2072 | 2042 | // Strip out any percent-encoded characters. |
| 2073 | 2043 | $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname ); |
| 2074 | 2044 | |
| 2075 | 2045 | // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'. |
| 2076 | - $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 2077 | - | |
| 2078 | - return $sanitized; | |
| 2046 | + return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 2079 | 2047 | } |
| 2080 | 2048 | |
| 2081 | 2049 | /** |
| 2082 | 2050 | * Returns true if the preview should be blocked. |
| @@ -2096,10 +2064,9 @@ | ||
| 2096 | 2064 | * |
| 2097 | 2065 | * @param bool $should_block |
| 2098 | 2066 | * @param string $form_key |
| 2099 | 2067 | */ |
| 2100 | - $should_block = (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 2101 | - return $should_block; | |
| 2068 | + return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 2102 | 2069 | } |
| 2103 | 2070 | |
| 2104 | 2071 | /** |
| 2105 | 2072 | * Checks if the form is loaded by API. |
| @@ -2113,12 +2080,24 @@ | ||
| 2113 | 2080 | |
| 2114 | 2081 | if ( ! empty( $frm_vars['inplace_edit'] ) ) { |
| 2115 | 2082 | return true; |
| 2116 | 2083 | } |
| 2117 | - return self::is_formidable_api_form() || self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview(); | |
| 2084 | + | |
| 2085 | + return self::is_formidable_api_form() || self::is_block_or_page_builder_preview(); | |
| 2118 | 2086 | } |
| 2119 | 2087 | |
| 2120 | 2088 | /** |
| 2089 | + * Checks if the form is rendered inside a block editor or page builder preview. | |
| 2090 | + * | |
| 2091 | + * @since 6.29 | |
| 2092 | + * | |
| 2093 | + * @return bool | |
| 2094 | + */ | |
| 2095 | + public static function is_block_or_page_builder_preview() { | |
| 2096 | + return self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview(); | |
| 2097 | + } | |
| 2098 | + | |
| 2099 | + /** | |
| 2121 | 2100 | * @since 6.21 |
| 2122 | 2101 | * |
| 2123 | 2102 | * @return bool |
| 2124 | 2103 | */ |
| @@ -2142,23 +2121,18 @@ | ||
| 2142 | 2121 | */ |
| 2143 | 2122 | private static function is_gutenberg_editor() { |
| 2144 | 2123 | $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); |
| 2145 | 2124 | |
| 2146 | - if ( false !== strpos( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 2125 | + if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 2147 | 2126 | return true; |
| 2148 | 2127 | } |
| 2149 | 2128 | |
| 2150 | - if ( false !== strpos( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) { | |
| 2129 | + if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) { | |
| 2151 | 2130 | return true; |
| 2152 | 2131 | } |
| 2153 | 2132 | |
| 2154 | 2133 | global $pagenow; |
| 2155 | - | |
| 2156 | - if ( 'post.php' === $pagenow ) { | |
| 2157 | - return true; | |
| 2158 | - } | |
| 2159 | - | |
| 2160 | - return false; | |
| 2134 | + return 'post.php' === $pagenow; | |
| 2161 | 2135 | } |
| 2162 | 2136 | |
| 2163 | 2137 | /** |
| 2164 | 2138 | * @since 6.21 |
| @@ -2171,9 +2145,9 @@ | ||
| 2171 | 2145 | } |
| 2172 | 2146 | |
| 2173 | 2147 | $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); |
| 2174 | 2148 | |
| 2175 | - if ( false !== strpos( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 2149 | + if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 2176 | 2150 | // Prevent the honeypot from appearing for an API loaded form. |
| 2177 | 2151 | // This is to prevent conflicts where the script is not working. |
| 2178 | 2152 | return true; |
| 2179 | 2153 | } |
| @@ -2189,39 +2163,46 @@ | ||
| 2189 | 2163 | return false; |
| 2190 | 2164 | } |
| 2191 | 2165 | |
| 2192 | 2166 | /** |
| 2193 | - * @since 3.0 | |
| 2194 | - * @deprecated 6.11 | |
| 2167 | + * @since 6.30 | |
| 2195 | 2168 | * |
| 2196 | - * @param array $atts | |
| 2197 | - * | |
| 2198 | 2169 | * @return void |
| 2199 | 2170 | */ |
| 2200 | - public static function actions_dropdown( $atts ) { | |
| 2201 | - _deprecated_function( __METHOD__, '6.11' ); | |
| 2171 | + public static function load_currency_js() { | |
| 2172 | + global $frm_vars; | |
| 2202 | 2173 | |
| 2203 | - if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 2174 | + if ( empty( $frm_vars['currency'] ) ) { | |
| 2204 | 2175 | return; |
| 2205 | 2176 | } |
| 2206 | 2177 | |
| 2207 | - $status = $atts['status']; | |
| 2208 | - $form_id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 2209 | - $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 2210 | - $links = self::get_action_links( $form_id, $status ); | |
| 2211 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php'; | |
| 2178 | + echo '<script>'; | |
| 2179 | + echo 'var frmcurrency=' . json_encode( $frm_vars['currency'] ) . ";\n"; | |
| 2180 | + echo 'if(typeof __FRMCURR == "undefined"){__FRMCURR=frmcurrency;}'; | |
| 2181 | + echo 'else{__FRMCURR=jQuery.extend(true,{},__FRMCURR,frmcurrency);}'; | |
| 2182 | + echo '</script>'; | |
| 2212 | 2183 | } |
| 2213 | 2184 | |
| 2214 | 2185 | /** |
| 2215 | - * Check if Pro isn't up to date yet. | |
| 2216 | - * 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). | |
| 2186 | + * Returns the form name or the no title text if the form name is empty. | |
| 2217 | 2187 | * |
| 2218 | - * @since 6.2 | |
| 2219 | - * @deprecated 6.20 | |
| 2188 | + * @since 6.30 | |
| 2220 | 2189 | * |
| 2221 | - * @return bool | |
| 2190 | + * @param array|stdClass $form The form data. | |
| 2191 | + * @param int $length The form name length to truncate to. | |
| 2192 | + * | |
| 2193 | + * @return string | |
| 2222 | 2194 | */ |
| 2223 | - public static function should_use_pro_for_ajax_submit() { | |
| 2224 | - _deprecated_function( __METHOD__, '6.20' ); | |
| 2225 | - return false; | |
| 2195 | + public static function get_form_name( $form, $length = 0 ) { | |
| 2196 | + $form_name = is_object( $form ) ? $form->name : $form['name']; | |
| 2197 | + | |
| 2198 | + if ( '' === $form_name || null === $form_name ) { | |
| 2199 | + return self::get_no_title_text(); | |
| 2200 | + } | |
| 2201 | + | |
| 2202 | + if ( ! $length ) { | |
| 2203 | + return $form_name; | |
| 2204 | + } | |
| 2205 | + | |
| 2206 | + return FrmAppHelper::truncate( $form_name, $length ); | |
| 2226 | 2207 | } |
| 2227 | 2208 | } |