-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved the support for plugins with free and premium versions that … #727
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7402,11 +7402,12 @@ function _activate_plugin_event_hook() { | |
* @author Leo Fajardo (@leorw) | ||
* @since 1.2.2 | ||
*/ | ||
if ( | ||
is_plugin_active( $other_version_basename ) && | ||
$this->apply_filters( 'deactivate_on_activation', true ) | ||
) { | ||
deactivate_plugins( $other_version_basename ); | ||
if ( is_plugin_active( $other_version_basename ) ) { | ||
if ( $this->apply_filters( 'deactivate_on_activation', true ) ) { | ||
deactivate_plugins( $other_version_basename ); | ||
} else { | ||
add_action( 'activated_plugin', array( &$this, '_activated_plugin' ), 10, 2 ); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -7544,6 +7545,45 @@ function _activate_plugin_event_hook() { | |
$this->_storage->was_plugin_loaded = true; | ||
} | ||
|
||
/** | ||
* @author Leo Fajardo (@leorw) | ||
* @since 2.8.0 | ||
* | ||
* @param string $plugin | ||
* @param bool $network_wide | ||
*/ | ||
function _activated_plugin( $plugin, $network_wide ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposing to rename this function to |
||
// We cannot rely on fs_remove_sdk_reference_by_basename() for reordering, as the latest SDK reference might be associated with a different product, leading to the reordering of that product instead of the intended one. | ||
$this->move_free_plugin_to_end_of_active_plugins( $this->_free_plugin_basename ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest not to pass the |
||
|
||
if ( $plugin !== $this->_free_plugin_basename ) { | ||
/** | ||
* 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. | ||
*/ | ||
fs_remove_sdk_reference_by_basename( $this->_free_plugin_basename ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it hurt us even if the SDK reference from the free version is at top? I don't mind doing this "just in case", but just asking for my understanding. |
||
} | ||
} | ||
|
||
/** | ||
* @author Leo Fajardo (@leorw) | ||
* @since 2.8.0 | ||
* | ||
* @param string $plugin | ||
*/ | ||
private function move_free_plugin_to_end_of_active_plugins( $plugin ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the if ( empty( $this->_free_plugin_basename ) ) {
return;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
$active_plugins = get_option( 'active_plugins' ); | ||
|
||
// Move the free version to the last position in the active plugins option. | ||
if ( false !== ( $key = array_search( $plugin, $active_plugins ) ) ) { | ||
unset( $active_plugins[ $key ] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's either use |
||
|
||
$active_plugins[] = $plugin; | ||
} | ||
|
||
// Update the active plugins option with the reordered plugins. | ||
update_option( 'active_plugins', $active_plugins ); | ||
} | ||
|
||
/** | ||
* @author Leo Fajardo (@leorw) | ||
* @since 2.3.0 | ||
|
@@ -8202,16 +8242,7 @@ function _deactivate_plugin_hook() { | |
* @since 1.1.6 | ||
*/ | ||
private function remove_sdk_reference() { | ||
global $fs_active_plugins; | ||
|
||
foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) { | ||
if ( $this->_plugin_basename == $data->plugin_path ) { | ||
unset( $fs_active_plugins->plugins[ $sdk_path ] ); | ||
break; | ||
} | ||
} | ||
|
||
fs_fallback_to_newest_active_sdk(); | ||
fs_remove_sdk_reference_by_basename( $this->_plugin_basename ); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the sake of properly handling bulk activation, can we also do this?