settings_helper = $settings_helper; add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); add_action( 'admin_post_aaweb_ab_reset_defaults', array( $this, 'reset_defaults' ) ); } /** * Add settings page. * * @return void */ public function add_menu() { add_options_page( esc_html__( 'AAWEB Announcement Bar', 'aaweb-announcement-bar' ), esc_html__( 'AAWEB Announcement Bar', 'aaweb-announcement-bar' ), 'manage_options', 'aaweb-announcement-bar', array( $this, 'render_settings_page' ) ); } /** * Register settings. * * @return void */ public function register_settings() { register_setting( 'aaweb_ab_group', AAWEB_Announcement_Bar_Settings::OPTION_KEY, array( 'type' => 'array', 'sanitize_callback' => array( $this->settings_helper, 'sanitize' ), ) ); } /** * Reset all plugin settings to built-in defaults. * * @return void */ public function reset_defaults() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to reset these settings.', 'aaweb-announcement-bar' ) ); } check_admin_referer( 'aaweb_ab_reset_defaults' ); delete_option( AAWEB_Announcement_Bar_Settings::OPTION_KEY ); // Store a short-lived, user-specific success flag and redirect to a clean URL. // This prevents the reset notice from being repeated by later settings saves. set_transient( 'aaweb_ab_reset_notice_' . get_current_user_id(), '1', 60 ); $redirect_url = add_query_arg( 'page', 'aaweb-announcement-bar', admin_url( 'options-general.php' ) ); wp_safe_redirect( $redirect_url ); exit; } /** * Enqueue admin assets. * * @param string $hook Current hook. * @return void */ public function enqueue_admin_assets( $hook ) { if ( 'settings_page_aaweb-announcement-bar' !== $hook ) { return; } wp_enqueue_style( 'aaweb-ab-admin', AAWEB_AB_URL . 'assets/css/admin.css', array(), AAWEB_AB_VERSION . '-ui4' ); wp_enqueue_script( 'aaweb-ab-admin', AAWEB_AB_URL . 'assets/js/admin.js', array(), AAWEB_AB_VERSION . '-ui4', true ); wp_localize_script( 'aaweb-ab-admin', 'AAWEB_AB_ADMIN', array( 'defaults' => $this->settings_helper->defaults(), 'sections' => $this->reset_sections(), 'strings' => array( 'sectionReset' => __( 'Section reset to defaults. Click Save settings to apply.', 'aaweb-announcement-bar' ), ), ) ); } /** * Render settings page. * * @return void */ public function render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = $this->settings_helper->get(); $enabled_text = ! empty( $settings['enabled'] ) ? __( 'Enabled', 'aaweb-announcement-bar' ) : __( 'Disabled', 'aaweb-announcement-bar' ); $reset_notice_key = 'aaweb_ab_reset_notice_' . get_current_user_id(); $show_reset_notice = (bool) get_transient( $reset_notice_key ); if ( $show_reset_notice ) { delete_transient( $reset_notice_key ); } $reset_url = wp_nonce_url( add_query_arg( 'action', 'aaweb_ab_reset_defaults', admin_url( 'admin-post.php' ) ), 'aaweb_ab_reset_defaults' ); $reset_confirm = __( 'Are you sure you want to reset all Announcement Bar settings to their built-in defaults?', 'aaweb-announcement-bar' ); ?>
AA

AAWEB Plugin Suite

'aaweb-ab-top-save' ) ); ?>

