PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / classes / class-deactivate-duplicate-plugin.php

class-deactivate-duplicate-plugin.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.0, at classes/class-deactivate-duplicate-plugin.php

85 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checks if another version of Ghost Kit/Ghost Kit Pro is active and deactivates it.
4 *
5 * @package ghostkit/deactivate-duplicate-plugin
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Deactivate_Duplicate_Plugin
14 */
15 class GhostKit_Deactivate_Duplicate_Plugin {
16 /**
17 * GhostKit_Deactivate_Duplicate_Plugin constructor.
18 */
19 public function __construct() {
20 add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) );
21 add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) );
22 }
23
24 /**
25 * Checks if another version of Ghost Kit/Ghost Kit Pro is active and deactivates it.
26 * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
27 *
28 * @param string $plugin The plugin being activated.
29 */
30 public function deactivate_other_instances( $plugin ) {
31 if ( ! in_array( $plugin, array( 'ghostkit/class-ghost-kit.php', 'ghostkit-pro/class-ghost-kit-pro.php' ), true ) ) {
32 return;
33 }
34
35 $plugin_to_deactivate = 'ghostkit/class-ghost-kit.php';
36 $deactivated_notice_id = 1;
37
38 // If we just activated the free version, deactivate the Pro version.
39 if ( $plugin === $plugin_to_deactivate ) {
40 $plugin_to_deactivate = 'ghostkit-pro/class-ghost-kit-pro.php';
41 $deactivated_notice_id = 2;
42 }
43
44 if ( is_multisite() && is_network_admin() ) {
45 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
46 $active_plugins = array_keys( $active_plugins );
47 } else {
48 $active_plugins = (array) get_option( 'active_plugins', array() );
49 }
50
51 foreach ( $active_plugins as $plugin_basename ) {
52 if ( $plugin_to_deactivate === $plugin_basename ) {
53 set_transient( 'gkt_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
54 deactivate_plugins( $plugin_basename );
55 return;
56 }
57 }
58 }
59
60 /**
61 * Displays a notice when either Ghost Kit or Ghost Kit Pro is automatically deactivated.
62 */
63 public function plugin_deactivated_notice() {
64 $deactivated_notice_id = (int) get_transient( 'gkt_deactivated_notice_id' );
65 if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) {
66 return;
67 }
68
69 $message = __( "Ghost Kit and Ghost Kit Pro should not be active at the same time. We've automatically deactivated Ghost Kit.", 'ghostkit' );
70 if ( 2 === $deactivated_notice_id ) {
71 $message = __( "Ghost Kit and Ghost Kit Pro should not be active at the same time. We've automatically deactivated Ghost Kit Pro.", 'ghostkit' );
72 }
73
74 ?>
75 <div class="notice notice-warning">
76 <p><?php echo esc_html( $message ); ?></p>
77 </div>
78 <?php
79
80 delete_transient( 'gkt_deactivated_notice_id' );
81 }
82 }
83
84 new GhostKit_Deactivate_Duplicate_Plugin();
85