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(); ?>