8) {
wp_send_json_error(array('message' => __('Visible thumbnails must be between 2 and 8.', 'ai-eshop-optimizer')));
}
$s['visible_thumbs'] = $n;
}
if (isset($_POST['thumbs_position'])) {
$v = sanitize_key(wp_unslash($_POST['thumbs_position']));
$s['thumbs_position'] = in_array($v, array('left', 'right', 'bottom', 'top'), true) ? $v : 'left';
}
if (isset($_POST['arrow_style'])) {
$v = sanitize_key(wp_unslash($_POST['arrow_style']));
$s['arrow_style'] = in_array($v, array('long', 'chevron'), true) ? $v : 'long';
}
if (isset($_POST['thumbs_height_mode'])) {
$mode = sanitize_key(wp_unslash($_POST['thumbs_height_mode']));
$s['thumbs_height_mode'] = in_array($mode, array('count', 'fill'), true) ? $mode : 'count';
}
foreach (array('lb_thumbnails', 'lb_dots', 'lb_counter', 'lb_share', 'lb_autoplay', 'lb_autoplay_pause_on_hover', 'lb_loop', 'lb_close_on_scroll', 'lb_thumb_equal', 'lb_thumb_border') as $b) {
if (isset($_POST[$b])) { $s[$b] = ('1' === (string) wp_unslash($_POST[$b])); }
}
if (isset($_POST['lb_thumb_border_colour'])) {
$c = sanitize_hex_color(wp_unslash($_POST['lb_thumb_border_colour']));
$s['lb_thumb_border_colour'] = $c ? $c : '#ffffff';
}
if (isset($_POST['lb_thumb_size'])) { $s['lb_thumb_size'] = max(48, min(200, (int) $_POST['lb_thumb_size'])); }
if (isset($_POST['lb_thumb_radius'])) { $s['lb_thumb_radius'] = max(0, min(24, (int) $_POST['lb_thumb_radius'])); }
if (isset($_POST['lb_autoplay_delay'])) { $s['lb_autoplay_delay'] = max(1000, min(20000, (int) $_POST['lb_autoplay_delay'])); }
if (isset($_POST['lb_backdrop_opacity'])) {
$s['lb_backdrop_opacity'] = max(0, min(1, (float) $_POST['lb_backdrop_opacity']));
}
if (isset($_POST['lb_arrow_style'])) {
$v = sanitize_key(wp_unslash($_POST['lb_arrow_style']));
$s['lb_arrow_style'] = in_array($v, array('square', 'round', 'minimal', 'long', 'chevron'), true) ? $v : 'square';
}
if (isset($_POST['lb_backdrop_style'])) {
$v = sanitize_key(wp_unslash($_POST['lb_backdrop_style']));
$s['lb_backdrop_style'] = in_array($v, array('dark', 'light', 'glass'), true) ? $v : 'dark';
}
if (isset($_POST['lb_arrow_colour'])) {
$c = sanitize_hex_color(wp_unslash($_POST['lb_arrow_colour']));
$s['lb_arrow_colour'] = $c ? $c : '#333333';
}
if (isset($_POST['ao_mode'])) {
$v = sanitize_key(wp_unslash($_POST['ao_mode']));
$s['ao_mode'] = in_array($v, array('disabled', 'always', 'listing', 'internal'), true) ? $v : 'disabled';
}
if (isset($_POST['ao_slide'])) { $s['ao_slide'] = max(0, min(50, (int) $_POST['ao_slide'])); }
if (isset($_POST['ao_mobile'])) { $s['ao_mobile'] = ('1' === (string) wp_unslash($_POST['ao_mobile'])); }
if (isset($_POST['ao_breakpoint'])) { $s['ao_breakpoint'] = max(0, min(4000, (int) $_POST['ao_breakpoint'])); }
if (isset($_POST['ao_listing_patterns'])) {
$lines = array();
foreach (preg_split('/\R/', (string) wp_unslash($_POST['ao_listing_patterns'])) as $line) {
$line = trim(wp_strip_all_tags($line));
if ('' !== $line) { $lines[] = $line; }
}
$s['ao_listing_patterns'] = implode("\n", array_unique($lines));
}
update_option(self::OPTION_KEY, $s, false);
do_action('aieo_purge_page_cache');
wp_send_json_success(array('message' => __('Gallery settings saved.', 'ai-eshop-optimizer')));
}
private static function note($text, $tone) {
if (class_exists('\Rooster\Admin\Ui')) {
return \Rooster\Admin\Ui::notice(esc_html($text), $tone, array('inline' => true));
}
$colour = 'destructive' === $tone ? '#b91c1c' : '#996800';
return '
' . esc_html($text) . '
';
}
public function render_subtab() {
$s = self::settings();
$theme_owns = class_exists('AIEO_Theme_Adapters')
&& 'theme' === AIEO_Theme_Adapters::effective_mode('gallery');
$compat_url = admin_url('admin.php?page=' . AIEO_DMM::MENU_SLUG . '&dmm_tab=theme_compat');
$compat_link = ' ' . esc_html__('Theme compatibility', 'ai-eshop-optimizer') . ' →';
$id_of = static function ($name) {
return 'aieo-gl-' . str_replace('_', '-', $name);
};
$row = static function ($name, $label, $control, $help = '', $extra = array()) use ($id_of) {
$field = array('id' => $id_of($name), 'label' => $label, 'control' => $control) + $extra;
if ('' !== $help) { $field['help'] = $help; }
return \Rooster\Admin\Ui::field_row($field);
};
$switch = static function ($name, $text, $hidden_label = false) use ($s, $id_of) {
return \Rooster\Admin\Ui::toggle($name, !empty($s[$name]), array('id' => $id_of($name), 'label' => $text, 'label_hidden' => $hidden_label));
};
$number = static function ($name, $min, $max, $step, $width, $unit = '') use ($s, $id_of) {
$q = ((float) $s[$name] - $min) / $step;
$opts = array('id' => $id_of($name), 'type' => 'number', $width => true, 'min' => $min, 'max' => $max, 'step' => abs($q - round($q)) < 1e-6 ? $step : 'any');
if ('' !== $unit) { $opts['unit'] = $unit; }
return \Rooster\Admin\Ui::input($name, (string) $s[$name], $opts);
};
$select = static function ($name, $options, $extra = array()) use ($s, $id_of) {
return \Rooster\Admin\Ui::select($name, $options, (string) $s[$name], array('id' => $id_of($name)) + $extra);
};
$colour = static function ($name, $fallback) use ($s, $id_of) {
return \Rooster\Admin\Fields::color($name, (string) $s[$name], array('id' => $id_of($name), 'default' => $fallback));
};
$guide = static function ($text, $link) {
return \Rooster\Admin\Guidance::text($text, 'guidance', array('html' => esc_html($text) . $link));
};
$card = static function ($anchor, $icon, $title, $col, $before, $fields, $extra = array(), $fold = '') {
$form_id = 'aieo-card-' . $anchor . '-form';
list($open, $close) = AIEO_DMM_UI::card(array(
'anchor' => $anchor,
'icon' => $icon,
'title' => $title,
'col' => $col,
'footer' => \Rooster\Admin\States::save_button($form_id),
) + $extra);
echo $open;
echo $before;
echo AIEO_DMM_UI::card_form('aieo_dmm_gallery_layout_save', 'gallery_layout', $form_id, '' . $fields . '
' . $fold);
echo $close;
};
$band = function_exists('rooster_admin_band_open');
if ($band) {
rooster_admin_band_open(array('cols' => 2));
}
$before = $guide(__('The design of the single-product image gallery when Rooster One renders it: a vertical thumbnail strip beside the main image, with arrows once there are more thumbnails than fit. Who renders the gallery — your theme or Rooster One — is decided per surface under Theme compatibility.', 'ai-eshop-optimizer'), $compat_link);
if ($theme_owns) {
$before .= self::note(__('Your theme currently renders the gallery, so these settings are not in effect. Switch the "Product image gallery" surface to Rooster One under Theme compatibility to use them.', 'ai-eshop-optimizer'), 'warning');
}
$theme_sets = AIEO_Gallery_Lightbox_Frontend::theme_sets_gallery();
$set_by = $theme_sets ? array('reason' => __('Set by RoosterX (Appearance → Rooster X → Design).', 'ai-eshop-optimizer')) : array();
$fields = $row('thumbs_position', __('Thumbnail position', 'ai-eshop-optimizer'), $select('thumbs_position', array(
'left' => __('Left of the image', 'ai-eshop-optimizer'),
'right' => __('Right of the image', 'ai-eshop-optimizer'),
'bottom' => __('Below the image', 'ai-eshop-optimizer'),
'top' => __('Above the image', 'ai-eshop-optimizer'),
), array('disabled' => $theme_sets)), __('Where the thumbnail strip sits on computers. Phones keep it under the image unless it is above.', 'ai-eshop-optimizer'), $set_by);
$fields .= $row('arrow_style', __('Arrow style', 'ai-eshop-optimizer'), $select('arrow_style', array(
'long' => __('Long thin arrows', 'ai-eshop-optimizer'),
'chevron' => __('Chevrons', 'ai-eshop-optimizer'),
), array('disabled' => $theme_sets)), __('The arrows at the sides of the image and at the ends of the thumbnail strip. The lightbox takes the same when its own arrow style says so.', 'ai-eshop-optimizer'), $set_by);
$fields .= $row('thumbs_height_mode', __('Thumbnail strip height', 'ai-eshop-optimizer'), $select('thumbs_height_mode', array(
'count' => __('Fixed number of thumbnails', 'ai-eshop-optimizer'),
'fill' => __('Fill the image height', 'ai-eshop-optimizer'),
)), __('Fixed: a compact centred strip of N thumbnails. Fill: the strip spans the whole image, arrows pinned to its top and bottom edges. Either way the rest scroll — arrows, mouse wheel or swipe.', 'ai-eshop-optimizer'));
$fields .= $row('visible_thumbs', __('Visible thumbnails', 'ai-eshop-optimizer'), $number('visible_thumbs', 2, 8, 1, 'xs'), __('How many thumbnails the strip shows before the up/down arrows take over. Used with the fixed option. Applies on desktop; on mobile the thumbnails scroll in a row.', 'ai-eshop-optimizer'), array(
'attrs' => \Rooster\Admin\States::depends_attrs($id_of('thumbs_height_mode'), 'count' === $s['thumbs_height_mode'], array('value' => 'count')),
));
$card('gallery-layout-overview', 'image', __('Thumbnail strip and arrows', 'ai-eshop-optimizer'), 1, $before, $fields, array('description' => __('How the product gallery\'s thumbnails sit beside the main picture: how many show and how the strip scrolls.', 'ai-eshop-optimizer')));
$lb_owned = self::owns_lightbox();
$lb_support = current_theme_supports('wc-product-gallery-lightbox');
$before = $guide(__('Rooster One\'s fullscreen viewer, built on the PhotoSwipe engine WooCommerce already ships: a bottom filmstrip, pager dots, autoplay and your own skin. Who renders the fullscreen view is decided per surface under Theme compatibility — the gallery and the lightbox are independent, so the theme can lay out the page while Rooster One owns fullscreen.', 'ai-eshop-optimizer'), $compat_link);
if (!$lb_owned) {
$before .= self::note(__('The default viewer is currently in use, so these settings are not in effect. Switch the "Product image lightbox" surface to Rooster One under Theme compatibility to use them.', 'ai-eshop-optimizer'), 'warning');
} elseif (!$lb_support) {
$before .= self::note(__('Your theme does not declare WooCommerce lightbox support (wc-product-gallery-lightbox), so Rooster One stands down rather than changing how your theme\'s gallery behaves. Ask us before forcing it on.', 'ai-eshop-optimizer'), 'destructive');
}
$fields = $row('lb_thumbnails', __('Bottom filmstrip', 'ai-eshop-optimizer'), $switch('lb_thumbnails', __('Show a scrollable thumbnail strip along the bottom', 'ai-eshop-optimizer')));
$fields .= $row('lb_thumb_size', __('Filmstrip thumbnail height', 'ai-eshop-optimizer'), $number('lb_thumb_size', 48, 200, 4, 'xs', 'px'));
$fields .= $row('lb_dots', __('Pager dots', 'ai-eshop-optimizer'), $switch('lb_dots', __('One dot per image, above the filmstrip', 'ai-eshop-optimizer')));
$fields .= $row('lb_counter', __('Image counter', 'ai-eshop-optimizer'), $switch('lb_counter', __('"3 / 24" in the top-left corner', 'ai-eshop-optimizer')));
$fields .= $row('lb_share', __('Share button', 'ai-eshop-optimizer'), $switch('lb_share', __('Show the share control in the toolbar', 'ai-eshop-optimizer')));
$fields .= $row('lb_arrow_style', __('Arrow style', 'ai-eshop-optimizer'), $select('lb_arrow_style', array(
'square' => __('Solid square', 'ai-eshop-optimizer'),
'round' => __('Solid circle', 'ai-eshop-optimizer'),
'minimal' => __('Minimal chevron', 'ai-eshop-optimizer'),
'long' => __('Long thin arrows, as the gallery', 'ai-eshop-optimizer'),
'chevron' => __('Chevrons, as the gallery', 'ai-eshop-optimizer'),
)));
$fields .= $row('lb_arrow_colour', __('Arrow colour', 'ai-eshop-optimizer'), $colour('lb_arrow_colour', '#333333'), __('Also used for the active dot and the active thumbnail outline.', 'ai-eshop-optimizer'));
$fields .= $row('lb_backdrop_style', __('Backdrop style', 'ai-eshop-optimizer'), $select('lb_backdrop_style', array(
'dark' => __('Dark', 'ai-eshop-optimizer'),
'light' => __('Light', 'ai-eshop-optimizer'),
'glass' => __('Frosted glass (blurs the page behind)', 'ai-eshop-optimizer'),
)));
$fields .= $row('lb_autoplay', __('Autoplay', 'ai-eshop-optimizer'), $switch('lb_autoplay', __('Advance to the next image automatically', 'ai-eshop-optimizer')));
$fields .= $row('lb_loop', __('Loop', 'ai-eshop-optimizer'), $switch('lb_loop', __('After the last image, continue from the first', 'ai-eshop-optimizer')));
$advanced = '';
$advanced .= $row('lb_thumb_radius', __('Thumbnail corner radius', 'ai-eshop-optimizer'), $number('lb_thumb_radius', 0, 24, 1, 'xs', 'px'), __('0 for square thumbnails. The active thumbnail is outlined in the arrow colour.', 'ai-eshop-optimizer'));
$advanced .= $row('lb_thumb_equal', __('Equal-size thumbnails', 'ai-eshop-optimizer'), $switch('lb_thumb_equal', __('Crop every thumbnail to a square of the height above, instead of keeping each image\'s own proportions', 'ai-eshop-optimizer')));
$advanced .= \Rooster\Admin\Ui::field_row(array(
'id' => $id_of('lb_thumb_border'),
'label' => __('Thumbnail border', 'ai-eshop-optimizer'),
'parts' => array(
array('label' => '', 'control' => $switch('lb_thumb_border', __('Thumbnail border', 'ai-eshop-optimizer'), true)),
array('label' => __('Colour', 'ai-eshop-optimizer'), 'control' => $colour('lb_thumb_border_colour', '#ffffff'), 'id' => $id_of('lb_thumb_border_colour')),
),
'help' => __('A border around every thumbnail. The active one still switches to the arrow colour.', 'ai-eshop-optimizer'),
));
$advanced .= $row('lb_backdrop_opacity', __('Backdrop opacity', 'ai-eshop-optimizer'), $number('lb_backdrop_opacity', 0, 1, 0.05, 'xs'), __('1 is fully opaque. With frosted glass, keep this high — the translucency comes from the glass itself.', 'ai-eshop-optimizer'));
$advanced .= $row('lb_autoplay_delay', __('Autoplay delay', 'ai-eshop-optimizer'), $number('lb_autoplay_delay', 1000, 20000, 500, 'short', 'ms'));
$advanced .= $row('lb_autoplay_pause_on_hover', __('Pause autoplay on hover', 'ai-eshop-optimizer'), $switch('lb_autoplay_pause_on_hover', __('On', 'ai-eshop-optimizer'), true));
$advanced .= $row('lb_close_on_scroll', __('Close on scroll', 'ai-eshop-optimizer'), $switch('lb_close_on_scroll', __('On', 'ai-eshop-optimizer'), true));
$fold = \Rooster\Admin\Ui::fold(__('Advanced', 'ai-eshop-optimizer'), '' . $advanced . '
');
$card('gallery-layout-lightbox', 'eye', __('Fullscreen lightbox', 'ai-eshop-optimizer'), 2, $before, $fields, array('description' => __('Settings for the full-screen view a shopper opens from a product picture, how it behaves and how it closes.', 'ai-eshop-optimizer')), $fold);
$fields = $row('ao_mode', __('When to open', 'ai-eshop-optimizer'), $select('ao_mode', array(
'disabled' => __('Disabled', 'ai-eshop-optimizer'),
'always' => __('Always, on every product page', 'ai-eshop-optimizer'),
'listing' => __('Only when arriving from a product listing', 'ai-eshop-optimizer'),
'internal' => __('Any internal page, but not organic or direct', 'ai-eshop-optimizer'),
)), __('"Always" also fires for organic and direct visitors, which affects bounce rate and LCP. "From a listing" matches the previous page against the patterns below.', 'ai-eshop-optimizer'));
$fields .= $row('ao_listing_patterns', __('Listing patterns', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::textarea('ao_listing_patterns', (string) $s['ao_listing_patterns'], array('id' => $id_of('ao_listing_patterns'), 'rows' => 3, 'code' => true)), __('One per line, matched as a substring of the referring page\'s path and query. Used with the listing mode only.', 'ai-eshop-optimizer'), array(
'attrs' => \Rooster\Admin\States::depends_attrs($id_of('ao_mode'), 'listing' === $s['ao_mode'], array('value' => 'listing')),
));
$fields .= $row('ao_slide', __('Start at image', 'ai-eshop-optimizer'), $number('ao_slide', 0, 50, 1, 'xs'), __('0 is the first image. Honoured by viewers that open from tagged links; WooCommerce\'s own trigger opens at the current slide.', 'ai-eshop-optimizer'));
$fields .= $row('ao_mobile', __('Open on mobile', 'ai-eshop-optimizer'), $switch('ao_mobile', __('On', 'ai-eshop-optimizer'), true));
$fields .= $row('ao_breakpoint', __('Mobile breakpoint', 'ai-eshop-optimizer'), $number('ao_breakpoint', 0, 4000, 1, 'xs', 'px'));
$card('gallery-layout-autoopen', 'door-open', __('Auto-open on arrival', 'ai-eshop-optimizer'), 1, '', $fields, array(
'description' => __('Open the product gallery\'s lightbox automatically when a visitor lands on a product page. Deliberately independent of who renders the fullscreen viewer: it opens whichever lightbox is active — Rooster One\'s or your theme\'s. The decision is made in the visitor\'s browser (referrer, screen size), so it works correctly under full-page caching.', 'ai-eshop-optimizer'),
));
if ($band) {
rooster_admin_band_close();
}
if ($band) {
rooster_admin_band_open(array('cols' => 2));
}
foreach ( array( 'variations_gallery', 'product_video' ) as $absorbed ) {
$mod = AIEO_DMM::instance()->get_module( $absorbed );
if ( $mod && method_exists( $mod, 'render_subtab' ) ) {
$mod->render_subtab();
}
}
if ($band) {
rooster_admin_band_close();
}
}
}