<?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://autoserve.io
 * @since             1.0.0
 * @package           Messageflow
 *
 * @wordpress-plugin
 * Plugin Name:       MessageFlow
 * Plugin URI:        https://messageflow.co
 * Description:       A Free, one-click-to-install, SMS telecommunication plugin made for e-commerce stores.
 * Version:           1.1.2.2
 * Author:            Autoserve
 * Author URI:        https://autoserve.io
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       messageflow
 * Domain Path:       /languages
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * 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( 'MESSAGEFLOW_VERSION', '1.1.2.2' );

/**
 * The path of the current plugin
 */
define( 'MESSAGEFLOW_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );

/**
 * The URL of the current plugin
 */
define( 'MESSAGEFLOW_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

/**
 * Check for the existence of WooCommerce plugin
 */
function messageflow_check_requirements() {
	if (!function_exists('is_plugin_active')) {
    include_once(ABSPATH . 'wp-admin/includes/plugin.php');
	}

	if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
		return true;
	} else {
		add_action( 'admin_notices', 'messageflow_missing_wc_notice' );
		return false;
	}
}

/**
 * Display a message advising WooCommerce is required
 */
function messageflow_missing_wc_notice() {
	$class = 'notice notice-error';
	$message = __( 'MessageFlow requires WooCommerce plugin to be installed and active!', 'messageflow' );

	printf(
		'<div class="%1$s"><p>%2$s</p></div>',
		esc_attr( $class ),
		esc_html( $message ),
	);
}

/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-messageflow-activator.php
 */
function activate_messageflow() {
	require_once MESSAGEFLOW_PLUGIN_PATH . 'includes/class-messageflow-activator.php';
	messageflow_Activator::activate();
}

/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/class-messageflow-deactivator.php
 */
function deactivate_messageflow() {
	require_once MESSAGEFLOW_PLUGIN_PATH . 'includes/class-messageflow-deactivator.php';
	messageflow_Deactivator::deactivate();
}

register_activation_hook( __FILE__, 'activate_messageflow' );
register_deactivation_hook( __FILE__, 'deactivate_messageflow' );

/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require MESSAGEFLOW_PLUGIN_PATH . 'includes/class-messageflow.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 run_messageflow() {

	if ( messageflow_check_requirements() ) {
		$plugin = new messageflow();
		$plugin->run();
	}


}
run_messageflow();
