|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 |
|
| 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 | + $GLOBALS['OTHER_STACKABLE_FILE'] = plugin_basename( STACKABLE_FILE ); |
| 32 | + |
| 33 | + // Use a temporary option to store the other Stackable Plugin info needed for the admin notice. This will be deleted later. |
| 34 | + // Note: We cannot use add_action in the register_activation_hook callback so we use this temporary option. |
| 35 | + // See https://developer.wordpress.org/reference/functions/register_activation_hook/#process-flow for more info. |
| 36 | + add_option( 'stackable_other_stackable_plugin_info', [ 'BUILD' => STACKABLE_BUILD, 'VERSION' => STACKABLE_VERSION ] ); |
| 37 | + |
| 38 | + register_activation_hook( __FILE__, 'stackable_multiple_plugins_check' ); |
| 39 | +} |
| 40 | + |
20 | 41 | // Freemius SDK: Auto deactivate the free version when activating the paid one. |
21 | 42 | if ( function_exists( 'sugb_fs' ) ) { |
22 | 43 | sugb_fs()->set_basename( true, __FILE__ ); |
@@ -158,6 +179,28 @@ function stackable_notice_gutenberg_plugin_ignore() { |
158 | 179 | add_action( 'wp_ajax_stackable_notice_gutenberg_plugin_ignore', 'stackable_notice_gutenberg_plugin_ignore' ); |
159 | 180 | } |
160 | 181 |
|
| 182 | +/** |
| 183 | + * Show notice if another Stackable plugin has been deactivated. |
| 184 | + * |
| 185 | + * @since 3.18.1 |
| 186 | + */ |
| 187 | +if ( ! function_exists( 'stackable_notice_other_stackable_plugin_deactivated' ) ) { |
| 188 | + function stackable_notice_other_stackable_plugin_deactivated() { |
| 189 | + $OTHER_STACKABLE_INFO = get_option( 'stackable_other_stackable_plugin_info', false ); |
| 190 | + if ( $OTHER_STACKABLE_INFO ) { |
| 191 | + printf( |
| 192 | + '<div class="notice notice-info is-dismissible stackable_notice_gutenberg_plugin"><p>%s</p></div>', |
| 193 | + 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'] ) |
| 194 | + ); |
| 195 | + delete_option( 'stackable_other_stackable_plugin_info' ); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + if ( get_option( 'stackable_other_stackable_plugin_info', false ) ) { |
| 200 | + add_action( 'admin_notices', 'stackable_notice_other_stackable_plugin_deactivated' ); |
| 201 | + } |
| 202 | +} |
| 203 | + |
161 | 204 | /******************************************************************************************** |
162 | 205 | * END Activation & PHP version checks. |
163 | 206 | ********************************************************************************************/ |
|
0 commit comments