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
21 changes: 20 additions & 1 deletion classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ protected static function set_categories( &$addon ) {
* @return void
*/
public static function license_settings() {
$plugins = apply_filters( 'frm_installed_addons', array() );
$plugins = self::get_plugins_for_license_settings();

if ( ! $plugins ) {
esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
Expand All @@ -450,6 +450,25 @@ public static function license_settings() {
include FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php';
}

/**
* Gets installed add-ons that accept a separate license key.
*
* @since x.x
*
* @return array
*/
public static function get_plugins_for_license_settings() {
$plugins = apply_filters( 'frm_installed_addons', array() );
foreach ( $plugins as $slug => $plugin ) {
$is_pro = 'formidable_pro' === $slug || 'Formidable Pro' === $plugin->plugin_name;
if ( $is_pro || $plugin->is_parent_licence || ! $plugin->needs_license || ! empty( $plugin->is_boost ) ) {
unset( $plugins[ $slug ] );
}
}

return $plugins;
}

/**
* @return array
*/
Expand Down
31 changes: 9 additions & 22 deletions classes/controllers/FrmSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,15 @@ private static function get_settings_tabs() {
),
);

if ( apply_filters( 'frm_include_addon_page', false ) ) {
// If no addons need a license, skip this page
$show_licenses = false;
$installed_addons = apply_filters( 'frm_installed_addons', array() );

foreach ( $installed_addons as $installed_addon ) {
if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name !== 'Formidable Pro' && $installed_addon->needs_license ) {
$show_licenses = true;
break;
}
}

if ( $show_licenses ) {
$sections['licenses'] = array(
'class' => 'FrmAddonsController',
'function' => 'license_settings',
'name' => __( 'Plugin Licenses', 'formidable' ),
'icon' => 'frmfont frm_key_icon',
'ajax' => true,
);
}
}//end if
if ( apply_filters( 'frm_include_addon_page', false ) && FrmAddonsController::get_plugins_for_license_settings() ) {
$sections['licenses'] = array(
'class' => 'FrmAddonsController',
'function' => 'license_settings',
'name' => __( 'Plugin Licenses', 'formidable' ),
'icon' => 'frmfont frm_key_icon',
'ajax' => true,
);
}

/**
* @param array<array> $sections
Expand Down
4 changes: 0 additions & 4 deletions classes/views/addons/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<?php

foreach ( $plugins as $slug => $plugin ) {
if ( $slug === 'formidable_pro' || $plugin->is_parent_licence || ! $plugin->needs_license ) {
continue;
}

$license = $plugin->license;
$status = get_option( $plugin->option_name . 'active' );
$activate = false !== $license && $status === 'valid' ? 'deactivate' : 'activate';
Expand Down
41 changes: 41 additions & 0 deletions tests/phpunit/misc/test_FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,47 @@ function () use ( $plugin_file ) {
}
}

/**
* Boosts run on the Pro license, so they never get a license row or the Plugin Licenses tab.
*
* @covers FrmAddonsController::get_plugins_for_license_settings
*
* @return void
*/
public function test_get_plugins_for_license_settings_excludes_boosts() {
$boost = $this->make_installed_addon( 'Some Boost' );
$boost->is_boost = true;
$addon = $this->make_installed_addon( 'Some Add-On' );
$register = static function ( $plugins ) use ( $boost, $addon ) {
$plugins['some_boost'] = $boost;
$plugins['some_add_on'] = $addon;
return $plugins;
};
add_filter( 'frm_installed_addons', $register );

try {
$this->assertSame( array( 'some_add_on' => $addon ), FrmAddonsController::get_plugins_for_license_settings() );
} finally {
remove_filter( 'frm_installed_addons', $register );
}
}

/**
* Build a stand-in for an installed add-on that needs its own license.
*
* @param string $name The add-on name shown in the license settings.
*
* @return stdClass
*/
private function make_installed_addon( $name ) {
$addon = new stdClass();
$addon->plugin_name = $name;
$addon->is_parent_licence = false;
$addon->needs_license = true;
$addon->is_boost = false;
return $addon;
}

/**
* Serve a fixed add-on list from the API for the length of the callback.
*
Expand Down
Loading