null, 'theme' => 'light', 'mode' => 'advanced', 'best_price_color' => '', 'best_quality_color' => '', 'best_cost_benefit_color' => '', 'template_id' => null, 'live_template_modules' => null ), $atts); $table_id = null; $template_id = $atts['template_id'] ? intval($atts['template_id']) : null; if (!empty($atts['id'])) { $table_id = intval($atts['id']); } else { $post_id = get_the_ID(); if ($post_id) { $table_id = get_post_meta($post_id, '_affl_associated_comparison_table', true); } if (empty($table_id)) { return __('No comparison table ID specified or associated.', 'affililabs'); } $table_id = intval($table_id); } if (!$template_id && $table_id) { $template_id = get_post_meta($table_id, '_affl_applied_template_id', true); $template_id = $template_id ? intval($template_id) : null; } try { $table_data = AFFLComparisonTableService::get_table_data($table_id); if (empty($table_data)) { return __('Comparison table data not found.', 'affililabs'); } } catch (Exception $e) { AFFL_LoggerService::log('Error fetching table data for shortcode ID ' . esc_html($table_id) . ': ' . esc_html($e->getMessage()), 'ERROR'); if (current_user_can('edit_posts')) { return sprintf( /* translators: %1$s: List ID, %2$s: Error details */ esc_html__('Error: Could not load List ID %1$s. It may have been deleted or is invalid. (Details: %2$s)', 'affililabs'), esc_html($table_id), esc_html($e->getMessage()) ); } return esc_html__('Error: Could not load the specified list.', 'affililabs'); } $live_template_modules = isset($atts['live_template_modules']) && is_array($atts['live_template_modules']) ? $atts['live_template_modules'] : null; return $this->render_comparison_table_html($table_data, $atts, $template_id, $live_template_modules); } private function render_comparison_table_html($table_data, $atts, $template_id = null, $live_template_modules = null) { if (empty($table_data['products'])) { return __('No products to display in the comparison table.', 'affililabs'); } $final_template_modules = null; if (is_array($live_template_modules) && !empty($live_template_modules)) { $final_template_modules = $live_template_modules; } elseif ($template_id) { $template_post = get_post($template_id); if ($template_post && $template_post->post_type === 'affl_template' && $template_post->post_status === 'publish') { $template_meta = get_post_meta($template_id, '_affl_template_data', true); if (is_array($template_meta) && !empty($template_meta)) { $final_template_modules = $template_meta; AFFL_LoggerService::debug('Using saved template structure for template ID ' . esc_html($template_id) . ': ' . esc_html(print_r($final_template_modules, true)), 'DEBUG'); } else { AFFL_LoggerService::log('Saved template meta _affl_template_data not found or not a non-empty array for template ID ' . esc_html($template_id), 'WARNING'); } } else { AFFL_LoggerService::log('Template post not found or not valid for template ID ' . esc_html($template_id), 'WARNING'); } } $default_modules = ['price', 'rating', 'criteria', 'buy_button']; $modules_to_render = is_array($final_template_modules) && !empty($final_template_modules) ? $final_template_modules : $default_modules; if ($live_template_modules !== null) { AFFL_LoggerService::debug('Preview Render - Live Modules Received by AJAX: ' . esc_html(print_r($live_template_modules, true)), 'DEBUG'); AFFL_LoggerService::debug('Preview Render - Template ID Received: ' . esc_html(print_r($template_id, true)), 'DEBUG'); AFFL_LoggerService::debug('Preview Render - Final Modules To Render: ' . esc_html(print_r($modules_to_render, true)), 'DEBUG'); } $theme = $atts['theme'] ?? 'light'; $mode = $atts['mode'] ?? 'advanced'; $best_price_color = $atts['best_price_color'] ?? ''; $best_quality_color = $atts['best_quality_color'] ?? ''; $best_cost_benefit_color = $atts['best_cost_benefit_color'] ?? ''; $themes = array('light', 'dark', 'modern-blue'); $modes = array('advanced', 'simple'); if (!in_array($theme, $themes)) { $theme = 'light'; } if (!in_array($mode, $modes)) { $mode = 'advanced'; } $theme_class = 'affl-comparison-table--theme-' . esc_attr($theme); $mode_class = 'affl-comparison-table--mode-' . esc_attr($mode); ob_start(); ?>
' . $marketplace_name_to_display . '
'); ?>