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()); } /** * 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'); // Migrate old settings if they exist $old_crawlsy_token = get_option('crawlsy_api_token'); $old_dutchie_token = get_option('dutchie_api_token'); if (!get_option('cannaiq_api_token')) { if ($old_crawlsy_token) { update_option('cannaiq_api_token', $old_crawlsy_token); } elseif ($old_dutchie_token) { update_option('cannaiq_api_token', $old_dutchie_token); } } } /** * Admin Page */ public function admin_page() { ?>
Version by CannaIQ
Display real-time cannabis menus with data updated daily from CannaIQ.
| 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 |
If you have Elementor installed, you can use the CannaIQ widgets:
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();