diff --git a/classes/controllers/FrmAddonsController.php b/classes/controllers/FrmAddonsController.php index 83bb71c5b9..eece9bb7dd 100644 --- a/classes/controllers/FrmAddonsController.php +++ b/classes/controllers/FrmAddonsController.php @@ -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' ); @@ -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 */ diff --git a/classes/controllers/FrmSettingsController.php b/classes/controllers/FrmSettingsController.php index 2e79fd1923..2c777f09ed 100644 --- a/classes/controllers/FrmSettingsController.php +++ b/classes/controllers/FrmSettingsController.php @@ -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 $sections diff --git a/classes/views/addons/settings.php b/classes/views/addons/settings.php index d0ca2501b6..2c069682ea 100644 --- a/classes/views/addons/settings.php +++ b/classes/views/addons/settings.php @@ -15,10 +15,6 @@ $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'; diff --git a/tests/phpunit/misc/test_FrmAddonsController.php b/tests/phpunit/misc/test_FrmAddonsController.php index 3833d84caa..eeebc28b46 100644 --- a/tests/phpunit/misc/test_FrmAddonsController.php +++ b/tests/phpunit/misc/test_FrmAddonsController.php @@ -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. *