saef_get_default_mode(); $atts = shortcode_atts( array( 'mode' => $default_mode, 'button_icon' => '', ), $atts, 'allergen_exclusion_filter' ); $mode = sanitize_key($atts['mode']); if (! in_array($mode, array('simple', 'block', 'compact'), true)) { $mode = 'simple'; } $button_icon_attr = sanitize_key($atts['button_icon']); if ($button_icon_attr === 'yes' || $button_icon_attr === 'no') { $show_icon = ($button_icon_attr === 'yes'); } else { $show_icon = ($mode === 'compact'); } $placeholder = $this->saef_get_text('placeholder', __('Write down an ingredient (e.g., milk, soy...)', 'allergen-exclusion-filter')); $button_text = $this->saef_get_text('button_text', __('FIND SAFE PRODUCTS', 'allergen-exclusion-filter')); $initial_message = $this->saef_get_text('initial_message', __('Select ingredients to filter the catalog.', 'allergen-exclusion-filter')); $block_title = $this->saef_get_text('block_title', __('Find products free of your allergens', 'allergen-exclusion-filter')); $block_description = $this->saef_get_text('block_description', __('Enter the ingredients you wish to exclude from your diet.', 'allergen-exclusion-filter')); // (ES) Ancho para simple/block (default 100%). // (EN) Width for simple/block (default 100%). $width_pct = $this->saef_get_search_bar_width(); $width_style = ' style="max-width: ' . esc_attr($width_pct) . '%; margin-left: auto; margin-right: auto;"'; $bg_color = $this->saef_get_background_color(); $bg_style = ''; if (! empty($bg_color)) { $bg_style = ' style="background: ' . esc_attr($bg_color) . ';"'; } $button_color = $this->saef_get_button_color(); $button_style = ''; if (! empty($button_color)) { $button_style = ' style="background: ' . esc_attr($button_color) . ' !important;"'; } ob_start(); if ($mode === 'simple') { $this->saef_render_simple($placeholder, $button_text, $width_style, $button_style, $show_icon); } elseif ($mode === 'compact') { // (ES) El modo compact calcula su propio ancho internamente. // (EN) Compact mode computes its own width internally. $this->saef_render_compact($placeholder, $button_text, $button_style, $show_icon); } else { $this->saef_render_block($placeholder, $button_text, $initial_message, $block_title, $block_description, $bg_style, $button_style, $width_style, $show_icon); } return ob_get_clean(); } private function saef_get_default_mode() { if (class_exists('SAEF_Settings')) { $mode = SAEF_Settings::saef_get_option('display_mode', 'simple'); return in_array($mode, array('simple', 'block'), true) ? $mode : 'simple'; } return 'simple'; } private function saef_get_text($key, $default) { if (class_exists('SAEF_Settings')) { $value = SAEF_Settings::saef_get_option($key, ''); if (! empty($value)) { return $value; } } return $default; } private function saef_get_background_color() { if (class_exists('SAEF_Settings')) { $color = SAEF_Settings::saef_get_option('background_color', ''); return sanitize_hex_color($color); } return ''; } private function saef_get_button_color() { if (class_exists('SAEF_Settings')) { $color = SAEF_Settings::saef_get_option('button_color', ''); return sanitize_hex_color($color); } return ''; } private function saef_get_search_bar_width() { if (class_exists('SAEF_Settings')) { $width = (int) SAEF_Settings::saef_get_option('search_bar_width', 100); return max(30, min(100, $width)); } return 100; } /** * (ES) Obtiene el ancho de la barra en modo compact (20-100, default 50). * (EN) Gets the compact mode bar width (20-100, default 50). * * @return int Porcentaje de ancho. */ private function saef_get_compact_bar_width() { if (class_exists('SAEF_Settings')) { $width = (int) SAEF_Settings::saef_get_option('compact_bar_width', 300); return max(150, min(600, $width)); } return 300; } private function saef_get_search_icon() { return ''; } /** * (ES) Renderiza el modo SIMPLE: solo formulario (sin mensaje inicial). * Usa CLASES (no IDs) para soportar múltiples instancias. * (EN) Renders the SIMPLE mode: just the form (no initial message). * Uses CLASSES (not IDs) to support multiple instances. */ private function saef_render_simple($placeholder, $button_text, $width_style, $button_style, $show_icon) { ?>
>
0) ? get_permalink($shop_page_id) : home_url('/'); // (ES) Ancho configurable para modo compact (default 50%). // margin-left: 0 para alinear a la izquierda en el header. // margin-right: 12px para separación del elemento siguiente. // (EN) Configurable width for compact mode (default 50%). // margin-left: 0 to align left in the header. // margin-right: 12px for separation from the next element. $compact_width = $this->saef_get_compact_bar_width(); $width_style = ' style="width: ' . esc_attr($compact_width) . 'px; max-width: 100%; margin-left: 0; margin-right: 12px;"'; ?>
data-saef-shop-url="">
>
>