Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ 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' ),
);

if ( isset( $excerpts[ $slug ] ) ) {
Expand Down Expand Up @@ -1145,6 +1145,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'] ) {
Expand Down Expand Up @@ -1189,6 +1194,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
Expand Down
11 changes: 5 additions & 6 deletions classes/helpers/FrmAddonsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ public static function get_reconnect_link() {
*/
public static function get_addon_icon( $slug ) {
$icons_map = array(
'advanced-modals' => 'boost_popups',
'simply-popups' => 'boost_popups',
'bulk-edit' => 'boost_bulk_edit',
'celebrations' => 'boost_celebrations',
'color-picker' => 'boost_color_picker',
'field-tooltips' => 'boost_tooltips',
'formidable-advanced-modals' => 'boost_popups',
'formidable-bulk-edit' => 'boost_bulk_edit',
'formidable-celebrations' => 'boost_celebrations',
'formidable-color-picker' => 'boost_color_picker',
'formidable-tooltips' => 'boost_tooltips',
'acf-forms' => 'acfforms',
'activecampaign-wordpress-plugin' => 'activecampaign',
'ai' => 'ai-form',
Expand Down
66 changes: 61 additions & 5 deletions tests/phpunit/misc/test_FrmBoostsMarketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ 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 ) {
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 ) );

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/';
Expand Down Expand Up @@ -208,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',
Expand Down Expand Up @@ -244,6 +244,62 @@ 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() {
// 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'] = 'Advanced Modals';
$api_file = 'formidable-advanced-modals/formidable-advanced-modals.php';
$cached = wp_cache_get( 'plugins', 'plugins' );

wp_cache_set(
'plugins',
array(
'' => array(
'formidable-advanced-modals/frm-advanced-modals.php' => array( 'Name' => 'Formidable Advanced Modals' ),
'formidable-other/formidable-other.php' => array( 'Name' => 'Formidable Other' ),
),
),
'plugins'
);

$updater = ( new ReflectionClass( 'FrmAddon' ) )->newInstanceWithoutConstructor();
$updater->download_id = 123;
$updater->plugin_folder = 'renamed-modals/frm-advanced-modals.php';
$register = static function ( $plugins ) use ( $updater ) {
$plugins['advanced-modals'] = $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-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-modals/frm-advanced-modals.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.
*
Expand Down
Loading