@@ -2383,32 +2383,20 @@ public static function show_add_field_buttons( $args ) {
23832383 }
23842384
23852385 // If the individual field isn't allowed, disable it.
2386- $ run_filter = true ;
2387- $ single_no_allow = ' ' ;
2388- $ install_data = '' ;
2389- $ requires = '' ;
2390- $ link = isset ( $ field_type ['link ' ] ) ? esc_url_raw ( $ field_type ['link ' ] ) : '' ;
2391- $ has_show_upgrade_class = isset ( $ field_type ['icon ' ] ) && str_contains ( $ field_type ['icon ' ], ' frm_show_upgrade ' );
2392- $ show_upgrade = $ has_show_upgrade_class || str_contains ( $ args ['no_allow_class ' ], 'frm_show_upgrade ' );
2393-
2394- if ( $ has_show_upgrade_class ) {
2395- $ single_no_allow .= 'frm_show_upgrade ' ;
2396- $ field_type ['icon ' ] = str_replace ( ' frm_show_upgrade ' , '' , $ field_type ['icon ' ] );
2397- $ run_filter = false ;
2398-
2399- if ( isset ( $ field_type ['addon ' ] ) ) {
2400- $ upgrading = FrmAddonsController::install_link ( $ field_type ['addon ' ] );
2401-
2402- if ( isset ( $ upgrading ['url ' ] ) ) {
2403- $ install_data = json_encode ( $ upgrading );
2404- }
2405-
2406- $ requires = FrmFormsHelper::get_plan_required ( $ upgrading );
2407- } elseif ( isset ( $ field_type ['require ' ] ) ) {
2408- $ requires = $ field_type ['require ' ];
2409- }
2410- }
2411-
2386+ $ link = isset ( $ field_type ['link ' ] ) ? esc_url_raw ( $ field_type ['link ' ] ) : '' ;
2387+
2388+ list (
2389+ $ run_filter ,
2390+ $ single_no_allow ,
2391+ $ install_data ,
2392+ $ requires ,
2393+ $ has_show_upgrade_class ,
2394+ $ has_show_update_class ,
2395+ $ upgrading ,
2396+ $ update_addon_name
2397+ ) = self ::get_field_upgrade_state ( $ field_type );
2398+
2399+ $ show_upgrade = $ has_show_upgrade_class || $ has_show_update_class || str_contains ( $ args ['no_allow_class ' ], 'frm_show_upgrade ' );
24122400 $ upgrade_label = '' ;
24132401 $ upgrade_message = '' ;
24142402
@@ -2452,7 +2440,14 @@ public static function show_add_field_buttons( $args ) {
24522440 );
24532441 }
24542442
2455- if ( isset ( $ upgrading ['url ' ] ) ) {
2443+ if ( $ has_show_update_class ) {
2444+ $ li_params ['data-message ' ] = sprintf (
2445+ // translators: %1$s: Add-on name, %2$s: Field type name.
2446+ esc_html__ ( 'You need a newer version of %1$s for %2$s fields. ' , 'formidable ' ),
2447+ $ update_addon_name ,
2448+ $ field_name
2449+ );
2450+ } elseif ( isset ( $ upgrading ['url ' ] ) ) {
24562451 $ li_params ['data-message ' ] = sprintf (
24572452 // translators: %s: Field name
24582453 esc_html__ ( 'You already have access to %s fields, you \'ll just need to activate to start using them. ' , 'formidable ' ),
@@ -2476,6 +2471,76 @@ public static function show_add_field_buttons( $args ) {
24762471 // phpcs:enable Generic.WhiteSpace.ScopeIndent
24772472 }
24782473
2474+ /**
2475+ * Parse the upgrade and update flags from a field type's icon class.
2476+ *
2477+ * @since x.x
2478+ *
2479+ * @param array $field_type Field type configuration, modified in place to strip icon flag classes.
2480+ *
2481+ * @return array Upgrade and update state values for the field button, in positional order.
2482+ */
2483+ private static function get_field_upgrade_state ( &$ field_type ) {
2484+ $ single_no_allow = ' ' ;
2485+ $ run_filter = true ;
2486+ $ has_show_upgrade_class = false ;
2487+ $ has_show_update_class = false ;
2488+ $ install_data = '' ;
2489+ $ requires = '' ;
2490+ $ upgrading = array ();
2491+ $ update_addon_name = '' ;
2492+
2493+ if ( isset ( $ field_type ['icon ' ] ) ) {
2494+ $ has_show_upgrade_class = str_contains ( $ field_type ['icon ' ], ' frm_show_upgrade ' );
2495+ $ has_show_update_class = str_contains ( $ field_type ['icon ' ], ' frm_show_update ' );
2496+ }
2497+
2498+ if ( $ has_show_upgrade_class ) {
2499+ $ single_no_allow .= 'frm_show_upgrade ' ;
2500+ $ field_type ['icon ' ] = str_replace ( ' frm_show_upgrade ' , '' , $ field_type ['icon ' ] );
2501+ $ run_filter = false ;
2502+
2503+ if ( isset ( $ field_type ['addon ' ] ) ) {
2504+ $ upgrading = FrmAddonsController::install_link ( $ field_type ['addon ' ] );
2505+
2506+ if ( isset ( $ upgrading ['url ' ] ) ) {
2507+ $ install_data = json_encode ( $ upgrading );
2508+ }
2509+
2510+ $ requires = FrmFormsHelper::get_plan_required ( $ upgrading );
2511+ } elseif ( isset ( $ field_type ['require ' ] ) ) {
2512+ $ requires = $ field_type ['require ' ];
2513+ }
2514+ }
2515+
2516+ if ( $ has_show_update_class ) {
2517+ $ single_no_allow .= ' frm_show_update ' ;
2518+ $ field_type ['icon ' ] = str_replace ( ' frm_show_update ' , '' , $ field_type ['icon ' ] );
2519+ $ run_filter = false ;
2520+ $ addon_slug = $ field_type ['addon ' ] ?? 'pro ' ;
2521+
2522+ if ( 'pro ' === $ addon_slug ) {
2523+ $ update_addon_name = __ ( 'Formidable Pro ' , 'formidable ' );
2524+ } else {
2525+ $ addon_data = FrmAddonsController::get_addon ( $ addon_slug );
2526+ $ update_addon_name = $ addon_data && ! empty ( $ addon_data ['title ' ] ) ? $ addon_data ['title ' ] : ucfirst ( $ addon_slug );
2527+ }
2528+
2529+ $ install_data = FrmAddonsController::get_update_install_data ( $ addon_slug );
2530+ }
2531+
2532+ return array (
2533+ $ run_filter ,
2534+ $ single_no_allow ,
2535+ $ install_data ,
2536+ $ requires ,
2537+ $ has_show_upgrade_class ,
2538+ $ has_show_update_class ,
2539+ $ upgrading ,
2540+ $ update_addon_name ,
2541+ );
2542+ }
2543+
24792544 /**
24802545 * Updates the params with limit data (the data-limit attribute, and possibly the frm_at_limit class).
24812546 * Some field types are limited to a certain number per form, including coupon fields.
0 commit comments