Skip to content

fix: auto-deactivate other active Stackable plugin #3574

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@
exit;
}

if ( ! function_exists( 'stackable_multiple_plugins_check' ) ) {
// Prevent multiple Stackable plugin versions from being active simultaneously.
function stackable_multiple_plugins_check() {
if ( is_plugin_active( $GLOBALS['OTHER_STACKABLE_FILE'] ) ) {
deactivate_plugins( $GLOBALS['OTHER_STACKABLE_FILE'] );
}
}
}

if ( defined('STACKABLE_FILE') && STACKABLE_FILE !== __FILE__ && ! isset( $GLOBALS['OTHER_STACKABLE_FILE'] ) ) {
// Get relative file path of the other Stackable version.
$GLOBALS['OTHER_STACKABLE_FILE'] = plugin_basename( STACKABLE_FILE );

// Use a temporary option to store the other Stackable Plugin info needed for the admin notice. This will be deleted later.
// Note: We cannot use add_action in the register_activation_hook callback so we use this temporary option.
// See https://developer.wordpress.org/reference/functions/register_activation_hook/#process-flow for more info.
add_option( 'stackable_other_stackable_plugin_info', [ 'BUILD' => STACKABLE_BUILD, 'VERSION' => STACKABLE_VERSION ] );

register_activation_hook( __FILE__, 'stackable_multiple_plugins_check' );
}

// Freemius SDK: Auto deactivate the free version when activating the paid one.
if ( function_exists( 'sugb_fs' ) ) {
sugb_fs()->set_basename( true, __FILE__ );
Expand Down Expand Up @@ -158,6 +179,28 @@ function stackable_notice_gutenberg_plugin_ignore() {
add_action( 'wp_ajax_stackable_notice_gutenberg_plugin_ignore', 'stackable_notice_gutenberg_plugin_ignore' );
}

/**
* Show notice if another Stackable plugin has been deactivated.
*
* @since 3.18.1
*/
if ( ! function_exists( 'stackable_notice_other_stackable_plugin_deactivated' ) ) {
function stackable_notice_other_stackable_plugin_deactivated() {
$OTHER_STACKABLE_INFO = get_option( 'stackable_other_stackable_plugin_info', false );
if ( $OTHER_STACKABLE_INFO ) {
printf(
'<div class="notice notice-info is-dismissible stackable_notice_gutenberg_plugin"><p>%s</p></div>',
sprintf( esc_html__( '%sStackable Notice%s: The Stackable plugin (%s version %s) has been deactivated. Only one active Stackable plugin is needed.', STACKABLE_I18N ), '<strong>', '</strong>', $OTHER_STACKABLE_INFO['BUILD'], $OTHER_STACKABLE_INFO['VERSION'] )
);
delete_option( 'stackable_other_stackable_plugin_info' );
}
}

if ( get_option( 'stackable_other_stackable_plugin_info', false ) ) {
add_action( 'admin_notices', 'stackable_notice_other_stackable_plugin_deactivated' );
}
}

/********************************************************************************************
* END Activation & PHP version checks.
********************************************************************************************/
Expand Down
Loading