register_display(); } } public function get_settings($raw = false) { $stored = get_option(self::OPTION_KEY, array()); if (!is_array($stored)) { $stored = array(); } return $raw ? (array_merge(array( 'enabled' => 'yes', 'modal_title' => '', ), $stored)) : self::fill_i18n_defaults(array_merge(array( 'enabled' => 'yes', 'modal_title' => '', ), $stored)); } private static function i18n_labels() { return array( 'modal_title' => __('Checkout errors', 'ai-eshop-optimizer'), ); } private static function fill_i18n_defaults(array $s) { if (!did_action('init')) { return $s; } foreach (self::i18n_labels() as $k => $v) { if (!isset($s[$k]) || '' === trim((string) $s[$k])) { $s[$k] = $v; } } return $s; } public function ajax_save() { AIEO_DMM::verify_ajax_request(); update_option(self::OPTION_KEY, array( 'enabled' => !empty($_POST['enabled']) ? 'yes' : 'no', 'modal_title' => isset($_POST['modal_title']) ? sanitize_text_field(wp_unslash($_POST['modal_title'])) : '', ), false); wp_send_json_success(array('message' => __('Checkout modal settings saved.', 'ai-eshop-optimizer'))); } public function render_subtab() { $s = $this->get_settings(); $form_id = 'aieo-card-checkout-modal-notice-dialog-form'; list($open, $close) = AIEO_DMM_UI::card(array( 'anchor' => 'checkout-modal-notice-dialog', 'title' => __('Notice dialog', 'ai-eshop-optimizer'), 'description' => __('Hoists WooCommerce checkout error / info / success notices into an accessibility-first modal dialog (focus-trapped, ESC-closable). Catches both classic and block checkout error flows. Suppresses the default inline notice render so customers don\'t see the same message twice.', 'ai-eshop-optimizer'), 'footer' => class_exists('\Rooster\Admin\States') ? \Rooster\Admin\States::save_button($form_id) : '', )); echo $open; $raw = $this->get_settings(true); $rows = \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-cm-enabled', 'label' => __('Enable', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::toggle('enabled', $s['enabled'] === 'yes', array('id' => 'aieo-cm-enabled', 'hidden' => false)), )); $rows .= \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-cm-title', 'label' => __('Modal title', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('modal_title', (string) $raw['modal_title'], array('id' => 'aieo-cm-title', 'medium' => true, 'placeholder' => (string) self::i18n_labels()['modal_title'])), )); echo AIEO_DMM_UI::card_form('aieo_dmm_checkout_modal_save', $this->get_id(), $form_id, '
' . $rows . '
'); echo $close; } }