should_display() ) { return; } $settings = adab_get_settings(); wp_enqueue_style( 'adab-frontend', ADAB_PLUGIN_URL . 'assets/css/adab-frontend.css', array(), ADAB_VERSION ); // Add dynamic inline CSS custom properties. $inline_css = self::generate_inline_css_vars( $settings ); wp_add_inline_style( 'adab-frontend', $inline_css ); wp_enqueue_script( 'adab-frontend', ADAB_PLUGIN_URL . 'assets/js/adab-frontend.js', array(), ADAB_VERSION, true ); } /** * Generate CSS custom properties for the announcement bar. * * @param array $settings Plugin settings. * @return string */ public static function generate_inline_css_vars( $settings ) { $bg_color = sanitize_hex_color( $settings['bg_color'] ) ? sanitize_hex_color( $settings['bg_color'] ) : '#1e1b4b'; $bg_grad_end = sanitize_hex_color( $settings['bg_gradient_end'] ) ? sanitize_hex_color( $settings['bg_gradient_end'] ) : '#4338ca'; $bg_angle = intval( $settings['bg_gradient_angle'] ); $bg_value = ( 'gradient' === $settings['bg_type'] ) ? sprintf( 'linear-gradient(%ddeg, %s 0%%, %s 100%%)', $bg_angle, $bg_color, $bg_grad_end ) : $bg_color; $text_color = sanitize_hex_color( $settings['text_color'] ) ? sanitize_hex_color( $settings['text_color'] ) : '#ffffff'; $font_desktop = max( 10, min( 32, absint( $settings['font_size_desktop'] ) ) ); $font_mobile = max( 10, min( 28, absint( $settings['font_size_mobile'] ) ) ); $font_weight = in_array( (string) $settings['font_weight'], array( '400', '500', '600', '700' ), true ) ? $settings['font_weight'] : '500'; $pad_desktop = max( 4, min( 36, absint( $settings['bar_padding_desktop'] ) ) ); $pad_mobile = max( 4, min( 28, absint( $settings['bar_padding_mobile'] ) ) ); $cta_bg = sanitize_hex_color( $settings['cta_bg_color'] ) ? sanitize_hex_color( $settings['cta_bg_color'] ) : '#ffffff'; $cta_text = sanitize_hex_color( $settings['cta_text_color'] ) ? sanitize_hex_color( $settings['cta_text_color'] ) : '#1e1b4b'; $cta_radius = max( 0, min( 50, absint( $settings['cta_border_radius'] ) ) ); $scroll_speed = max( 5, min( 90, absint( $settings['scroll_speed'] ) ) ); return sprintf( ':root { --adab-bg: %1$s; --adab-text-color: %2$s; --adab-font-size-desktop: %3$dpx; --adab-font-size-mobile: %4$dpx; --adab-font-weight: %5$s; --adab-pad-desktop: %6$dpx; --adab-pad-mobile: %7$dpx; --adab-cta-bg: %8$s; --adab-cta-text: %9$s; --adab-cta-radius: %10$dpx; --adab-scroll-duration: %11$ds; }', $bg_value, $text_color, $font_desktop, $font_mobile, $font_weight, $pad_desktop, $pad_mobile, $cta_bg, $cta_text, $cta_radius, $scroll_speed ); } /** * Output the bar on wp_body_open if positioned at the top. */ public function output_announcement_bar() { if ( $this->rendered || ! $this->should_display() ) { return; } $settings = adab_get_settings(); if ( 'bottom_sticky' === $settings['position'] ) { return; } $this->rendered = true; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside render_bar_html. echo self::render_bar_html( $settings, false ); } /** * Fallback output in wp_footer (for themes missing wp_body_open or when bottom_sticky is selected). */ public function output_announcement_bar_fallback() { if ( $this->rendered || ! $this->should_display() ) { return; } $settings = adab_get_settings(); $this->rendered = true; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside render_bar_html. echo self::render_bar_html( $settings, false ); } /** * Render the announcement bar HTML. * * @param array $settings Plugin settings array. * @param bool $is_preview Whether rendering inside the Admin Live Preview. * @return string */ public static function render_bar_html( $settings, $is_preview = false ) { $mode = in_array( $settings['display_mode'], array( 'static', 'scrolling', 'sliding' ), true ) ? $settings['display_mode'] : 'static'; $position = in_array( $settings['position'], array( 'top_sticky', 'top_static', 'bottom_sticky' ), true ) ? $settings['position'] : 'top_sticky'; $device_vis = in_array( $settings['device_visibility'], array( 'all', 'desktop_only', 'mobile_only' ), true ) ? $settings['device_visibility'] : 'all'; $slide_dir = in_array( $settings['slide_direction'], array( 'vertical', 'horizontal' ), true ) ? $settings['slide_direction'] : 'vertical'; $messages = isset( $settings['messages'] ) && is_array( $settings['messages'] ) ? array_values( array_filter( $settings['messages'] ) ) : array(); if ( empty( $messages ) ) { $messages = array( __( '🚀 Welcome! Customize your announcement message here.', 'abhinavdev-announcement-bar' ) ); } $classes = array( 'adab-bar', 'adab-mode-' . $mode, 'adab-pos-' . $position, 'adab-device-' . $device_vis, 'adab-slide-dir-' . $slide_dir, ); if ( $is_preview ) { $classes[] = 'adab-is-preview'; } $bar_hash = substr( md5( wp_json_encode( $messages ) ), 0, 8 ); ob_start(); ?>
>
$msg ) : ?>
00d : 00h : 00m : 00s
>