@@ -7402,11 +7402,12 @@ function _activate_plugin_event_hook() {
74027402 * @author Leo Fajardo (@leorw)
74037403 * @since 1.2.2
74047404 */
7405- if (
7406- is_plugin_active( $other_version_basename ) &&
7407- $this->apply_filters( 'deactivate_on_activation', true )
7408- ) {
7409- deactivate_plugins( $other_version_basename );
7405+ if ( is_plugin_active( $other_version_basename ) ) {
7406+ if ( $this->apply_filters( 'deactivate_on_activation', true ) ) {
7407+ deactivate_plugins( $other_version_basename );
7408+ } else {
7409+ add_action( 'activated_plugin', array( &$this, '_activated_plugin' ), 10, 2 );
7410+ }
74107411 }
74117412 }
74127413
@@ -7544,6 +7545,44 @@ function _activate_plugin_event_hook() {
75447545 $this->_storage->was_plugin_loaded = true;
75457546 }
75467547
7548+ /**
7549+ * @author Leo Fajardo (@leorw)
7550+ * @since 2.8.0
7551+ *
7552+ * @param string $plugin
7553+ * @param bool $network_wide
7554+ */
7555+ function _activated_plugin( $plugin, $network_wide ) {
7556+ $this->move_free_plugin_to_end_of_active_plugins( $this->_free_plugin_basename );
7557+
7558+ if ( $plugin !== $this->_free_plugin_basename ) {
7559+ /**
7560+ * To avoid placing the free version at the start of the active plugins option when the SDK is loaded from it, remove the SDK reference linked to the free version if it is the newest.
7561+ */
7562+ fs_remove_sdk_reference_by_basename( $this->_free_plugin_basename );
7563+ }
7564+ }
7565+
7566+ /**
7567+ * @author Leo Fajardo (@leorw)
7568+ * @since 2.8.0
7569+ *
7570+ * @param string $plugin
7571+ */
7572+ private function move_free_plugin_to_end_of_active_plugins( $plugin ) {
7573+ $active_plugins = get_option( 'active_plugins' );
7574+
7575+ // Move the free version to the last position in the active plugins option.
7576+ if ( false !== ( $key = array_search( $plugin, $active_plugins ) ) ) {
7577+ unset( $active_plugins[ $key ]);
7578+
7579+ $active_plugins[] = $plugin;
7580+ }
7581+
7582+ // Update the active plugins option with the reordered plugins.
7583+ update_option('active_plugins', $active_plugins);
7584+ }
7585+
75477586 /**
75487587 * @author Leo Fajardo (@leorw)
75497588 * @since 2.3.0
@@ -8202,16 +8241,7 @@ function _deactivate_plugin_hook() {
82028241 * @since 1.1.6
82038242 */
82048243 private function remove_sdk_reference() {
8205- global $fs_active_plugins;
8206-
8207- foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
8208- if ( $this->_plugin_basename == $data->plugin_path ) {
8209- unset( $fs_active_plugins->plugins[ $sdk_path ] );
8210- break;
8211- }
8212- }
8213-
8214- fs_fallback_to_newest_active_sdk();
8244+ fs_remove_sdk_reference_by_basename( $this->_plugin_basename );
82158245 }
82168246
82178247 /**
0 commit comments