uuid = $parser->get_uuid(); $this->layout = get_option('hare_layout', 'grid'); $this->items_count = intval(get_option('hare_items_count', 12)); } public function fetch($module) { if (empty($this->uuid)) { return ''; } $cache_key = 'hare_' . md5($this->uuid . '_' . $module . '_' . $this->layout); $cached = get_transient($cache_key); if (false !== $cached) { return $cached; } $url = HARE_API_BASE . '/' . urlencode($this->uuid) . '/' . urlencode($module); $response = wp_remote_get($url, array( 'timeout' => 15, 'headers' => array( 'Accept' => 'application/json', ), )); if (is_wp_error($response)) { return ''; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (!is_array($data) || empty($data)) { return ''; } $items = array_slice($data, 0, $this->items_count); $html = $this->render($items, $module); set_transient($cache_key, $html, 5 * MINUTE_IN_SECONDS); return $html; } private function render($items, $module) { $layout_class = 'hare-' . $this->layout; $module_class = 'hare-module-' . sanitize_html_class($module); $html = '
' . $description . '
'; if (!empty($price)) { $html .= '' . $price . '
'; } $html .= ''; $html .= '