<?php
/**
 * The plugin bootstrap file
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all of the dependencies used by the plugin,
 * registers the activation and deactivation functions, and defines a function
 * that starts the plugin.
 *
 * @link              https://profiles.wordpress.org/gohelkunjan/
 * @since             1.0.1
 * @package           KG_Digital_Catalog_For_WooCommerce
 *
 * @wordpress-plugin
 * Plugin Name:       KG Digital Catalog for WooCommerce
 * Description:       KG Digital Catalog for WooCommerce instantly generates clean, professional PDF catalogs of your online store products.
 * Version:           1.0.1
 * Author:            gohelkunjan
 * Author URI:        https://profiles.wordpress.org/gohelkunjan/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       kg-digital-catalog-for-woocommerce
 * Domain Path:       /languages
 * Requires Plugins:  woocommerce
 */
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Currently plugin version.
 * Start at version 1.0.0 and use SemVer - https://semver.org
 * Rename this for your plugin and update it as you release new versions.
 */
define( 'KGDC_VERSION', '1.0.1' );
/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require plugin_dir_path( __FILE__ ) . 'includes/class-kg-digital-catalog-for-woocommerce.php';
require plugin_dir_path( __FILE__ ) . 'product-custom-bulk-actions.php';
/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function kgdc_run_plugin() {
	if ( ! function_exists( 'is_plugin_active' ) ) {
		require_once ABSPATH . 'wp-admin/includes/plugin.php';
	}
	
	// Deactivate plugin if WooCommerce is not active
	if ( is_admin() && ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
		add_action( 'admin_notices', 'kgdc_woocommerce_missing_notice' );
		deactivate_plugins( plugin_basename( __FILE__ ) );
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['activate'] ) ) {
			unset( $_GET['activate'] );
		}
		return;
	}

	$plugin = new KGDC_Main();
	$plugin->run();
}
kgdc_run_plugin();

function kgdc_woocommerce_missing_notice() {
	echo '<div class="notice notice-error is-dismissible"><p><strong>KG Digital Catalog for WooCommerce</strong> requires WooCommerce to be installed and active. The plugin has been automatically deactivated.</p></div>';
}

/**
 * Activate the plugin and set default options if they don't exist.
 */
function kgdc_activate_plugin() {
	if ( get_option( 'kgdc_pdf_layout_type' ) === false ) {
		update_option( 'kgdc_pdf_layout_type', '1' );
	}
	if ( get_option( 'kgdc_button_text' ) === false ) {
		update_option( 'kgdc_button_text', 'BUY NOW' );
	}
}
register_activation_hook( __FILE__, 'kgdc_activate_plugin' );
