Files
cannaiq/wordpress-plugin/dutchie-analytics/dutchie-analytics.php
2025-11-28 19:45:44 -07:00

131 lines
4.2 KiB
PHP

<?php
/**
* Plugin Name: Dispensary Analytics
* Plugin URI: https://creationshop.io
* Description: Display Arizona dispensary product data, brands, and specials with beautiful Elementor widgets and shortcodes
* Version: 1.0.2
* Author: Creationshop LLC
* Author URI: creationshop.io
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: dutchie-analytics
* Requires at least: 5.0
* Requires PHP: 7.4
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
define('DUTCHIE_ANALYTICS_VERSION', '1.0.2');
define('DUTCHIE_ANALYTICS_PATH', plugin_dir_path(__FILE__));
define('DUTCHIE_ANALYTICS_URL', plugin_dir_url(__FILE__));
// Autoloader
spl_autoload_register(function ($class) {
$prefix = 'DutchieAnalytics\\';
$base_dir = DUTCHIE_ANALYTICS_PATH . 'includes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
// Initialize plugin
function dutchie_analytics_init() {
// Load API Client
require_once DUTCHIE_ANALYTICS_PATH . 'includes/API_Client.php';
// Load Shortcodes
require_once DUTCHIE_ANALYTICS_PATH . 'includes/Shortcodes.php';
new DutchieAnalytics\Shortcodes();
// Load Admin Settings
if (is_admin()) {
require_once DUTCHIE_ANALYTICS_PATH . 'includes/Admin_Settings.php';
new DutchieAnalytics\Admin_Settings();
}
// Register Elementor Widgets
add_action('elementor/widgets/register', function($widgets_manager) {
require_once DUTCHIE_ANALYTICS_PATH . 'includes/elementor/Products_Grid_Widget.php';
require_once DUTCHIE_ANALYTICS_PATH . 'includes/elementor/Products_Carousel_Widget.php';
require_once DUTCHIE_ANALYTICS_PATH . 'includes/elementor/Stores_List_Widget.php';
require_once DUTCHIE_ANALYTICS_PATH . 'includes/elementor/Brands_List_Widget.php';
require_once DUTCHIE_ANALYTICS_PATH . 'includes/elementor/Specials_Widget.php';
$widgets_manager->register(new \DutchieAnalytics\Elementor\Products_Grid_Widget());
$widgets_manager->register(new \DutchieAnalytics\Elementor\Products_Carousel_Widget());
$widgets_manager->register(new \DutchieAnalytics\Elementor\Stores_List_Widget());
$widgets_manager->register(new \DutchieAnalytics\Elementor\Brands_List_Widget());
$widgets_manager->register(new \DutchieAnalytics\Elementor\Specials_Widget());
});
// Register Elementor Widget Category
add_action('elementor/elements/categories_registered', function($elements_manager) {
$elements_manager->add_category(
'dutchie-analytics',
[
'title' => __('Dutchie Analytics', 'dutchie-analytics'),
'icon' => 'fa fa-plug',
]
);
});
}
add_action('plugins_loaded', 'dutchie_analytics_init');
// Enqueue styles and scripts
function dutchie_analytics_enqueue_assets() {
wp_enqueue_style(
'dutchie-analytics-styles',
DUTCHIE_ANALYTICS_URL . 'assets/css/dutchie-analytics.css',
[],
DUTCHIE_ANALYTICS_VERSION
);
wp_enqueue_script(
'dutchie-analytics-scripts',
DUTCHIE_ANALYTICS_URL . 'assets/js/dutchie-analytics.js',
['jquery'],
DUTCHIE_ANALYTICS_VERSION,
true
);
// Enqueue Swiper for carousels
wp_enqueue_style(
'swiper-css',
'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css',
[],
'11.0.0'
);
wp_enqueue_script(
'swiper-js',
'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js',
[],
'11.0.0',
true
);
}
add_action('wp_enqueue_scripts', 'dutchie_analytics_enqueue_assets');
// Activation hook
register_activation_hook(__FILE__, function() {
// Set default options
add_option('dutchie_analytics_api_url', 'http://localhost:3010/api');
add_option('dutchie_analytics_api_token', '');
});
// Deactivation hook
register_deactivation_hook(__FILE__, function() {
// Cleanup if needed
});