Skip to content

Commit

Permalink
Improved the support for plugins with free and premium versions that …
Browse files Browse the repository at this point in the history
…can be activated in parallel.
  • Loading branch information
fajardoleo committed Jul 23, 2024
1 parent de76663 commit f49b565
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -7407,6 +7407,11 @@ function _activate_plugin_event_hook() {
$this->apply_filters( 'deactivate_on_activation', true )
) {
deactivate_plugins( $other_version_basename );
} else if ( $is_premium_version_activation ) {
/**
* To prevent the free version from loading before the premium version when both are active, remove the SDK reference associated with the free version if it's the newest.
*/
$this->remove_sdk_reference( $other_version_basename );
}
}

Expand Down Expand Up @@ -8198,20 +8203,35 @@ function _deactivate_plugin_hook() {
}

/**
* @since 1.1.6
* @since 1.7.4 The $plugin_basename parameter was added by Leo Fajardo (@leorw).
*
* @author Vova Feldman (@svovaf)
* @since 1.1.6
* @author Leo Fajardo (@leorw)
*
* @param string|null $plugin_basename
*/
private function remove_sdk_reference() {
private function remove_sdk_reference( $plugin_basename = null ) {
global $fs_active_plugins;

if ( is_null( $plugin_basename ) ) {
$plugin_basename = $this->_plugin_basename;
}

foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
if ( $this->_plugin_basename == $data->plugin_path ) {
if ( $plugin_basename == $data->plugin_path ) {
unset( $fs_active_plugins->plugins[ $sdk_path ] );
break;
}
}

fs_fallback_to_newest_active_sdk();
if (
! empty( $fs_active_plugins->newest ) &&
! empty( $fs_active_plugins->newest->plugin_path ) &&
$fs_active_plugins->newest->plugin_path === $plugin_basename
) {
fs_fallback_to_newest_active_sdk();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion start.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$this_sdk_version = '2.7.3.5';
$this_sdk_version = '2.7.3.6';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down

0 comments on commit f49b565

Please sign in to comment.