<?php

/**
 * Plugin Name: Page Visit Counter Analytics
 * Plugin URI: https://pluginstack.dev
 * Description: Privacy-first WordPress analytics with real-time visitor tracking, page stats, heatmaps, UTM campaigns, user journeys, and smart goals.
 * Version: 3.1.0
 * Author: PluginStackDev
 * Author URI: https://pluginstack.dev
 * License: GPL-2.0+
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: page-visit-counter-analytics
 * Domain Path: /languages
 * Requires at least: 5.5
 * Requires PHP: 7.4
 *
 */
defined( 'ABSPATH' ) || exit;
if ( !function_exists( 'pvca_fs' ) ) {
    // Create a helper function for easy SDK access.
    function pvca_fs() {
        global $pvca_fs;
        if ( !isset( $pvca_fs ) ) {
            // Include Freemius SDK.
            require_once __DIR__ . '/lib/freemius/start.php';
            $pvca_fs = fs_dynamic_init( array(
                'id'              => '19102',
                'slug'            => 'page-visit-counter-analytics',
                'premium_slug'    => 'page-visit-counter-analytics-pro',
                'type'            => 'plugin',
                'public_key'      => 'pk_6035b315b1c4c03ca29a269d57151',
                'is_premium'      => false,
                'premium_suffix'  => '(Pro)',
                'has_addons'      => false,
                'has_paid_plans'  => true,
                'has_affiliation' => 'selected',
                'menu'            => array(
                    'slug'       => 'pagevico-dashboard',
                    'first-path' => 'admin.php?page=pagevico-dashboard',
                ),
                'is_live'         => true,
            ) );
        }
        return $pvca_fs;
    }

    // Init Freemius.
    pvca_fs();
    // Signal that SDK was initiated.
    do_action( 'pvca_fs_loaded' );
    // Load configuration
    require_once plugin_dir_path( __FILE__ ) . 'includes/config.php';
    // Load the plugin
    require_once PageVICO_PLUGIN_DIR . 'loader.php';
    // pvca_fs()->add_action('after_uninstall', 'pvca_fs_uninstall_cleanup');
}
/* Show a small promotional notice for PluginStack bundle. */
if ( !function_exists( 'pvca_pluginstack_promo_notice' ) ) {
    function pvca_pluginstack_promo_notice() {
        $dismissed = get_option( 'pvca_pluginstack_promo_dismissed' );
        if ( $dismissed ) {
            return;
        }
        ?>
		<div class="notice pvca-promo-notice" style="border-left-color:#6c47ff;padding:8px 12px;display:flex;align-items:center;gap:10px;">
			<span style="font-size:18px;">⚡</span>
			<p style="margin:0;font-size:13px;">
				<strong>Enjoying this plugin?</strong> Get the <a href="https://pluginstack.dev/?utm_source=page-visit-counter-analytics&utm_medium=admin_notice&utm_campaign=pluginstack_bundle" target="_blank" rel="noopener noreferrer" style="color:#6c47ff;font-weight:600;">PluginStack Bundle</a> — AI, WooCommerce, Gravity Forms, Analytics &amp; more. All current + upcoming plugins. <strong>One-time payment, no subscription.</strong>
				<a href="<?php 
        echo esc_url( wp_nonce_url( add_query_arg( 'pvca_dismiss_promo', '1' ), 'pvca_dismiss_promo' ) );
        ?>" style="margin-left:10px;color:#999;font-size:12px;text-decoration:none;"><?php 
        esc_html_e( 'Dismiss', 'page-visit-counter-analytics' );
        ?></a>
			</p>
		</div>
		<?php 
    }

    add_action( 'admin_notices', 'pvca_pluginstack_promo_notice' );
}
/* Handle dismiss action for PluginStack promo notice. */
if ( !function_exists( 'pvca_handle_promo_dismiss' ) ) {
    function pvca_handle_promo_dismiss() {
        if ( isset( $_GET['pvca_dismiss_promo'] ) && check_admin_referer( 'pvca_dismiss_promo' ) ) {
            update_option( 'pvca_pluginstack_promo_dismissed', true );
            wp_safe_redirect( remove_query_arg( array('pvca_dismiss_promo', '_wpnonce') ) );
            exit;
        }
    }

    add_action( 'admin_init', 'pvca_handle_promo_dismiss' );
}