Skip to content

Commit 11e5f09

Browse files
committed
prevent multiple active stackable plugins
1 parent 31adb03 commit 11e5f09

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

plugin.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@
1717
exit;
1818
}
1919

20+
if ( ! function_exists( 'stackable_multiple_plugins_check' ) ) {
21+
// Prevent multiple Stackable plugin versions from being active simultaneously.
22+
function stackable_multiple_plugins_check() {
23+
if ( is_plugin_active( $GLOBALS['OTHER_STACKABLE_FILE'] ) ) {
24+
deactivate_plugins( $GLOBALS['OTHER_STACKABLE_FILE'] );
25+
}
26+
}
27+
}
28+
29+
if ( defined('STACKABLE_FILE') && STACKABLE_FILE !== __FILE__ && ! isset( $GLOBALS['OTHER_STACKABLE_FILE'] ) ) {
30+
// Get relative file path of the other Stackable version.
31+
preg_match( "#([^\/]*?\/plugin.php)$#", STACKABLE_FILE, $matches );
32+
$GLOBALS['OTHER_STACKABLE_FILE'] = $matches[1];
33+
34+
register_activation_hook( __FILE__, 'stackable_multiple_plugins_check' );
35+
}
36+
2037
// Freemius SDK: Auto deactivate the free version when activating the paid one.
2138
if ( function_exists( 'sugb_fs' ) ) {
22-
// Prevent PHP errors by checking sugb_fs return value.
23-
// In the free version, sugb_fs() is a no-op function that returns null.
24-
// Only proceed if sugb_fs() returns an object (i.e., the Freemius SDK is loaded).
25-
if ( is_object( sugb_fs() ) ) {
26-
sugb_fs()->set_basename( false, __FILE__ );
27-
return;
28-
}
39+
sugb_fs()->set_basename( true, __FILE__ );
40+
return;
2941
}
3042

3143
defined( 'STACKABLE_SHOW_PRO_NOTICES' ) || define( 'STACKABLE_SHOW_PRO_NOTICES', true );
@@ -218,11 +230,6 @@ function is_frontend() {
218230
*/
219231
if ( STACKABLE_BUILD !== 'free' ) {
220232
require_once( plugin_dir_path( __FILE__ ) . 'freemius.php' );
221-
} else if ( ! function_exists( 'sugb_fs' ) ) {
222-
// Provide a no-op sugb_fs() stub for compatibility when Freemius SDK is not loaded.
223-
// This allows themes and plugins to safely check for Stackable's presence.
224-
// The function returns null and performs no actions.
225-
function sugb_fs() {};
226233
}
227234

228235
/**

0 commit comments

Comments
 (0)