add_category( 'cannaiq', [ 'title' => __('CannaIQ', 'cannaiq-menus'), 'icon' => 'fa fa-cannabis', ] ); } public function init() { // Initialize plugin load_plugin_textdomain('cannaiq-menus', false, dirname(plugin_basename(__FILE__)) . '/languages'); // Load Elementor Dynamic Tags (if Elementor is active) if (did_action('elementor/loaded')) { require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/dynamic-tags.php'; } // Register shortcodes - primary CannaIQ shortcodes add_shortcode('cannaiq_products', [$this, 'products_shortcode']); add_shortcode('cannaiq_product', [$this, 'single_product_shortcode']); // DEPRECATED: Legacy shortcode alias for backward compatibility only add_shortcode('crawlsy_products', [$this, 'products_shortcode']); add_shortcode('crawlsy_product', [$this, 'single_product_shortcode']); } /** * Register Elementor Widgets */ public function register_elementor_widgets($widgets_manager) { require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/product-grid.php'; require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/single-product.php'; require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/brand-grid.php'; require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/category-list.php'; require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/specials-grid.php'; require_once CANNAIQ_MENUS_PLUGIN_DIR . 'widgets/product-loop.php'; $widgets_manager->register(new \CannaIQ_Menus_Product_Grid_Widget()); $widgets_manager->register(new \CannaIQ_Menus_Single_Product_Widget()); $widgets_manager->register(new \CannaIQ_Menus_Brand_Grid_Widget()); $widgets_manager->register(new \CannaIQ_Menus_Category_List_Widget()); $widgets_manager->register(new \CannaIQ_Menus_Specials_Grid_Widget()); $widgets_manager->register(new \CannaIQ_Product_Loop_Widget()); } /** * Enqueue Scripts and Styles */ public function enqueue_scripts() { wp_enqueue_style( 'cannaiq-menus-styles', CANNAIQ_MENUS_PLUGIN_URL . 'assets/css/cannaiq-menus.css', [], CANNAIQ_MENUS_VERSION ); wp_enqueue_script( 'cannaiq-menus-script', CANNAIQ_MENUS_PLUGIN_URL . 'assets/js/cannaiq-menus.js', ['jquery'], CANNAIQ_MENUS_VERSION, true ); } /** * Add Admin Menu */ public function add_admin_menu() { add_menu_page( 'CannaIQ Menus', 'CannaIQ Menus', 'manage_options', 'cannaiq-menus', [$this, 'admin_page'], 'dashicons-products', 30 ); } /** * Register Plugin Settings */ public function register_settings() { register_setting('cannaiq_menus_settings', 'cannaiq_api_token'); // MIGRATION: Auto-migrate API token from old Crawlsy plugin $old_crawlsy_token = get_option('crawlsy_api_token'); if (!get_option('cannaiq_api_token') && $old_crawlsy_token) { update_option('cannaiq_api_token', $old_crawlsy_token); } } /** * Admin Page */ public function admin_page() { ?>

CannaIQ Menus Settings

Version by CannaIQ

Display real-time cannabis menus with data updated daily from CannaIQ.

Your authentication token from the CannaIQ admin dashboard. The token includes your store configuration.


Test Connection


Usage

Shortcodes

Shortcode Description
[cannaiq_products] Display a grid of products. Options: category_id, limit, columns, in_stock
[cannaiq_product id="123"] Display a single product by ID

Elementor Widgets

If you have Elementor installed, you can use the CannaIQ widgets:

'', 'limit' => 12, 'columns' => 3, 'in_stock' => 'true' ], $atts); $products = $this->fetch_products($atts); if (!$products) { return '

No products found.

'; } ob_start(); include CANNAIQ_MENUS_PLUGIN_DIR . 'templates/product-grid.php'; return ob_get_clean(); } /** * Single Product Shortcode */ public function single_product_shortcode($atts) { $atts = shortcode_atts([ 'id' => 0 ], $atts); if (!$atts['id']) { return '

Product ID required.

'; } $product = $this->fetch_product($atts['id']); if (!$product) { return '

Product not found.

'; } ob_start(); include CANNAIQ_MENUS_PLUGIN_DIR . 'templates/single-product.php'; return ob_get_clean(); } /** * Fetch Products from API */ public function fetch_products($args = []) { $api_token = get_option('cannaiq_api_token'); if (!$api_token) { return false; } $query_args = http_build_query($args); $url = CANNAIQ_MENUS_API_URL . '/products?' . $query_args; $response = wp_remote_get($url, [ 'headers' => [ 'X-API-Key' => $api_token ], 'timeout' => 30 ]); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data['products'] ?? false; } /** * Fetch Single Product from API */ public function fetch_product($id) { $api_token = get_option('cannaiq_api_token'); if (!$api_token) { return false; } $url = CANNAIQ_MENUS_API_URL . '/products/' . intval($id); $response = wp_remote_get($url, [ 'headers' => [ 'X-API-Key' => $api_token ], 'timeout' => 30 ]); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data['product'] ?? false; } /** * Fetch Categories from API */ public function fetch_categories($args = []) { $api_token = get_option('cannaiq_api_token'); if (!$api_token) { return false; } $query_args = http_build_query($args); $url = CANNAIQ_MENUS_API_URL . '/categories' . ($query_args ? '?' . $query_args : ''); $response = wp_remote_get($url, [ 'headers' => [ 'X-API-Key' => $api_token ], 'timeout' => 30 ]); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data['categories'] ?? false; } /** * Fetch Brands from API */ public function fetch_brands($args = []) { $api_token = get_option('cannaiq_api_token'); if (!$api_token) { return false; } $query_args = http_build_query($args); $url = CANNAIQ_MENUS_API_URL . '/brands' . ($query_args ? '?' . $query_args : ''); $response = wp_remote_get($url, [ 'headers' => [ 'X-API-Key' => $api_token ], 'timeout' => 30 ]); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data['brands'] ?? false; } /** * Fetch Specials/Deals from API */ public function fetch_specials($args = []) { $api_token = get_option('cannaiq_api_token'); if (!$api_token) { return false; } $query_args = http_build_query($args); $url = CANNAIQ_MENUS_API_URL . '/specials' . ($query_args ? '?' . $query_args : ''); $response = wp_remote_get($url, [ 'headers' => [ 'X-API-Key' => $api_token ], 'timeout' => 30 ]); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data['products'] ?? false; } /** * Get categories as options for Elementor select control * Returns cached results for performance */ public function get_category_options() { $cache_key = 'cannaiq_category_options'; $cached = get_transient($cache_key); if ($cached !== false) { return $cached; } $categories = $this->fetch_categories(); $options = ['' => __('All Categories', 'cannaiq-menus')]; if ($categories) { foreach ($categories as $cat) { $name = $cat['type'] ?? $cat['name'] ?? ''; if ($name) { $options[$name] = ucwords(str_replace('_', ' ', $name)); } } } set_transient($cache_key, $options, 5 * MINUTE_IN_SECONDS); return $options; } /** * Get brands as options for Elementor select control * Returns cached results for performance */ public function get_brand_options() { $cache_key = 'cannaiq_brand_options'; $cached = get_transient($cache_key); if ($cached !== false) { return $cached; } $brands = $this->fetch_brands(['limit' => 200]); $options = ['' => __('All Brands', 'cannaiq-menus')]; if ($brands) { foreach ($brands as $brand) { $name = $brand['brand'] ?? $brand['brand_name'] ?? ''; if ($name) { $options[$name] = $name; } } } set_transient($cache_key, $options, 5 * MINUTE_IN_SECONDS); return $options; } } // Initialize Plugin function cannaiq_menus() { return CannaIQ_Menus_Plugin::instance(); } cannaiq_menus();