<?php
/**
 * Plugin Name: Ionic Ecommerce
 * Plugin URI: http://ionicecommerce.com/
 * Description: A wordpress Plugin for ionicecommerce.com  app template  
 * Version: 3.0
 * Author: vectorcoder
 * Author URI: http://vectorcoder.com
 */
header('Access-Control-Allow-Origin:  *');
header("Cache-Control: no-cache, must-revalidate");
header('Access-Control-Allow-Methods:  POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Origin, Authorization');
global $woocommerce , $wpdb;
if (!defined('ABSPATH')) {exit;}
define( 'IONICVC_ABSPATH', dirname( __FILE__ ) . '/' );

define( 'IONIC_APP_BANNERS_SETTINGS', $wpdb->prefix . 'ionic_ecommerce_banner_settings' ); 
define( 'IONIC_SETTINGS_DATA', $wpdb->prefix . 'ionic_ecommerce_data' );
define( 'IONIC_NOTIFICATION_DEVICES', $wpdb->prefix . 'ionic_ecommerce_notification_devices' );
define( 'IONIC_ALL_NOTIFICATION', $wpdb->prefix . 'ionic_ecommerce_all_notification' );
update_option ('ionic_ecommerce_plugin_active','active');
update_option ('ionic_ecommerce_purchase_code','valid');

if(get_option('ionic_ecommerce_purchase_code') != "" && get_option('ionic_ecommerce_plugin_active') == 'active'){
	if ( ! class_exists( 'ReduxFramework' ) && file_exists( plugin_dir_path(__FILE__) .'/ionic_framework/framework.php' ) ) {
	   require_once('ionic_framework/framework.php' );
	}
	
	if ( ! isset( $redux_demo ) && file_exists( plugin_dir_path(__FILE__) .'/functions/ionic_ecommerce_app_setting_config.php' ) ) {
	   require_once( 'functions/ionic_ecommerce_app_setting_config.php' );
	}
	add_action( 'admin_menu', 'ionic_ecommerce_add_app_admin_menu' );
}else {
	add_action( 'admin_menu', 'ionic_ecommerce_add_app_admin_menu_activation' );	
}

require_once( 'functions/ionic_ecommerce_misc_function.php' );
require_once( 'functions/ionic_ecommerce_insert_data_function.php' );
require_once( 'functions/ionic_ecommerce_app_banner_setting.php' );
require_once( 'functions/ionic_ecommerce_api_controller_function.php' );
require_once( 'functions/ionic_ecommerce_geo_fencing_function.php' );
require_once( 'functions/ionic_ecommerce_notification_function.php' );

require_once __DIR__ .'/assets/src/Templater.php';
use JO\Module\Templater\Templater;

add_action ( 'admin_notices', 'ionic_ecommerce_admin_notices' );
register_activation_hook(__FILE__,'ionic_ecommerce_add_ionic_ecommerce_data');
add_filter( 'json_api_controllers', 'custom_appusers_controllers' );
add_filter( 'json_api_appusers_controller_path', 'define_custom_appusers_controllers_path' );
add_filter( 'json_api_appsettings_controller_path', 'define_custom_appsettings_controllers_path' );
add_action( 'wp_head', 'ionic_ecommerce_my_app_hook');
add_action('plugins_loaded', 'ionic_ecommerce_load_checkout_template');
add_action( 'woocommerce_coupon_options_save', 'save_coupon_notification_ionicecommerce');

add_action( 'show_user_profile', 'my_show_extra_profile_fields_for_wcvendor' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields_for_wcvendor' );

add_action( 'personal_options_update', 'my_save_extra_profile_fields_for_wcvendor' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields_for_wcvendor' );

function ionic_ecommerce_load_checkout_template()
{	
	$my_templater = new Templater( array('plugin_directory' => plugin_dir_path(__FILE__), 'plugin_prefix' => 'plugin_prefix_', 'plugin_template_directory' => 'templates',));
    $my_templater->add(array('page' => array('template-mobile-checkout.php' => 'Checkout Custom Template',),))->register();
} ?>