<?php

/*
Plugin Name: eCommerce Addon for Elementor
Plugin URI: https://nicheaddons.com/demos/ecommerce
Description: eCommerce Addon covers all the must-needed elements for creating a perfect eCommerce website using Elementor Page Builder. 20+ Unique & Basic Elementor widget covers all of the eCommerce elements.
Author: NicheAddons
Author URI: https://nicheaddons.com/
Version: 1.4
Text Domain: ecommerce-addon
*/
include_once ABSPATH . 'wp-admin/includes/plugin.php';
// Pro Codes

if ( !function_exists( 'naeca_fs' ) ) {
    // Create a helper function for easy SDK access.
    function naeca_fs()
    {
        global  $naeca_fs ;
        
        if ( !isset( $naeca_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/freemius/start.php';
            $naeca_fs = fs_dynamic_init( array(
                'id'             => '7880',
                'slug'           => 'ecommerce-addon',
                'premium_slug'   => '',
                'type'           => 'plugin',
                'public_key'     => 'pk_bdc5419670fc332714a0a629ddd8c',
                'is_premium'     => false,
                'premium_suffix' => '',
                'has_addons'     => false,
                'has_paid_plans' => true,
                'trial'          => array(
                'days'               => 7,
                'is_require_payment' => true,
            ),
                'menu'           => array(
                'slug'           => 'naeca_admin_page',
                'override_exact' => true,
                'support'        => false,
                'parent'         => array(
                'slug' => 'naeca_admin_page',
            ),
            ),
                'is_live'        => true,
            ) );
        }
        
        return $naeca_fs;
    }
    
    // Init Freemius.
    naeca_fs();
    // Signal that SDK was initiated.
    do_action( 'naeca_fs_loaded' );
    function naeca_fs_settings_url()
    {
        return admin_url( 'admin.php?page=naeca_admin_page' );
    }
    
    naeca_fs()->add_filter( 'connect_url', 'naeca_fs_settings_url' );
    naeca_fs()->add_filter( 'after_skip_url', 'naeca_fs_settings_url' );
    naeca_fs()->add_filter( 'after_connect_url', 'naeca_fs_settings_url' );
    naeca_fs()->add_filter( 'after_pending_connect_url', 'naeca_fs_settings_url' );
}

/**
* Enqueue Files for BackEnd
*/

if ( !function_exists( 'naeca_admin_scripts_styles' ) ) {
    function naeca_admin_scripts_styles()
    {
        wp_enqueue_style( 'naeca-admin-styles', plugins_url( '/', __FILE__ ) . 'assets/css/admin-styles.css', true );
    }
    
    add_action( 'admin_enqueue_scripts', 'naeca_admin_scripts_styles' );
}

// Admin Pages
require_once plugin_dir_path( __FILE__ ) . '/elementor/naeca-admin-page.php';
require_once plugin_dir_path( __FILE__ ) . '/elementor/naeca-admin-sub-page.php';
require_once plugin_dir_path( __FILE__ ) . '/elementor/naeca-admin-basic-fields.php';
require_once plugin_dir_path( __FILE__ ) . '/elementor/naeca-admin-pro-fields.php';
add_action( 'admin_init', 'naeca_bw_settings_init' );
add_action( 'admin_init', 'naeca_uw_settings_init' );

if ( !function_exists( 'naeca_admin_menu' ) ) {
    add_action( 'admin_menu', 'naeca_admin_menu' );
    function naeca_admin_menu()
    {
        add_menu_page(
            'eCommerce Addon',
            'eCommerce Addon',
            'manage_options',
            'naeca_admin_page',
            'naeca_admin_page',
            'dashicons-carrot',
            80
        );
        add_submenu_page(
            'naeca_admin_page',
            'Enable & Disable',
            'Enable & Disable',
            'manage_options',
            'naeca_admin_sub_page',
            'naeca_admin_sub_page'
        );
    }

}

// is_premium
// ABSPATH
if ( !function_exists( 'naecommerce_block_direct_access' ) ) {
    function naecommerce_block_direct_access()
    {
        if ( !defined( 'ABSPATH' ) ) {
            exit( 'Forbidden' );
        }
    }

}
// Initial File
// Only for free users
if ( naeca_fs()->is_free_plan() ) {
    if ( is_plugin_active( 'elementor/elementor.php' ) && is_plugin_active( 'ecommerce-addon/ecommerce-addon.php' ) ) {
        if ( file_exists( plugin_dir_path( __FILE__ ) . '/elementor/em-setup.php' ) ) {
            require_once plugin_dir_path( __FILE__ ) . '/elementor/em-setup.php';
        }
    }
}
// is_premium
// Development Purpose
require_once plugin_dir_path( __FILE__ ) . '/elementor/em-setup.php';
// Plugin language

if ( !function_exists( 'naecommerce_plugin_language_setup' ) ) {
    function naecommerce_plugin_language_setup()
    {
        load_plugin_textdomain( 'ecommerce-addon', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    }
    
    add_action( 'init', 'naecommerce_plugin_language_setup' );
}

// Check if Elementor installed and activated

if ( !function_exists( 'naecommerce_load_plugin' ) ) {
    function naecommerce_load_plugin()
    {
        
        if ( !did_action( 'elementor/loaded' ) ) {
            add_action( 'admin_notices', 'admin_notice_missing_main_plugin' );
            return;
        }
    
    }
    
    add_action( 'plugins_loaded', 'naecommerce_load_plugin' );
}

// Warning when the site doesn't have Elementor installed or activated.
if ( !function_exists( 'admin_notice_missing_main_plugin' ) ) {
    function admin_notice_missing_main_plugin()
    {
        if ( isset( $_GET['activate'] ) ) {
            unset( $_GET['activate'] );
        }
        $message = sprintf(
            /* translators: 1: Plugin name 2: Elementor */
            esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'ecommerce-addon' ),
            '<strong>' . esc_html__( 'eCommerce Addon', 'ecommerce-addon' ) . '</strong>',
            '<strong>' . esc_html__( 'Elementor', 'ecommerce-addon' ) . '</strong>'
        );
        printf( '<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message );
    }

}
// Both Free and Pro activated
if ( is_plugin_active( 'ecommerce-addon/ecommerce-addon.php' ) && is_plugin_active( 'ecommerce-addon-pro/ecommerce-addon.php' ) ) {
    add_action( 'admin_notices', 'admin_notice_deactivate_free' );
}
// Warning when the site have Both Free and Pro activated.
if ( !function_exists( 'admin_notice_deactivate_free' ) ) {
    function admin_notice_deactivate_free()
    {
        if ( isset( $_GET['activate'] ) ) {
            unset( $_GET['activate'] );
        }
        $message = sprintf(
            /* translators: 1: Plugin name */
            esc_html__( 'Please deactivate the free version of "%1$s".', 'ecommerce-addon' ),
            '<strong>' . esc_html__( 'eCommerce Addon', 'ecommerce-addon' ) . '</strong>'
        );
        printf( '<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message );
    }

}
// Enable & Dissable Notice
add_action( 'admin_notices', 'admin_notice_enable_dissable' );
if ( !function_exists( 'admin_notice_enable_dissable' ) ) {
    function admin_notice_enable_dissable()
    {
        
        if ( isset( $_GET['settings-updated'] ) ) {
            $message = sprintf( esc_html__( 'Widgets Settings Saved.', 'ecommerce-addon' ) );
            printf( '<div class="notice notice-success is-dismissible"><p>%1$s</p></div>', $message );
        }
    
    }

}
// is_premium
// Enqueue Files for Elementor Editor
if ( is_plugin_active( 'elementor/elementor.php' ) ) {
    // Css Enqueue
    add_action( 'elementor/editor/before_enqueue_scripts', function () {
        wp_enqueue_style(
            'naecommerce-ele-editor-linea',
            plugins_url( '/', __FILE__ ) . 'assets/css/linea.min.css',
            [],
            '1.0.0'
        );
        wp_enqueue_style(
            'naecommerce-ele-editor-themify',
            plugins_url( '/', __FILE__ ) . 'assets/css/themify-icons.min.css',
            [],
            '1.0.0'
        );
        wp_enqueue_style(
            'naecommerce-ele-editor-icofont',
            plugins_url( '/', __FILE__ ) . 'assets/css/icofont.min.css',
            [],
            '1.0.1'
        );
    } );
}
// Enqueue Files for FrontEnd

if ( !function_exists( 'naecommerce_scripts_styles' ) ) {
    function naecommerce_scripts_styles()
    {
        // Styles
        wp_enqueue_style(
            'niche-frame',
            plugins_url( '/', __FILE__ ) . 'assets/css/niche-frame.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'font-awesome',
            plugins_url( '/', __FILE__ ) . 'assets/css/font-awesome.min.css',
            array(),
            '4.7.0',
            'all'
        );
        wp_enqueue_style(
            'aos',
            plugins_url( '/', __FILE__ ) . 'assets/css/aos.min.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'all',
            plugins_url( '/', __FILE__ ) . 'assets/css/all.min.css',
            array(),
            '5.15.2',
            'all'
        );
        wp_enqueue_style(
            'themify-icons',
            plugins_url( '/', __FILE__ ) . 'assets/css/themify-icons.min.css',
            array(),
            '1.0.0',
            'all'
        );
        wp_enqueue_style(
            'linea',
            plugins_url( '/', __FILE__ ) . 'assets/css/linea.min.css',
            array(),
            '1.0.0',
            'all'
        );
        wp_enqueue_style(
            'icofont',
            plugins_url( '/', __FILE__ ) . 'assets/css/icofont.min.css',
            array(),
            '1.0.1',
            'all'
        );
        wp_enqueue_style(
            'CustomScrollbar',
            plugins_url( '/', __FILE__ ) . 'assets/css/jquery.mCustomScrollbar.min.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'magnific-popup',
            plugins_url( '/', __FILE__ ) . 'assets/css/magnific-popup.min.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'time-circles',
            plugins_url( '/', __FILE__ ) . 'assets/css/time-circles.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'owl-carousel',
            plugins_url( '/', __FILE__ ) . 'assets/css/owl.carousel.min.css',
            array(),
            '2.3.4',
            'all'
        );
        wp_enqueue_style(
            'multiscroll',
            plugins_url( '/', __FILE__ ) . 'assets/css/jquery.multiscroll.min.css',
            array(),
            '0.2.2',
            'all'
        );
        wp_enqueue_style(
            'slick-theme',
            plugins_url( '/', __FILE__ ) . 'assets/css/slick-theme.min.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'slick',
            plugins_url( '/', __FILE__ ) . 'assets/css/slick.min.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'naecommerce-styles',
            plugins_url( '/', __FILE__ ) . 'assets/css/styles.css',
            array(),
            '1.0',
            'all'
        );
        wp_enqueue_style(
            'naecommerce-responsive',
            plugins_url( '/', __FILE__ ) . 'assets/css/responsive.css',
            array(),
            '1.0',
            'all'
        );
        // Scripts
        wp_enqueue_script(
            'waypoints',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.waypoints.min.js',
            array( 'jquery' ),
            '4.0.1',
            true
        );
        wp_enqueue_script(
            'imagesloaded',
            plugins_url( '/', __FILE__ ) . 'assets/js/imagesloaded.pkgd.min.js',
            array( 'jquery' ),
            '4.1.4',
            true
        );
        wp_enqueue_script(
            'html5shiv',
            plugins_url( '/', __FILE__ ) . 'assets/js/html5shiv.min.js',
            array( 'jquery' ),
            '3.7.3',
            true
        );
        wp_enqueue_script(
            'circle-progress',
            plugins_url( '/', __FILE__ ) . 'assets/js/circle-progress.min.js',
            array( 'jquery' ),
            '1.2.2',
            true
        );
        wp_enqueue_script(
            'wow',
            plugins_url( '/', __FILE__ ) . 'assets/js/wow.min.js',
            array( 'jquery' ),
            '1.0',
            true
        );
        wp_enqueue_script(
            'mCustomScrollbar',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.mCustomScrollbar.min.js',
            array( 'jquery' ),
            '3.1.5',
            true
        );
        wp_enqueue_script(
            'owl-carousel',
            plugins_url( '/', __FILE__ ) . 'assets/js/owl.carousel.min.js',
            array( 'jquery' ),
            '2.3.4',
            true
        );
        wp_enqueue_script(
            'slick',
            plugins_url( '/', __FILE__ ) . 'assets/js/slick.min.js',
            array( 'jquery' ),
            '1.9.0',
            true
        );
        wp_enqueue_script(
            'countdown',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.countdown.min.js',
            array( 'jquery' ),
            '1.6.2',
            true
        );
        wp_enqueue_script(
            'counterup',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.counterup.min.js',
            array( 'jquery' ),
            '1.0',
            true
        );
        wp_enqueue_script(
            'magnific-popup',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.magnific-popup.min.js',
            array( 'jquery' ),
            '1.1.0',
            true
        );
        wp_enqueue_script(
            'time-circles',
            plugins_url( '/', __FILE__ ) . 'assets/js/time-circles.js',
            array( 'jquery' ),
            '1.0',
            true
        );
        wp_enqueue_script(
            'matchheight',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.matchHeight.min.js',
            array( 'jquery' ),
            '0.7.2',
            true
        );
        wp_enqueue_script(
            'easing',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.easing.min.js',
            array( 'jquery' ),
            '1.4.1',
            true
        );
        wp_enqueue_script(
            'multiscroll',
            plugins_url( '/', __FILE__ ) . 'assets/js/jquery.multiscroll.min.js',
            array( 'jquery' ),
            '0.2.2',
            true
        );
        wp_enqueue_script(
            'isotope',
            plugins_url( '/', __FILE__ ) . 'assets/js/isotope.min.js',
            array( 'jquery' ),
            '3.0.6',
            true
        );
        wp_enqueue_script(
            'packery-mode',
            plugins_url( '/', __FILE__ ) . 'assets/js/packery-mode.pkgd.min.js',
            array( 'jquery' ),
            '2.1.2',
            true
        );
        wp_enqueue_script(
            'naecommerce-scripts',
            plugins_url( '/', __FILE__ ) . 'assets/js/scripts.js',
            array( 'jquery' ),
            '1.0',
            true
        );
    }
    
    add_action( 'wp_enqueue_scripts', 'naecommerce_scripts_styles' );
}
