register(new \CannaIQ_Menus_Product_Grid_Widget()); $widgets_manager->register(new \CannaIQ_Menus_Single_Product_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; } } // Initialize Plugin function cannaiq_menus() { return CannaIQ_Menus_Plugin::instance(); } cannaiq_menus();