get_settings(); if (empty($s['enabled'])) { return; } add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); if (empty($s['use_shortcode'])) { add_action('woocommerce_single_product_summary', array($this, 'output'), 30); } } public function get_settings($raw = false) { $stored = get_option(self::OPTION_KEY, array()); if (!is_array($stored)) { $stored = array(); } $legacy = get_option('om_ppe_payment-logos', array()); if (!is_array($legacy)) { $legacy = array(); } $merged = array_merge(array( 'enabled' => false, 'logos' => isset($legacy['logos']) ? (string) $legacy['logos'] : '', 'title' => '', 'align' => isset($legacy['align']) ? (string) $legacy['align'] : 'flex-start', 'font_size' => isset($legacy['font_size']) ? (int) $legacy['font_size'] : 18, 'text_color' => isset($legacy['text_color']) ? (string) $legacy['text_color'] : '#212121', 'margin_top' => isset($legacy['margin_top']) ? (int) $legacy['margin_top'] : 20, 'margin_bottom' => isset($legacy['margin_bottom']) ? (int) $legacy['margin_bottom'] : 20, 'image_max_width' => isset($legacy['image_max_width']) ? (int) $legacy['image_max_width'] : 80, 'image_max_height' => isset($legacy['image_max_height']) ? (int) $legacy['image_max_height'] : 100, 'use_shortcode' => false, 'custom_class' => '', ), $stored); return $raw ? $merged : self::fill_i18n_defaults($merged); } private static function i18n_default() { return __('🔒 Safe & Secure Checkout', 'ai-eshop-optimizer'); } private static function fill_i18n_defaults(array $s) { if (!did_action('init')) { return $s; } if (!isset($s['title']) || '' === trim((string) $s['title'])) { $s['title'] = self::i18n_default(); } return $s; } public function ajax_save() { AIEO_DMM::verify_ajax_request(); update_option(self::OPTION_KEY, array( 'enabled' => !empty($_POST['enabled']), 'logos' => isset($_POST['logos']) ? sanitize_text_field(wp_unslash($_POST['logos'])) : '', 'title' => isset($_POST['title']) ? sanitize_text_field(wp_unslash($_POST['title'])) : '', 'align' => isset($_POST['align']) && in_array(sanitize_text_field( wp_unslash( $_POST['align'] ) ), array('flex-start','center','flex-end'), true) ? sanitize_text_field( wp_unslash( $_POST['align'] ) ) : 'flex-start', 'font_size' => max(10, min(50, isset($_POST['font_size']) ? (int) $_POST['font_size'] : 18)), 'text_color' => isset($_POST['text_color']) ? (sanitize_hex_color(wp_unslash($_POST['text_color'])) ?: '#212121') : '#212121', 'margin_top' => max(0, min(100, isset($_POST['margin_top']) ? (int) $_POST['margin_top'] : 20)), 'margin_bottom' => max(0, min(100, isset($_POST['margin_bottom']) ? (int) $_POST['margin_bottom'] : 20)), 'image_max_width' => max(20, min(200, isset($_POST['image_max_width']) ? (int) $_POST['image_max_width'] : 80)), 'image_max_height' => max(20, min(200, isset($_POST['image_max_height']) ? (int) $_POST['image_max_height'] : 100)), 'use_shortcode' => !empty($_POST['use_shortcode']), 'custom_class' => isset($_POST['custom_class']) ? sanitize_html_class(wp_unslash($_POST['custom_class'])) : '', ), false); wp_send_json_success(array('message' => __('Payment Logos settings saved.', 'ai-eshop-optimizer'))); } public function enqueue_styles() { if (!function_exists('is_product') || !is_product()) { return; } $version = defined('AIEO_VERSION') ? AIEO_VERSION : '1.0'; wp_enqueue_style( 'aieo-payment-logos', plugins_url('assets/css/product-display/payment-logos.css', AIEO_FILE), array(), $version ); $s = $this->get_settings(); $css = sprintf( '.om-ppe-payment-logos{' . '--om-ppe-pl-font-size:%dpx;' . '--om-ppe-pl-text-color:%s;' . '--om-ppe-pl-margin-top:%dpx;' . '--om-ppe-pl-margin-bottom:%dpx;' . '--om-ppe-pl-align:%s;' . '--om-ppe-pl-image-max-width:%dpx;' . '--om-ppe-pl-image-max-height:%dpx;' . '}', (int) $s['font_size'], esc_attr($s['text_color']), (int) $s['margin_top'], (int) $s['margin_bottom'], esc_attr($s['align']), (int) $s['image_max_width'], (int) $s['image_max_height'] ); wp_add_inline_style('aieo-payment-logos', $css); } public function is_active() { $s = $this->get_settings(); return !empty($s['enabled']); } public function output() { if (!$this->is_active()) { return; } static $rendered = false; if ($rendered) { return; } if (is_archive() || is_page()) { return; } $s = $this->get_settings(); if (!empty($s['use_shortcode'])) { return; } $rendered = true; echo wp_kses_post($this->get_html()); } public function shortcode_handler($atts = array()) { $s = $this->get_settings(); if (empty($s['enabled']) || empty($s['use_shortcode'])) { return ''; } if (!is_singular('product')) { if (current_user_can('manage_options')) { return '

' . esc_html__('Payment Logos shortcode can only be used on single product pages.', 'ai-eshop-optimizer') . '

'; } return ''; } return $this->get_html(); } private function get_html() { $s = $this->get_settings(); $logos = !empty($s['logos']) ? array_filter(array_map('absint', explode(',', (string) $s['logos']))) : array(); $custom_class = !empty($s['custom_class']) ? ' ' . esc_attr((string) $s['custom_class']) : ''; ob_start(); ?>
post_title : __('Payment method', 'ai-eshop-optimizer'); } echo wp_get_attachment_image($image_id, 'thumbnail', false, array( 'class' => 'om-ppe-payment-logo', 'alt' => $alt, 'loading' => 'lazy', )); endforeach; ?>
get_settings(); $form_id = 'aieo-card-payment-logos-overview-form'; list($open, $close) = AIEO_DMM_UI::card(array( 'anchor' => 'payment-logos-overview', 'title' => __('Payment icon layout', 'ai-eshop-optimizer'), 'description' => __('Show payment-method icons under the Add-to-Cart button on single product pages. Use the shortcode [aieo_payment_logos] for manual placement (toggle on below). The legacy [om_ppe_payment_logos] shortcode still works.', 'ai-eshop-optimizer'), 'footer' => class_exists('\Rooster\Admin\States') ? \Rooster\Admin\States::save_button($form_id) : '', )); echo $open; $px = static function ($name, $id, $value, $min, $max) { return \Rooster\Admin\Ui::input($name, (string) (int) $value, array('id' => $id, 'type' => 'number', 'xs' => true, 'unit' => 'px', 'min' => $min, 'max' => $max)); }; $rows = array( array( 'id' => 'aieo-pl-enabled', 'label' => __('Enable', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::toggle('enabled', !empty($s['enabled']), array('id' => 'aieo-pl-enabled', 'hidden' => false, 'label' => __('On', 'ai-eshop-optimizer'), 'label_hidden' => true)), ), array( 'id' => 'aieo-pl-logos', 'label' => __('Logos (comma-separated attachment IDs)', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('logos', (string) $s['logos'], array('id' => 'aieo-pl-logos', 'medium' => true, 'placeholder' => '123,456,789')), 'help' => __('Upload PNG/SVG icons via Media Library, copy the attachment IDs from the URL after clicking each, paste here separated by commas. Or use the legacy om-product-essentials gallery picker if it\'s still active.', 'ai-eshop-optimizer'), ), array( 'id' => 'aieo-pl-title', 'label' => __('Title text', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('title', (string) $s['title'], array('id' => 'aieo-pl-title', 'medium' => true, 'placeholder' => self::i18n_default())), ), array( 'id' => 'aieo-pl-align', 'label' => __('Alignment', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::select('align', array('flex-start' => __('Left', 'ai-eshop-optimizer'), 'center' => __('Center', 'ai-eshop-optimizer'), 'flex-end' => __('Right', 'ai-eshop-optimizer')), (string) $s['align'], array('id' => 'aieo-pl-align', 'short' => true)), ), array( 'id' => 'aieo-pl-font-size', 'label' => __('Title font size', 'ai-eshop-optimizer'), 'control' => $px('font_size', 'aieo-pl-font-size', $s['font_size'], 10, 50), ), array( 'id' => 'aieo-pl-text-color', 'label' => __('Text colour', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Fields::color('text_color', (string) $s['text_color'], array('id' => 'aieo-pl-text-color', 'default' => '#212121')), ), array( 'id' => 'aieo-pl-margin-top', 'label' => __('Margin top', 'ai-eshop-optimizer'), 'control' => $px('margin_top', 'aieo-pl-margin-top', $s['margin_top'], 0, 100), ), array( 'id' => 'aieo-pl-margin-bottom', 'label' => __('Margin bottom', 'ai-eshop-optimizer'), 'control' => $px('margin_bottom', 'aieo-pl-margin-bottom', $s['margin_bottom'], 0, 100), ), array( 'id' => 'aieo-pl-image-max-width', 'label' => __('Image max width', 'ai-eshop-optimizer'), 'control' => $px('image_max_width', 'aieo-pl-image-max-width', $s['image_max_width'], 20, 200), ), array( 'id' => 'aieo-pl-image-max-height', 'label' => __('Image max height', 'ai-eshop-optimizer'), 'control' => $px('image_max_height', 'aieo-pl-image-max-height', $s['image_max_height'], 20, 200), ), array( 'id' => 'aieo-pl-custom-class', 'label' => __('Custom CSS class', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('custom_class', (string) $s['custom_class'], array('id' => 'aieo-pl-custom-class', 'medium' => true, 'code' => true)), ), array( 'id' => 'aieo-pl-use-shortcode', 'label' => __('Use shortcode (manual placement)', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::toggle('use_shortcode', !empty($s['use_shortcode']), array('id' => 'aieo-pl-use-shortcode', 'hidden' => false, 'label' => __('Don\'t auto-insert; only render when [aieo_payment_logos] is used', 'ai-eshop-optimizer'))), ), ); $fields = '
'; foreach ($rows as $row) { $fields .= \Rooster\Admin\Ui::field_row($row); } $fields .= '
'; echo AIEO_DMM_UI::card_form('aieo_dmm_payment_logos_save', $this->get_id(), $form_id, $fields); echo $close; } }