From 9d73a83b94e741c9ee2cb407b472b79a5d341c02 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Tue, 17 Nov 2026 13:58:25 -0400 Subject: [PATCH 1/2] fix(admin): let installed Boosts toggle on/off Match installed Boosts by their updater download id or plugin name when the API plugin path does not match the installed folder, so the Add-Ons page shows their toggle and activates the right file. Map the folder-style Boost slugs the API now sends to the existing default descriptions and icons. The short slugs still work for older cached feeds. Co-Authored-By: Claude Opus 5.5 --- classes/controllers/FrmAddonsController.php | 61 +++++++++++++++++- classes/helpers/FrmAddonsHelper.php | 5 ++ .../misc/test_FrmBoostsMarketplace.php | 64 +++++++++++++++++-- 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index db7e3dbc1b..2a0d1e9e8a 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -323,8 +323,18 @@ protected static function override_addon_display( &$addon, $slug ) { 'field-tooltips' => __( 'Add customized hover-and-tap help to any field.', 'formidable' ), ); - if ( isset( $excerpts[ $slug ] ) ) { - $addon['excerpt'] = $excerpts[ $slug ]; + // The API now sends Boost slugs that match their plugin folders. Older cached feeds still use the short slugs. + $current_slugs = array( + 'formidable-advanced-modals' => 'advanced-modals', + 'formidable-color-picker' => 'color-picker', + 'formidable-bulk-edit' => 'bulk-edit', + 'formidable-celebrations' => 'celebrations', + 'formidable-tooltips' => 'field-tooltips', + ); + $excerpt_slug = $current_slugs[ $slug ] ?? $slug; + + if ( isset( $excerpts[ $excerpt_slug ] ) ) { + $addon['excerpt'] = $excerpts[ $excerpt_slug ]; } } @@ -1145,6 +1155,11 @@ protected static function prepare_addons( &$addons ) { self::override_addon_display( $addon, $slug ); + if ( FrmAddonsHelper::is_boost( $addon ) ) { + $file_name = self::get_boost_plugin_file( $addon, $file_name ); + $addon['plugin'] = $file_name; + } + $addon['installed'] = self::is_installed( $file_name ); if ( 'highrise' === $slug && ! $addon['installed'] ) { @@ -1189,6 +1204,48 @@ protected static function prepare_addons( &$addons ) { }//end foreach } + /** + * Find the plugin file of an installed Boost. + * + * The plugin path the API sends for a Boost does not always match the folder + * it is installed in. When it does not, match the installed copy by its + * updater download id (active Boosts), then by its plugin name (inactive Boosts). + * + * @since x.x + * + * @param array $addon The Boost data from the API. + * @param string $file_name The plugin file the API sends for the Boost. + * + * @return string The installed plugin file, or the API plugin file when the Boost is not installed. + */ + private static function get_boost_plugin_file( $addon, $file_name ) { + if ( self::is_installed( $file_name ) ) { + return $file_name; + } + + if ( ! empty( $addon['id'] ) ) { + foreach ( apply_filters( 'frm_installed_addons', array() ) as $installed_addon ) { + if ( $installed_addon instanceof FrmAddon && $installed_addon->plugin_folder && (string) $installed_addon->download_id === (string) $addon['id'] ) { + return $installed_addon->plugin_folder; + } + } + } + + if ( empty( $addon['title'] ) ) { + return $file_name; + } + + $plugin_names = array( 'Formidable ' . $addon['title'], $addon['title'] ); + + foreach ( self::get_plugins() as $plugin_file => $plugin_data ) { + if ( in_array( $plugin_data['Name'] ?? '', $plugin_names, true ) ) { + return $plugin_file; + } + } + + return $file_name; + } + /** * @param string $file_name * @param string $slug diff --git a/classes/helpers/FrmAddonsHelper.php b/classes/helpers/FrmAddonsHelper.php index 730339c066..47d7d4e1a0 100644 --- a/classes/helpers/FrmAddonsHelper.php +++ b/classes/helpers/FrmAddonsHelper.php @@ -181,11 +181,16 @@ public static function get_reconnect_link() { public static function get_addon_icon( $slug ) { $icons_map = array( 'advanced-modals' => 'boost_popups', + 'formidable-advanced-modals' => 'boost_popups', 'simply-popups' => 'boost_popups', 'bulk-edit' => 'boost_bulk_edit', + 'formidable-bulk-edit' => 'boost_bulk_edit', 'celebrations' => 'boost_celebrations', + 'formidable-celebrations' => 'boost_celebrations', 'color-picker' => 'boost_color_picker', + 'formidable-color-picker' => 'boost_color_picker', 'field-tooltips' => 'boost_tooltips', + 'formidable-tooltips' => 'boost_tooltips', 'acf-forms' => 'acfforms', 'activecampaign-wordpress-plugin' => 'activecampaign', 'ai' => 'ai-form', diff --git a/tests/phpunit/misc/test_FrmBoostsMarketplace.php b/tests/phpunit/misc/test_FrmBoostsMarketplace.php index 40878de60a..81c69da235 100644 --- a/tests/phpunit/misc/test_FrmBoostsMarketplace.php +++ b/tests/phpunit/misc/test_FrmBoostsMarketplace.php @@ -50,14 +50,15 @@ public function test_boost_detection_and_categories() { /** @return void */ public function test_missing_excerpts_render_without_empty_paragraphs() { - foreach ( array( 'bulk-edit', 'brand-new-boost' ) as $slug ) { + // The API sends the folder-style slugs. Older cached feeds still send the short ones. + foreach ( array( 'bulk-edit', 'formidable-bulk-edit', 'formidable-tooltips', 'brand-new-boost' ) as $slug ) { $addon = $this->addon( $slug ); $this->run_private_method( array( 'FrmAddonsController', 'override_addon_display' ), array( &$addon, $slug ) ); - if ( 'bulk-edit' === $slug ) { - $this->assertNotEmpty( $addon['excerpt'] ); - } else { + if ( 'brand-new-boost' === $slug ) { $this->assertArrayNotHasKey( 'excerpt', $addon ); + } else { + $this->assertNotEmpty( $addon['excerpt'] ); } $pricing = 'https://formidableforms.com/pricing/'; @@ -244,6 +245,61 @@ public function test_boosts_are_not_counted_or_searched_as_addons() { $this->assertNull( $this->run_private_method( array( $search, 'matching_addon' ), array( $feed, array( 'tooltips' ) ) ) ); } + /** + * An installed Boost keeps its toggle when the API plugin path differs from the installed folder. + * + * @covers FrmAddonsController::get_boost_plugin_file + * + * @return void + */ + public function test_installed_boost_is_found_when_the_api_path_differs() { + $addon = $this->addon( 'field-tooltips' ); + $addon['id'] = 123; + $addon['title'] = 'Tooltips'; + $api_file = 'field-tooltips/field-tooltips.php'; + $cached = wp_cache_get( 'plugins', 'plugins' ); + + wp_cache_set( + 'plugins', + array( + '' => array( + 'formidable-tooltips/formidable-tooltips.php' => array( 'Name' => 'Formidable Tooltips' ), + 'formidable-other/formidable-other.php' => array( 'Name' => 'Formidable Other' ), + ), + ), + 'plugins' + ); + + $updater = ( new ReflectionClass( 'FrmAddon' ) )->newInstanceWithoutConstructor(); + $updater->download_id = 123; + $updater->plugin_folder = 'renamed-tooltips/renamed-tooltips.php'; + $register = static function ( $plugins ) use ( $updater ) { + $plugins['tooltips'] = $updater; + return $plugins; + }; + + $resolve = function ( $addon ) use ( $api_file ) { + return $this->run_private_method( array( 'FrmAddonsController', 'get_boost_plugin_file' ), array( $addon, $api_file ) ); + }; + + try { + // Inactive Boost: matched by its plugin name. + $this->assertSame( 'formidable-tooltips/formidable-tooltips.php', $resolve( $addon ) ); + + // Active Boost: matched by its updater download id first. + add_filter( 'frm_installed_addons', $register ); + $this->assertSame( 'renamed-tooltips/renamed-tooltips.php', $resolve( $addon ) ); + remove_filter( 'frm_installed_addons', $register ); + + // Not installed: the API path is kept. + $addon['title'] = 'Celebrations'; + $this->assertSame( $api_file, $resolve( $addon ) ); + } finally { + remove_filter( 'frm_installed_addons', $register ); + wp_cache_set( 'plugins', $cached, 'plugins' ); + } + } + /** * @param string $slug Boost slug. * From cca1b4b9a0d6e42c73896ce174a5ad74eb685a21 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Tue, 17 Nov 2026 14:02:13 -0400 Subject: [PATCH 2/2] refactor(admin): drop short Boost slugs The API now sends folder-style Boost slugs, and the short slugs never shipped in a release. Key the default Boost descriptions and icons on the current slugs only. Co-Authored-By: Claude Opus 5.5 --- classes/controllers/FrmAddonsController.php | 24 ++++++------------- classes/helpers/FrmAddonsHelper.php | 6 ----- .../misc/test_FrmBoostsMarketplace.php | 24 +++++++++---------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index 2a0d1e9e8a..30ee0e244b 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -316,25 +316,15 @@ protected static function override_addon_display( &$addon, $slug ) { } $excerpts = array( - 'advanced-modals' => __( 'Open forms and content in smart popups with various trigger options.', 'formidable' ), - 'color-picker' => __( 'Select custom or pre-set colors, including optional transparency', 'formidable' ), - 'bulk-edit' => __( 'Update multiple entries at once, no CSV export/import needed.', 'formidable' ), - 'celebrations' => __( 'Reward submissions with emoji fountains and celebratory sounds.', 'formidable' ), - 'field-tooltips' => __( 'Add customized hover-and-tap help to any field.', 'formidable' ), + 'formidable-advanced-modals' => __( 'Open forms and content in smart popups with various trigger options.', 'formidable' ), + 'formidable-color-picker' => __( 'Select custom or pre-set colors, including optional transparency', 'formidable' ), + 'formidable-bulk-edit' => __( 'Update multiple entries at once, no CSV export/import needed.', 'formidable' ), + 'formidable-celebrations' => __( 'Reward submissions with emoji fountains and celebratory sounds.', 'formidable' ), + 'formidable-tooltips' => __( 'Add customized hover-and-tap help to any field.', 'formidable' ), ); - // The API now sends Boost slugs that match their plugin folders. Older cached feeds still use the short slugs. - $current_slugs = array( - 'formidable-advanced-modals' => 'advanced-modals', - 'formidable-color-picker' => 'color-picker', - 'formidable-bulk-edit' => 'bulk-edit', - 'formidable-celebrations' => 'celebrations', - 'formidable-tooltips' => 'field-tooltips', - ); - $excerpt_slug = $current_slugs[ $slug ] ?? $slug; - - if ( isset( $excerpts[ $excerpt_slug ] ) ) { - $addon['excerpt'] = $excerpts[ $excerpt_slug ]; + if ( isset( $excerpts[ $slug ] ) ) { + $addon['excerpt'] = $excerpts[ $slug ]; } } diff --git a/classes/helpers/FrmAddonsHelper.php b/classes/helpers/FrmAddonsHelper.php index 47d7d4e1a0..e80ef5c8d2 100644 --- a/classes/helpers/FrmAddonsHelper.php +++ b/classes/helpers/FrmAddonsHelper.php @@ -180,16 +180,10 @@ public static function get_reconnect_link() { */ public static function get_addon_icon( $slug ) { $icons_map = array( - 'advanced-modals' => 'boost_popups', 'formidable-advanced-modals' => 'boost_popups', - 'simply-popups' => 'boost_popups', - 'bulk-edit' => 'boost_bulk_edit', 'formidable-bulk-edit' => 'boost_bulk_edit', - 'celebrations' => 'boost_celebrations', 'formidable-celebrations' => 'boost_celebrations', - 'color-picker' => 'boost_color_picker', 'formidable-color-picker' => 'boost_color_picker', - 'field-tooltips' => 'boost_tooltips', 'formidable-tooltips' => 'boost_tooltips', 'acf-forms' => 'acfforms', 'activecampaign-wordpress-plugin' => 'activecampaign', diff --git a/tests/phpunit/misc/test_FrmBoostsMarketplace.php b/tests/phpunit/misc/test_FrmBoostsMarketplace.php index 81c69da235..88bca461bd 100644 --- a/tests/phpunit/misc/test_FrmBoostsMarketplace.php +++ b/tests/phpunit/misc/test_FrmBoostsMarketplace.php @@ -50,8 +50,7 @@ public function test_boost_detection_and_categories() { /** @return void */ public function test_missing_excerpts_render_without_empty_paragraphs() { - // The API sends the folder-style slugs. Older cached feeds still send the short ones. - foreach ( array( 'bulk-edit', 'formidable-bulk-edit', 'formidable-tooltips', 'brand-new-boost' ) as $slug ) { + foreach ( array( 'formidable-bulk-edit', 'formidable-tooltips', 'brand-new-boost' ) as $slug ) { $addon = $this->addon( $slug ); $this->run_private_method( array( 'FrmAddonsController', 'override_addon_display' ), array( &$addon, $slug ) ); @@ -209,7 +208,7 @@ public function test_only_the_addon_api_requests_boosts() { public function test_boosts_are_not_counted_or_searched_as_addons() { // The Boost comes first so a search that does not skip Boosts would match it. $feed = array( - '2' => $this->addon( 'field-tooltips' ) + array( + '2' => $this->addon( 'formidable-tooltips' ) + array( 'name' => 'Tooltips', 'excerpt' => 'Add tooltips.', 'search_terms' => 'tooltips', @@ -253,18 +252,19 @@ public function test_boosts_are_not_counted_or_searched_as_addons() { * @return void */ public function test_installed_boost_is_found_when_the_api_path_differs() { - $addon = $this->addon( 'field-tooltips' ); + // The API sends this path, but Advanced Modals ships its main file as frm-advanced-modals.php. + $addon = $this->addon( 'formidable-advanced-modals' ); $addon['id'] = 123; - $addon['title'] = 'Tooltips'; - $api_file = 'field-tooltips/field-tooltips.php'; + $addon['title'] = 'Advanced Modals'; + $api_file = 'formidable-advanced-modals/formidable-advanced-modals.php'; $cached = wp_cache_get( 'plugins', 'plugins' ); wp_cache_set( 'plugins', array( '' => array( - 'formidable-tooltips/formidable-tooltips.php' => array( 'Name' => 'Formidable Tooltips' ), - 'formidable-other/formidable-other.php' => array( 'Name' => 'Formidable Other' ), + 'formidable-advanced-modals/frm-advanced-modals.php' => array( 'Name' => 'Formidable Advanced Modals' ), + 'formidable-other/formidable-other.php' => array( 'Name' => 'Formidable Other' ), ), ), 'plugins' @@ -272,9 +272,9 @@ public function test_installed_boost_is_found_when_the_api_path_differs() { $updater = ( new ReflectionClass( 'FrmAddon' ) )->newInstanceWithoutConstructor(); $updater->download_id = 123; - $updater->plugin_folder = 'renamed-tooltips/renamed-tooltips.php'; + $updater->plugin_folder = 'renamed-modals/frm-advanced-modals.php'; $register = static function ( $plugins ) use ( $updater ) { - $plugins['tooltips'] = $updater; + $plugins['advanced-modals'] = $updater; return $plugins; }; @@ -284,11 +284,11 @@ public function test_installed_boost_is_found_when_the_api_path_differs() { try { // Inactive Boost: matched by its plugin name. - $this->assertSame( 'formidable-tooltips/formidable-tooltips.php', $resolve( $addon ) ); + $this->assertSame( 'formidable-advanced-modals/frm-advanced-modals.php', $resolve( $addon ) ); // Active Boost: matched by its updater download id first. add_filter( 'frm_installed_addons', $register ); - $this->assertSame( 'renamed-tooltips/renamed-tooltips.php', $resolve( $addon ) ); + $this->assertSame( 'renamed-modals/frm-advanced-modals.php', $resolve( $addon ) ); remove_filter( 'frm_installed_addons', $register ); // Not installed: the API path is kept.