=' ) && version_compare( $wp_version, '5.5', '>=' ) && class_exists( 'GFForms' ) ); } /** * Display a notice if requirements are not met. * * @return void */ function notice_for_missing_requirements() { printf( '

%1$s

', esc_html__( 'The "Gravity Forms to Brevo" Add-On is inactive because the minimal requirements are not met.', 'addon-gravityforms-sendinblue-free' ) ); } /** * Trigger a custom action when activating the plugin. * * @param string $plugin * @param boolean $network * @return void */ function on_plugin_activation( $plugin, $network ) { if ( $plugin !== DKGFSIB_FREE_BASENAME ) { return; } init(); do_action( 'dk-gf-sib-free/plugin-activated', (bool) $network ); } add_action( 'activate_plugin', __NAMESPACE__ . '\\on_plugin_activation', 10, 2 ); /** * Trigger a custom action when de-activating the plugin. * * @return void */ function on_plugin_deactivation( $plugin, $network ) { if ( $plugin !== DKGFSIB_FREE_BASENAME ) { return; } init(); do_action( 'dk-gf-sib-free/plugin-deactivated', (bool) $network ); } add_action( 'deactivate_plugin', __NAMESPACE__ . '\\on_plugin_deactivation', 10, 2 ); /** * Register our add-on. * * @return void */ function register_addon() { if ( ! method_exists( 'GFForms', 'include_addon_framework' ) ) { return; } // Stop here if the pro version is enabled if ( is_pro_enabled() ) { return; } init(); GFAddOn::register( 'DK_GF_SIB_FREE\GF_Addon' ); } add_action( 'gform_loaded', __NAMESPACE__ . '\\register_addon', 5 ); /** * Settings Link. * * @param array $links The array of plugin settings links. * @return array */ function add_settings_link( $links ) { $settings_link[] = "" . esc_html( __( 'Upgrade to PRO', 'addon-gravityforms-sendinblue-free' ) ) . ''; $links = array_merge( $settings_link, $links ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\\add_settings_link' ); /** * Return true if the pro version of the add-on is enabled. * * @return bool */ function is_pro_enabled() { return defined( 'DKGFSIB_VERSION' ) || defined( 'WPCONNECT_GF_SIB_VERSION' ); } /** * Checks if another version of Gravity Forms to Sendinblue Free/Pro is active and deactivates it. * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated. * * @param string $plugin The plugin being activated. * @return */ function deactivate_other_instances( $plugin ) { if ( ! in_array( $plugin, array( 'addon-gravityforms-sendinblue-free/addon-gravityforms-sendinblue-free.php', 'wpconnect-gf-sendinblue/wpconnect-gf-sendinblue.php' ), true ) ) { return; } $plugin_to_deactivate = 'addon-gravityforms-sendinblue-free/addon-gravityforms-sendinblue-free.php'; $deactivated_notice_id = '1'; // If we just activated the Free version, deactivate the Pro version. if ( $plugin === $plugin_to_deactivate ) { $plugin_to_deactivate = 'wpconnect-gf-sendinblue/wpconnect-gf-sendinblue.php'; $deactivated_notice_id = '2'; } if ( is_multisite() && is_network_admin() ) { $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); $active_plugins = array_keys( $active_plugins ); } else { $active_plugins = (array) get_option( 'active_plugins', array() ); } foreach ( $active_plugins as $plugin_basename ) { if ( $plugin_to_deactivate === $plugin_basename ) { set_transient( 'wpconnectgfsib_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS ); deactivate_plugins( $plugin_basename ); return; } } } add_action( 'activated_plugin', __NAMESPACE__ . '\\deactivate_other_instances', 10, 1 ); /** * Displays a notice when either Gravity Forms to Sendinblue Free or Gravity Forms to Sendinblue Pro is automatically deactivated. * * @return void */ function plugin_deactivated_notice() { $deactivated_notice_id = (int) get_transient( 'wpconnectgfsib_deactivated_notice_id' ); if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) { return; } $message = __( "Add-on Brevo for Gravity Forms Free and Gravity Forms to Brevo Add-On should not be active at the same time. We've automatically deactivated Gravity Forms to Brevo Add-On", 'wpc-gf-sib' ); if ( 2 === $deactivated_notice_id ) { $message = __( "Gravity Forms to Brevo Add-On and Add-on Brevo for Gravity Forms Free should not be active at the same time. We've automatically deactivated Gravity Forms to Brevo Add-On.", 'wpc-gf-sib' ); } ?>