<?php

/**
 * Plugin Name: Atomic Slider
 * Description: Atomic Slider Addons for Elementor: It offers a drag-and-drop builder, modern design, mobile responsiveness and more. Start now!
 * Plugin URI:  https://wpcaliph.com/atomic-slider/
 * Version:     1.0.4
 * Author:      WP Caliph
 * Author URI:  https://wpcaliph.com/
 * Text Domain: atomic-slider
 * Domain Path: /languages
 * License:     GPLv3
 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
 *
 * Requires Plugins: elementor
 * Elementor tested up to: 3.33.6
 * 
 * 
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
    // Exit if accessed directly.
}
if ( function_exists( 'as_fs' ) ) {
    as_fs()->set_basename( false, __FILE__ );
} else {
    /**
     * DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE
     * `function_exists` CALL ABOVE TO PROPERLY WORK.
     */
    if ( !function_exists( 'as_fs' ) ) {
        // ... Freemius integration snippet ...
        // Create a helper function for easy SDK access.
        function as_fs() {
            global $as_fs;
            if ( !isset( $as_fs ) ) {
                // Include Freemius SDK.
                require_once dirname( __FILE__ ) . '/freemius/start.php';
                $as_fs = fs_dynamic_init( array(
                    'id'             => '20865',
                    'slug'           => 'atomic-slider',
                    'premium_slug'   => 'atomic-slider-pro',
                    'type'           => 'plugin',
                    'public_key'     => 'pk_f68efb777fde17fa924bc570505e3',
                    'is_premium'     => false,
                    'premium_suffix' => 'Pro',
                    'has_addons'     => false,
                    'has_paid_plans' => true,
                    'menu'           => array(
                        'slug' => 'atomic-slider',
                    ),
                    'is_live'        => true,
                ) );
            }
            return $as_fs;
        }

        // Init Freemius.
        as_fs();
        // Signal that SDK was initiated.
        do_action( 'as_fs_loaded' );
    }
    // ... Your plugin's main file logic ...
    /**
     * Addon Version
     */
    define( 'ATOMSL_VER', '1.0.4' );
    function atomicslider_plugins_loaded() {
        if ( !did_action( 'elementor/loaded' ) ) {
            add_action( 'admin_notices', 'atomicslider_fail_load' );
            return;
        }
        // Load plugin file
        require_once __DIR__ . '/includes/plugin.php';
        // Helper function here
        require_once dirname( __FILE__ ) . '/includes/helper.php';
        require_once dirname( __FILE__ ) . '/includes/utils.php';
        require_once dirname( __FILE__ ) . '/includes/admin.php';
        // Run the plugin
        \AtomicSlider\Plugin::instance();
    }

    add_action( 'plugins_loaded', 'atomicslider_plugins_loaded' );
    /**
     * Check Elementor installed and activated correctly
     */
    function atomicslider_fail_load() {
        $screen = get_current_screen();
        if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
            return;
        }
        $plugin = 'elementor/elementor.php';
        if ( atomicslider_is_elementor_installed() ) {
            if ( !current_user_can( 'activate_plugins' ) ) {
                return;
            }
            $activation_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
            $admin_message = '<p>' . esc_html__( 'Oho! Atomic Slider not working because you need to activate the Elementor plugin first.', 'atomic-slider' ) . '</p>';
            $admin_message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, esc_html__( 'Activate Elementor', 'atomic-slider' ) ) . '</p>';
        } else {
            if ( !current_user_can( 'install_plugins' ) ) {
                return;
            }
            $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' );
            $admin_message = '<p>' . esc_html__( 'Oho! Atomic Slider not working because you need to install the Elementor plugin', 'atomic-slider' ) . '</p>';
            $admin_message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, esc_html__( 'Install Elementor', 'atomic-slider' ) ) . '</p>';
        }
        echo '<div class="error">' . wp_kses_post( $admin_message ) . '</div>';
    }

    /**
     * Check the elementor installed or not
     */
    if ( !function_exists( 'atomicslider_is_elementor_installed' ) ) {
        function atomicslider_is_elementor_installed() {
            $file_path = 'elementor/elementor.php';
            $installed_plugins = get_plugins();
            return isset( $installed_plugins[$file_path] );
        }

    }
}