section_heading( '✍', __( 'Content & message', 'aaweb-announcement-bar' ), __( 'Choose plain text or safe HTML and control the announcement copy.', 'aaweb-announcement-bar' ), 'content-all' ); ?> subsection_heading( __( 'Main message', 'aaweb-announcement-bar' ), 'content-main' ); ?>
checkbox_field( 'enabled', __( 'Enable announcement bar', 'aaweb-announcement-bar' ), $settings, __( 'Turn the frontend bar on or off.', 'aaweb-announcement-bar' ) ); ?> select_field( 'content_mode', __( 'Content mode', 'aaweb-announcement-bar' ), $settings, array( 'text' => __( 'Plain text', 'aaweb-announcement-bar' ), 'html' => __( 'Safe HTML', 'aaweb-announcement-bar' ) ) ); ?>
textarea_field( 'text', __( 'Text message', 'aaweb-announcement-bar' ), $settings, 4, __( 'Used when content mode is Plain text.', 'aaweb-announcement-bar' ) ); ?>
textarea_field( 'html_content', __( 'HTML content', 'aaweb-announcement-bar' ), $settings, 7, __( 'Used when content mode is Safe HTML. WordPress safe post HTML filtering is applied.', 'aaweb-announcement-bar' ) ); ?>
subsection_heading( __( 'Mobile message override', 'aaweb-announcement-bar' ), 'mobile' ); ?>
checkbox_field( 'mobile_text_enabled', __( 'Use a different message on mobile', 'aaweb-announcement-bar' ), $settings, __( 'Below 768px, replace the main message with this shorter mobile text.', 'aaweb-announcement-bar' ) ); ?>
textarea_field( 'mobile_text', __( 'Mobile text', 'aaweb-announcement-bar' ), $settings, 3, __( 'Plain text only. Leave empty to fall back to the main message.', 'aaweb-announcement-bar' ) ); ?>
section_heading( '🎟', __( 'Coupon / discount code', 'aaweb-announcement-bar' ), __( 'Show an existing discount code in the announcement bar so visitors can copy it with one click.', 'aaweb-announcement-bar' ), 'coupon' ); ?>

