settings->breakpoints(); } catch (\Throwable $e) { $all_breakpoints = null; } } if (!is_array($all_breakpoints)) { $all_breakpoints = class_exists('\Zadex\Settings') ? \Zadex\Settings::default_breakpoints() : []; } $bp_widths = []; foreach ($all_breakpoints as $bp_key => $bp) { if ($bp_key === 'desktop' || !is_array($bp) || empty($bp['enabled']) || ($bp['direction'] ?? 'max') !== 'max') { continue; } $bp_widths[$bp_key] = (int) ($bp['value'] ?? 0); } $slides = ['desktop' => max(1, (int) ($settings['slides_to_show'] ?? 3))]; foreach (array_keys($bp_widths) as $bp_key) { $v = $settings['slides_to_show@' . $bp_key] ?? null; if (is_numeric($v) && (int) $v > 0) { $slides[$bp_key] = (int) $v; } } $gap_value = $settings['gap'] ?? ['size' => 20, 'unit' => 'px']; $gap = is_array($gap_value) ? (int) ($gap_value['size'] ?? 0) : (int) $gap_value; $arrows = !empty($settings['arrows']); $dots = !empty($settings['dots']); $autoplay = !empty($settings['autoplay']) ? max(500, (int) ($settings['autoplay_speed'] ?? 4000)) : 0; $attrs = preg_replace('/class="/', 'class="zx-slider ', $attrs, 1); $attrs .= ' data-zx-slides="' . esc_attr((string) wp_json_encode($slides)) . '"'; $attrs .= ' data-zx-breakpoints="' . esc_attr((string) wp_json_encode((object) $bp_widths)) . '"'; $attrs .= ' data-zx-scroll="' . esc_attr((string) max(1, (int) ($settings['slides_to_scroll'] ?? 1))) . '" data-zx-gap="' . esc_attr((string) $gap) . '" data-zx-speed="' . esc_attr((string) max(0, (int) ($settings['speed'] ?? 400))) . '"'; $attrs .= ' data-zx-loop="' . esc_attr(!empty($settings['loop']) ? 'true' : 'false') . '" data-zx-autoplay="' . esc_attr((string) ($autoplay ?: 'false')) . '" data-zx-pause="true"'; $attrs .= ' data-zx-arrows="' . esc_attr($arrows ? 'true' : 'false') . '" data-zx-dots="' . esc_attr($dots ? 'true' : 'false') . '"'; $attrs .= ' style="--zx-spv:' . esc_attr((string) $slides['desktop']) . ';--zx-gap:' . esc_attr((string) $gap) . 'px"'; if ($loop['config']) { $attrs .= ' data-zx-loop-config="' . esc_attr((string) wp_json_encode($loop['config'])) . '"'; } $zx_html = '
'; if ($loop['notice'] !== '') { $zx_html .= '
' . esc_html($loop['notice']) . '
'; } elseif ($loop['ready']) { $zx_html .= ''; $zx_html .= $loop['empty']; if ($arrows) { $zx_html .= ''; $zx_html .= ''; } if ($dots) { $zx_html .= ''; } } $zx_html .= '
'; echo wp_kses($zx_html, \Zadex\Frontend\Kses::allowed_html()) . "\n";