| @@ -589,8 +589,12 @@ | ||
| 589 | 589 | * @return void |
| 590 | 590 | */ |
| 591 | 591 | public static function show_fields( $fields, $errors, $form, $form_action ) { |
| 592 | 592 | foreach ( $fields as $field ) { |
| 593 | + if ( ! is_array( $field ) ) { | |
| 594 | + continue; | |
| 595 | + } | |
| 596 | + | |
| 593 | 597 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
| 594 | 598 | $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) ); |
| 595 | 599 | } |
| 596 | 600 | } |
| @@ -959,13 +963,11 @@ | ||
| 959 | 963 | } elseif ( $cond === '!=' ) { |
| 960 | 964 | // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 961 | 965 | $m = ! in_array( $hide_opt, $observed_value ); |
| 962 | 966 | } elseif ( $cond === '>' ) { |
| 963 | - $min = min( $observed_value ); | |
| 964 | - $m = $min > $hide_opt; | |
| 967 | + $m = min( $observed_value ) > $hide_opt; | |
| 965 | 968 | } elseif ( $cond === '<' ) { |
| 966 | - $max = max( $observed_value ); | |
| 967 | - $m = $max < $hide_opt; | |
| 969 | + $m = max( $observed_value ) < $hide_opt; | |
| 968 | 970 | } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { |
| 969 | 971 | foreach ( $observed_value as $ob ) { |
| 970 | 972 | $m = strpos( $ob, $hide_opt ); |
| 971 | 973 | |
| @@ -1824,18 +1826,20 @@ | ||
| 1824 | 1826 | return str_replace( $replace, $replace_with, $val ); |
| 1825 | 1827 | } |
| 1826 | 1828 | |
| 1827 | 1829 | foreach ( $val as $k => $v ) { |
| 1828 | - if ( is_string( $v ) ) { | |
| 1829 | - if ( 'custom_html' === $k ) { | |
| 1830 | - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); | |
| 1831 | - unset( $k, $v ); | |
| 1832 | - continue; | |
| 1833 | - } | |
| 1830 | + if ( ! is_string( $v ) ) { | |
| 1831 | + continue; | |
| 1832 | + } | |
| 1834 | 1833 | |
| 1835 | - $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1834 | + if ( 'custom_html' === $k ) { | |
| 1835 | + $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); | |
| 1836 | 1836 | unset( $k, $v ); |
| 1837 | + continue; | |
| 1837 | 1838 | } |
| 1839 | + | |
| 1840 | + $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1841 | + unset( $k, $v ); | |
| 1838 | 1842 | } |
| 1839 | 1843 | |
| 1840 | 1844 | return $val; |
| 1841 | 1845 | } |
| @@ -2360,8 +2364,39 @@ | ||
| 2360 | 2364 | return $field_array + $field_options; |
| 2361 | 2365 | } |
| 2362 | 2366 | |
| 2363 | 2367 | /** |
| 2368 | + * Shows add field link. | |
| 2369 | + * | |
| 2370 | + * @since 6.30 | |
| 2371 | + * | |
| 2372 | + * @param array $field_type See file `classes/views/frm-forms/add_field_links.php`. | |
| 2373 | + * | |
| 2374 | + * @return void | |
| 2375 | + */ | |
| 2376 | + public static function show_add_field_link( $field_type ) { | |
| 2377 | + $field_label = FrmFormsHelper::get_field_link_name( $field_type ); | |
| 2378 | + $classes = 'frmbutton frm6 frm_t' . $field_type['key']; | |
| 2379 | + | |
| 2380 | + if ( ! empty( $field_type['hide'] ) ) { | |
| 2381 | + $classes .= ' frm_hidden'; | |
| 2382 | + } | |
| 2383 | + ?> | |
| 2384 | +<li class="<?php echo esc_attr( $classes ); ?>" id="<?php echo esc_attr( $field_type['key'] ); ?>"> | |
| 2385 | + <a href="#" class="frm_add_field" title="<?php echo esc_attr( $field_label ); ?>" role="button" aria-label="<?php echo esc_attr( $field_label ); ?>"> | |
| 2386 | + <?php FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ) ); ?> | |
| 2387 | + <span><?php echo esc_html( $field_label ); ?></span> | |
| 2388 | + <?php | |
| 2389 | + if ( 'credit_card' === $field_type['key'] && ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 2390 | + FrmAppHelper::show_pill_text(); | |
| 2391 | + } | |
| 2392 | + ?> | |
| 2393 | + </a> | |
| 2394 | +</li> | |
| 2395 | + <?php | |
| 2396 | + } | |
| 2397 | + | |
| 2398 | + /** | |
| 2364 | 2399 | * @since 4.04 |
| 2365 | 2400 | * |
| 2366 | 2401 | * @param array $args |
| 2367 | 2402 | * |
| @@ -2380,34 +2415,22 @@ | ||
| 2380 | 2415 | $field_label .= ob_get_clean(); |
| 2381 | 2416 | } |
| 2382 | 2417 | |
| 2383 | 2418 | // If the individual field isn't allowed, disable it. |
| 2384 | - $run_filter = true; | |
| 2385 | - $single_no_allow = ' '; | |
| 2386 | - $install_data = ''; | |
| 2387 | - $requires = ''; | |
| 2388 | - $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 2389 | - $has_show_upgrade_class = isset( $field_type['icon'] ) && str_contains( $field_type['icon'], ' frm_show_upgrade' ); | |
| 2390 | - $show_upgrade = $has_show_upgrade_class || str_contains( $args['no_allow_class'], 'frm_show_upgrade' ); | |
| 2419 | + $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 2391 | 2420 | |
| 2392 | - if ( $has_show_upgrade_class ) { | |
| 2393 | - $single_no_allow .= 'frm_show_upgrade'; | |
| 2394 | - $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] ); | |
| 2395 | - $run_filter = false; | |
| 2421 | + list( | |
| 2422 | + $run_filter, | |
| 2423 | + $single_no_allow, | |
| 2424 | + $install_data, | |
| 2425 | + $requires, | |
| 2426 | + $has_show_upgrade_class, | |
| 2427 | + $has_show_update_class, | |
| 2428 | + $upgrading, | |
| 2429 | + $update_addon_name | |
| 2430 | + ) = self::get_field_upgrade_state( $field_type ); | |
| 2396 | 2431 | |
| 2397 | - if ( isset( $field_type['addon'] ) ) { | |
| 2398 | - $upgrading = FrmAddonsController::install_link( $field_type['addon'] ); | |
| 2399 | - | |
| 2400 | - if ( isset( $upgrading['url'] ) ) { | |
| 2401 | - $install_data = json_encode( $upgrading ); | |
| 2402 | - } | |
| 2403 | - | |
| 2404 | - $requires = FrmFormsHelper::get_plan_required( $upgrading ); | |
| 2405 | - } elseif ( isset( $field_type['require'] ) ) { | |
| 2406 | - $requires = $field_type['require']; | |
| 2407 | - } | |
| 2408 | - } | |
| 2409 | - | |
| 2432 | + $show_upgrade = $has_show_upgrade_class || $has_show_update_class || str_contains( $args['no_allow_class'], 'frm_show_upgrade' ); | |
| 2410 | 2433 | $upgrade_label = ''; |
| 2411 | 2434 | $upgrade_message = ''; |
| 2412 | 2435 | |
| 2413 | 2436 | if ( $show_upgrade ) { |
| @@ -2449,10 +2472,17 @@ | ||
| 2449 | 2472 | str_contains( $field_type['learn-more'], '/' ) |
| 2450 | 2473 | ); |
| 2451 | 2474 | } |
| 2452 | 2475 | |
| 2453 | - if ( isset( $upgrading['url'] ) ) { | |
| 2476 | + if ( $has_show_update_class ) { | |
| 2454 | 2477 | $li_params['data-message'] = sprintf( |
| 2478 | + // translators: %1$s: Add-on name, %2$s: Field type name. | |
| 2479 | + esc_html__( 'You need a newer version of %1$s for %2$s fields.', 'formidable' ), | |
| 2480 | + $update_addon_name, | |
| 2481 | + $field_name | |
| 2482 | + ); | |
| 2483 | + } elseif ( isset( $upgrading['url'] ) ) { | |
| 2484 | + $li_params['data-message'] = sprintf( | |
| 2455 | 2485 | // translators: %s: Field name |
| 2456 | 2486 | esc_html__( 'You already have access to %s fields, you\'ll just need to activate to start using them.', 'formidable' ), |
| 2457 | 2487 | $field_name |
| 2458 | 2488 | ); |
| @@ -2474,8 +2504,78 @@ | ||
| 2474 | 2504 | // phpcs:enable Generic.WhiteSpace.ScopeIndent |
| 2475 | 2505 | } |
| 2476 | 2506 | |
| 2477 | 2507 | /** |
| 2508 | + * Parse the upgrade and update flags from a field type's icon class. | |
| 2509 | + * | |
| 2510 | + * @since 6.29 | |
| 2511 | + * | |
| 2512 | + * @param array $field_type Field type configuration, modified in place to strip icon flag classes. | |
| 2513 | + * | |
| 2514 | + * @return array Upgrade and update state values for the field button, in positional order. | |
| 2515 | + */ | |
| 2516 | + private static function get_field_upgrade_state( &$field_type ) { | |
| 2517 | + $single_no_allow = ' '; | |
| 2518 | + $run_filter = true; | |
| 2519 | + $has_show_upgrade_class = false; | |
| 2520 | + $has_show_update_class = false; | |
| 2521 | + $install_data = ''; | |
| 2522 | + $requires = ''; | |
| 2523 | + $upgrading = array(); | |
| 2524 | + $update_addon_name = ''; | |
| 2525 | + | |
| 2526 | + if ( isset( $field_type['icon'] ) ) { | |
| 2527 | + $has_show_upgrade_class = str_contains( $field_type['icon'], ' frm_show_upgrade' ); | |
| 2528 | + $has_show_update_class = str_contains( $field_type['icon'], ' frm_show_update' ); | |
| 2529 | + } | |
| 2530 | + | |
| 2531 | + if ( $has_show_upgrade_class ) { | |
| 2532 | + $single_no_allow .= 'frm_show_upgrade'; | |
| 2533 | + $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] ); | |
| 2534 | + $run_filter = false; | |
| 2535 | + | |
| 2536 | + if ( isset( $field_type['addon'] ) ) { | |
| 2537 | + $upgrading = FrmAddonsController::install_link( $field_type['addon'] ); | |
| 2538 | + | |
| 2539 | + if ( isset( $upgrading['url'] ) ) { | |
| 2540 | + $install_data = json_encode( $upgrading ); | |
| 2541 | + } | |
| 2542 | + | |
| 2543 | + $requires = FrmFormsHelper::get_plan_required( $upgrading ); | |
| 2544 | + } elseif ( isset( $field_type['require'] ) ) { | |
| 2545 | + $requires = $field_type['require']; | |
| 2546 | + } | |
| 2547 | + } | |
| 2548 | + | |
| 2549 | + if ( $has_show_update_class ) { | |
| 2550 | + $single_no_allow .= ' frm_show_update'; | |
| 2551 | + $field_type['icon'] = str_replace( ' frm_show_update', '', $field_type['icon'] ); | |
| 2552 | + $run_filter = false; | |
| 2553 | + $addon_slug = $field_type['addon'] ?? 'pro'; | |
| 2554 | + | |
| 2555 | + if ( 'pro' === $addon_slug ) { | |
| 2556 | + $update_addon_name = __( 'Formidable Pro', 'formidable' ); | |
| 2557 | + } else { | |
| 2558 | + $addon_data = FrmAddonsController::get_addon( $addon_slug ); | |
| 2559 | + $update_addon_name = $addon_data && ! empty( $addon_data['title'] ) ? $addon_data['title'] : ucfirst( $addon_slug ); | |
| 2560 | + } | |
| 2561 | + | |
| 2562 | + $install_data = FrmAddonsController::get_update_install_data( $addon_slug ); | |
| 2563 | + } | |
| 2564 | + | |
| 2565 | + return array( | |
| 2566 | + $run_filter, | |
| 2567 | + $single_no_allow, | |
| 2568 | + $install_data, | |
| 2569 | + $requires, | |
| 2570 | + $has_show_upgrade_class, | |
| 2571 | + $has_show_update_class, | |
| 2572 | + $upgrading, | |
| 2573 | + $update_addon_name, | |
| 2574 | + ); | |
| 2575 | + } | |
| 2576 | + | |
| 2577 | + /** | |
| 2478 | 2578 | * Updates the params with limit data (the data-limit attribute, and possibly the frm_at_limit class). |
| 2479 | 2579 | * Some field types are limited to a certain number per form, including coupon fields. |
| 2480 | 2580 | * |
| 2481 | 2581 | * @since 6.27 |
| @@ -2553,8 +2653,12 @@ | ||
| 2553 | 2653 | 'content' => 'button-options', |
| 2554 | 2654 | ), |
| 2555 | 2655 | ); |
| 2556 | 2656 | |
| 2657 | + if ( 'product' === FrmField::get_field_type( $field ) ) { | |
| 2658 | + unset( $options['buttons'] ); | |
| 2659 | + } | |
| 2660 | + | |
| 2557 | 2661 | /** |
| 2558 | 2662 | * Allows modifying the options of Display format setting of Radio field. |
| 2559 | 2663 | * |
| 2560 | 2664 | * @since 5.0.04 |
| @@ -2739,12 +2843,13 @@ | ||
| 2739 | 2843 | * @return void |
| 2740 | 2844 | */ |
| 2741 | 2845 | public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) { |
| 2742 | 2846 | $attributes = array( |
| 2743 | - 'type' => 'button', | |
| 2744 | - 'class' => self::get_ai_generate_options_button_class(), | |
| 2847 | + 'type' => 'button', | |
| 2745 | 2848 | ); |
| 2746 | 2849 | |
| 2850 | + $attributes['class'] = ! empty( $args['class'] ) ? $args['class'] : self::get_ai_generate_options_button_class(); | |
| 2851 | + | |
| 2747 | 2852 | if ( $should_hide_bulk_edit ) { |
| 2748 | 2853 | $attributes['class'] .= ' frm-force-hidden'; |
| 2749 | 2854 | } |
| 2750 | 2855 | |
| @@ -2751,9 +2856,9 @@ | ||
| 2751 | 2856 | $data = FrmAppHelper::get_upgrade_data_params( |
| 2752 | 2857 | 'ai', |
| 2753 | 2858 | array( |
| 2754 | 2859 | 'requires' => 'Business', |
| 2755 | - 'upgrade' => __( 'Generate options with AI', 'formidable' ), | |
| 2860 | + 'upgrade' => $args['upgrade_text'] ?? __( 'Generate options with AI', 'formidable' ), | |
| 2756 | 2861 | 'medium' => 'builder', |
| 2757 | 2862 | 'content' => 'generate-options-with-ai', |
| 2758 | 2863 | ), |
| 2759 | 2864 | true |
| @@ -2760,16 +2865,16 @@ | ||
| 2760 | 2865 | ); |
| 2761 | 2866 | |
| 2762 | 2867 | if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) { |
| 2763 | 2868 | // Backwards compatibility "@since 6.24". |
| 2764 | - if ( ! method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) { | |
| 2869 | + if ( method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) { | |
| 2870 | + $attributes['class'] .= ' frm-ai-generate-options-modal-trigger'; | |
| 2871 | + $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id']; | |
| 2872 | + } else { | |
| 2765 | 2873 | $data = array( |
| 2766 | 2874 | 'modal-title' => __( 'Generate options with AI', 'formidable' ), |
| 2767 | 2875 | 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ), |
| 2768 | 2876 | ); |
| 2769 | - } else { | |
| 2770 | - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger'; | |
| 2771 | - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id']; | |
| 2772 | 2877 | } |
| 2773 | 2878 | } |
| 2774 | 2879 | |
| 2775 | 2880 | if ( empty( $attributes['data-fid'] ) ) { |