checkbox_field( 'coupon_enabled', __( 'Enable click-to-copy coupon', 'aaweb-announcement-bar' ), $settings, __( 'Show the coupon code as a clickable copy control in the announcement bar.', 'aaweb-announcement-bar' ) ); ?> text_field( 'coupon_code', __( 'Discount code', 'aaweb-announcement-bar' ), $settings, 'text', 'SAVE10', __( 'Enter the exact coupon code the visitor should copy.', 'aaweb-announcement-bar' ) ); ?> text_field( 'coupon_label', __( 'Label before code', 'aaweb-announcement-bar' ), $settings, 'text', __( 'Code', 'aaweb-announcement-bar' ) ); ?>
section_heading( '↗', __( 'CTA button', 'aaweb-announcement-bar' ), __( 'Style the call-to-action independently from the text so both stay aligned and clickable.', 'aaweb-announcement-bar' ), 'button-all' ); ?> subsection_heading( __( 'Button content & behavior', 'aaweb-announcement-bar' ), 'button-main' ); ?>
checkbox_field( 'button_enabled', __( 'Enable CTA button', 'aaweb-announcement-bar' ), $settings ); ?> select_field( 'link_target', __( 'Open link', 'aaweb-announcement-bar' ), $settings, array( '_self' => __( 'Same tab', 'aaweb-announcement-bar' ), '_blank' => __( 'New tab', 'aaweb-announcement-bar' ) ) ); ?> text_field( 'link_url', __( 'Button URL', 'aaweb-announcement-bar' ), $settings, 'url', 'https://example.com' ); ?> text_field( 'link_text', __( 'Button text', 'aaweb-announcement-bar' ), $settings ); ?> select_field( 'button_position', __( 'Button position', 'aaweb-announcement-bar' ), $settings, array( 'after' => __( 'After content', 'aaweb-announcement-bar' ), 'before' => __( 'Before content', 'aaweb-announcement-bar' ) ) ); ?> select_field( 'button_visibility', __( 'Button visibility', 'aaweb-announcement-bar' ), $settings, array( 'all' => __( 'All devices', 'aaweb-announcement-bar' ), 'desktop' => __( 'Desktop only', 'aaweb-announcement-bar' ), 'mobile' => __( 'Mobile only', 'aaweb-announcement-bar' ) ) ); ?> select_field( 'button_animation', __( 'Button animation', 'aaweb-announcement-bar' ), $settings, array( 'none' => __( 'None', 'aaweb-announcement-bar' ), 'pulse' => __( 'Pulse', 'aaweb-announcement-bar' ), 'bounce' => __( 'Bounce', 'aaweb-announcement-bar' ), 'glow' => __( 'Glow', 'aaweb-announcement-bar' ) ) ); ?>
subsection_heading( __( 'Button style', 'aaweb-announcement-bar' ), 'button-style' ); ?>
text_field( 'button_bg_color', __( 'Background', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'button_text_color', __( 'Text color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'button_hover_bg_color', __( 'Hover background', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'button_hover_text_color', __( 'Hover text', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'button_border_color', __( 'Border color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> number_field( 'button_border_width', __( 'Border width', 'aaweb-announcement-bar' ), $settings, 0, 8, 'px' ); ?> number_field( 'button_radius', __( 'Radius', 'aaweb-announcement-bar' ), $settings, 0, 999, 'px' ); ?> number_field( 'button_padding_y', __( 'Padding Y', 'aaweb-announcement-bar' ), $settings, 0, 30, 'px' ); ?> number_field( 'button_padding_x', __( 'Padding X', 'aaweb-announcement-bar' ), $settings, 0, 60, 'px' ); ?> number_field( 'button_font_size', __( 'Font size', 'aaweb-announcement-bar' ), $settings, 10, 40, 'px' ); ?> select_field( 'button_font_weight', __( 'Font weight', 'aaweb-announcement-bar' ), $settings, array( '400' => '400', '500' => '500', '600' => '600', '700' => '700' ) ); ?> number_field( 'button_margin_left', __( 'Margin left', 'aaweb-announcement-bar' ), $settings, 0, 80, 'px' ); ?> number_field( 'button_margin_right', __( 'Margin right', 'aaweb-announcement-bar' ), $settings, 0, 80, 'px' ); ?>
section_heading( '🎨', __( 'Design & layout', 'aaweb-announcement-bar' ), __( 'Control colors, typography, width and the horizontal / vertical alignment of text and button.', 'aaweb-announcement-bar' ), 'design-all' ); ?> subsection_heading( __( 'Colors & typography', 'aaweb-announcement-bar' ), 'design-colors' ); ?>
text_field( 'background_color', __( 'Background', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'text_color', __( 'Text color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'link_color', __( 'Link color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'border_color', __( 'Border color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> number_field( 'font_size', __( 'Font size', 'aaweb-announcement-bar' ), $settings, 10, 40, 'px' ); ?> select_field( 'font_weight', __( 'Font weight', 'aaweb-announcement-bar' ), $settings, array( '400' => '400', '500' => '500', '600' => '600', '700' => '700' ) ); ?>
subsection_heading( __( 'Layout & positioning', 'aaweb-announcement-bar' ), 'design-layout' ); ?>
number_field( 'container_width', __( 'Container width', 'aaweb-announcement-bar' ), $settings, 0, 2400, 'px', __( 'Leave empty or 0 for full width.', 'aaweb-announcement-bar' ), true ); ?> select_field( 'horizontal_align', __( 'Horizontal alignment', 'aaweb-announcement-bar' ), $settings, array( 'left' => __( 'Left', 'aaweb-announcement-bar' ), 'center' => __( 'Center', 'aaweb-announcement-bar' ), 'right' => __( 'Right', 'aaweb-announcement-bar' ) ) ); ?> select_field( 'vertical_align', __( 'Vertical alignment', 'aaweb-announcement-bar' ), $settings, array( 'top' => __( 'Top', 'aaweb-announcement-bar' ), 'center' => __( 'Middle', 'aaweb-announcement-bar' ), 'bottom' => __( 'Bottom', 'aaweb-announcement-bar' ) ) ); ?>
checkbox_field( 'sticky', __( 'Sticky at top', 'aaweb-announcement-bar' ), $settings ); ?> checkbox_field( 'border_bottom', __( 'Show bottom border', 'aaweb-announcement-bar' ), $settings ); ?>
section_heading( '👁', __( 'Visibility & schedule', 'aaweb-announcement-bar' ), __( 'Choose where, when and on which devices the bar appears.', 'aaweb-announcement-bar' ), 'rules-all' ); ?> subsection_heading( __( 'Display targeting & schedule', 'aaweb-announcement-bar' ), 'rules-display' ); ?>
select_field( 'display_rule', __( 'Display rule', 'aaweb-announcement-bar' ), $settings, array( 'sitewide' => __( 'Sitewide', 'aaweb-announcement-bar' ), 'homepage' => __( 'Homepage only', 'aaweb-announcement-bar' ), 'exclude_wc_pages' => __( 'Everywhere except cart / checkout / account', 'aaweb-announcement-bar' ), 'woo_products' => __( 'Selected WooCommerce products only', 'aaweb-announcement-bar' ), 'woo_categories' => __( 'Selected WooCommerce product categories', 'aaweb-announcement-bar' ) ) ); ?> select_field( 'device_visibility', __( 'Devices', 'aaweb-announcement-bar' ), $settings, array( 'all' => __( 'All devices', 'aaweb-announcement-bar' ), 'desktop' => __( 'Desktop only', 'aaweb-announcement-bar' ), 'mobile' => __( 'Mobile only', 'aaweb-announcement-bar' ) ) ); ?> text_field( 'exclude_page_ids', __( 'Exclude page IDs', 'aaweb-announcement-bar' ), $settings, 'text', '12,34,56', __( 'Comma separated IDs.', 'aaweb-announcement-bar' ) ); ?> text_field( 'start_date', __( 'Start date', 'aaweb-announcement-bar' ), $settings, 'date' ); ?> text_field( 'end_date', __( 'End date', 'aaweb-announcement-bar' ), $settings, 'date' ); ?> text_field( 'target_product_ids', __( 'Target product IDs', 'aaweb-announcement-bar' ), $settings, 'text', '123,456', __( 'Used with “Selected WooCommerce products only”. Comma separated product IDs.', 'aaweb-announcement-bar' ) ); ?> text_field( 'target_category_ids', __( 'Target product category IDs', 'aaweb-announcement-bar' ), $settings, 'text', '12,34', __( 'Used with “Selected WooCommerce product categories”. Shows on matching category archives and products in those categories.', 'aaweb-announcement-bar' ) ); ?>
subsection_heading( __( 'Countdown', 'aaweb-announcement-bar' ), 'countdown' ); ?>
checkbox_field( 'countdown_enabled', __( 'Show countdown to end date', 'aaweb-announcement-bar' ), $settings, __( 'Counts down to 23:59:59 on the selected end date using the WordPress site timezone.', 'aaweb-announcement-bar' ) ); ?> text_field( 'countdown_label', __( 'Countdown label', 'aaweb-announcement-bar' ), $settings, 'text', __( 'Ends in', 'aaweb-announcement-bar' ) ); ?>
subsection_heading( __( 'Dismiss behavior', 'aaweb-announcement-bar' ), 'dismiss' ); ?>
checkbox_field( 'dismissible', __( 'Allow visitors to close the bar', 'aaweb-announcement-bar' ), $settings, __( 'Uses a small browser cookie/local storage key so the bar stays hidden for the selected days.', 'aaweb-announcement-bar' ) ); ?> number_field( 'dismiss_days', __( 'Show again after', 'aaweb-announcement-bar' ), $settings, 1, 365, __( 'days', 'aaweb-announcement-bar' ) ); ?>
subsection_heading( __( 'Close button appearance (×)', 'aaweb-announcement-bar' ), 'close-style' ); ?>
text_field( 'close_bg_color', __( 'Button background color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'close_text_color', __( 'Icon color ×', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'close_hover_bg_color', __( 'Hover background color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'close_hover_text_color', __( 'Hover icon color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> text_field( 'close_border_color', __( 'Border color', 'aaweb-announcement-bar' ), $settings, 'color' ); ?> number_field( 'close_border_width', __( 'Border width', 'aaweb-announcement-bar' ), $settings, 0, 8, 'px' ); ?> number_field( 'close_size', __( 'Button size', 'aaweb-announcement-bar' ), $settings, 24, 64, 'px' ); ?> number_field( 'close_icon_size', __( 'Icon size ×', 'aaweb-announcement-bar' ), $settings, 12, 40, 'px' ); ?> number_field( 'close_radius', __( 'Border radius', 'aaweb-announcement-bar' ), $settings, 0, 999, 'px' ); ?> number_field( 'close_right', __( 'Right spacing', 'aaweb-announcement-bar' ), $settings, 0, 80, 'px' ); ?>
section_heading( '⚙', __( 'Advanced', 'aaweb-announcement-bar' ), __( 'Developer-friendly options and preview helper.', 'aaweb-announcement-bar' ), 'advanced' ); ?>
text_field( 'custom_class', __( 'Custom CSS class', 'aaweb-announcement-bar' ), $settings, 'text', 'my-announcement-bar' ); ?>
[aaweb_announcement_bar_preview]

·

section_reset_button( $reset_section, __( 'Reset panel', 'aaweb-announcement-bar' ) ); ?>
section_reset_button( $reset_section, __( 'Reset', 'aaweb-announcement-bar' ) ); ?>
> */ private function reset_sections() { $content_main = array( 'enabled', 'content_mode', 'text', 'html_content' ); $mobile = array( 'mobile_text_enabled', 'mobile_text' ); $button_main = array( 'button_enabled', 'link_url', 'link_text', 'link_target', 'button_position', 'button_visibility', 'button_animation' ); $button_style = array( 'button_bg_color', 'button_text_color', 'button_hover_bg_color', 'button_hover_text_color', 'button_border_color', 'button_border_width', 'button_radius', 'button_padding_y', 'button_padding_x', 'button_font_size', 'button_font_weight', 'button_margin_left', 'button_margin_right' ); $design_colors = array( 'background_color', 'text_color', 'link_color', 'border_color', 'font_size', 'font_weight' ); $design_layout = array( 'container_width', 'horizontal_align', 'vertical_align', 'sticky', 'border_bottom' ); $rules_display = array( 'display_rule', 'device_visibility', 'exclude_page_ids', 'start_date', 'end_date', 'target_product_ids', 'target_category_ids' ); $countdown = array( 'countdown_enabled', 'countdown_label' ); $dismiss = array( 'dismissible', 'dismiss_days' ); $close_style = array( 'close_bg_color', 'close_text_color', 'close_hover_bg_color', 'close_hover_text_color', 'close_border_color', 'close_border_width', 'close_size', 'close_icon_size', 'close_radius', 'close_right' ); return array( 'content-main' => $content_main, 'mobile' => $mobile, 'content-all' => array_merge( $content_main, $mobile ), 'coupon' => array( 'coupon_enabled', 'coupon_label', 'coupon_code' ), 'button-main' => $button_main, 'button-style' => $button_style, 'button-all' => array_merge( $button_main, $button_style ), 'design-colors' => $design_colors, 'design-layout' => $design_layout, 'design-all' => array_merge( $design_colors, $design_layout ), 'rules-display' => $rules_display, 'countdown' => $countdown, 'dismiss' => $dismiss, 'close-style' => $close_style, 'rules-all' => array_merge( $rules_display, $countdown, $dismiss, $close_style ), 'advanced' => array( 'custom_class' ), ); } /** * Field name helper. * * @param string $key Field key. * @return string */ private function field_name( $key ) { return AAWEB_Announcement_Bar_Settings::OPTION_KEY . '[' . $key . ']'; } /** * Render checkbox. * * @param string $key Key. * @param string $label Label. * @param array $settings Settings. * @param string $description Description. * @return void */ private function checkbox_field( $key, $label, $settings, $description = '' ) { ?> $settings Settings. * @param string $type Input type. * @param string $placeholder Placeholder. * @param string $description Description. * @return void */ private function text_field( $key, $label, $settings, $type = 'text', $placeholder = '', $description = '' ) { /* translators: %s: Label of the color setting. */ $color_picker_aria_label = sprintf( __( 'Color picker: %s', 'aaweb-announcement-bar' ), $label ); ?>
$settings Settings. * @param int $rows Rows. * @param string $description Description. * @return void */ private function textarea_field( $key, $label, $settings, $rows = 4, $description = '' ) { ?> $settings Settings. * @param int $min Min. * @param int $max Max. * @param string $suffix Suffix. * @param string $description Description. * @param bool $allow_empty Allow empty value. * @return void */ private function number_field( $key, $label, $settings, $min, $max, $suffix = '', $description = '', $allow_empty = false ) { $value = isset( $settings[ $key ] ) ? $settings[ $key ] : ''; if ( $allow_empty && empty( $value ) ) { $value = ''; } ?> $settings Settings. * @param array $options Options. * @return void */ private function select_field( $key, $label, $settings, $options ) { ?>