feat(wordpress): Add new Elementor widgets and dynamic selectors v1.6.0
New Widgets: - Brand Grid: Display brands in a grid with product counts - Category List: Show categories in grid/list/pills layouts - Specials Grid: Display products on sale with discount badges Enhanced Product Grid Widget: - Dynamic category dropdown (fetches from API) - Dynamic brand dropdown (fetches from API) - "On Special Only" toggle filter New Plugin Methods: - fetch_categories() - Get categories from API - fetch_brands() - Get brands from API - fetch_specials() - Get products on sale - get_category_options() - Cached options for Elementor - get_brand_options() - Cached options for Elementor 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: CannaIQ Menus
|
||||
* Plugin URI: https://cannaiq.co
|
||||
* Description: Display cannabis product menus from CannaIQ with Elementor integration. Real-time menu data updated daily.
|
||||
* Version: 1.5.4
|
||||
* Version: 1.6.0
|
||||
* Author: CannaIQ
|
||||
* Author URI: https://cannaiq.co
|
||||
* License: GPL v2 or later
|
||||
@@ -15,7 +15,7 @@ if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
define('CANNAIQ_MENUS_VERSION', '1.5.4');
|
||||
define('CANNAIQ_MENUS_VERSION', '1.6.0');
|
||||
define('CANNAIQ_MENUS_API_URL', 'https://cannaiq.co/api/v1');
|
||||
define('CANNAIQ_MENUS_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('CANNAIQ_MENUS_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
@@ -62,9 +62,15 @@ class CannaIQ_Menus_Plugin {
|
||||
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';
|
||||
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,6 +398,152 @@ class CannaIQ_Menus_Plugin {
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user