Plugin Directory

Changeset 3780926


Ignore:
Timestamp:
11/02/2026 10:48:22 PM (4 hours ago)
Author:
giorgaras
Message:

Pilot Announcement Bar 1.2.1: hide the theme's own announcement bar while the plugin bar is live, with an opt-out and extra-selector field.

Location:
pilot-announcement-bar/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pilot-announcement-bar/trunk/announcement-pilot.php

    r3777392 r3780926  
    33 * Plugin Name: Pilot Announcement Bar – Announcement Bar & Notification Bar
    44 * Description: Create a clear, branded announcement bar for your WordPress website.
    5  * Version: 1.2.0
     5 * Version: 1.2.1
    66 * Author: Plano Apps
    77 * Text Domain: announcement-pilot
    … …  
    1717final class Plugin {
    1818    const SLUG = 'announcement-pilot';
    19     const VERSION = '1.2.0';
     19    const VERSION = '1.2.1';
    2020
    2121    public static function boot() {
    … …  
    3737            'position' => 'top', 'devices' => 'all', 'font_size' => 16,
    3838            'mobile_font_size' => 16, 'padding_y' => 14, 'bold' => false, 'dismissible' => true,
     39            'hide_theme_bar' => true, 'theme_bar_selectors' => '',
    3940        );
    4041    }
    … …  
    4344        $input = is_array( $input ) ? $input : array();
    4445        $clean = self::defaults();
    45         foreach ( array( 'enabled', 'bold', 'dismissible' ) as $key ) {
     46        foreach ( array( 'enabled', 'bold', 'dismissible', 'hide_theme_bar' ) as $key ) {
    4647            $clean[ $key ] = isset( $input[ $key ] ) && is_scalar( $input[ $key ] ) && in_array( (string) $input[ $key ], array( '1', 'true' ), true );
    4748        }
    … …  
    7475                $clean['url'] = esc_url_raw( $url, array( 'http', 'https' ) );
    7576            }
     77        }
     78        if ( isset( $input['theme_bar_selectors'] ) && is_scalar( $input['theme_bar_selectors'] ) ) {
     79            // CSS selectors only: no braces, semicolons, at-rules or markup.
     80            $selectors = (string) $input['theme_bar_selectors'];
     81            $selectors = preg_replace( '/[\x00-\x1f\x7f{}<>;@\\\\"]/', '', $selectors );
     82            $selectors = trim( preg_replace( '/\s+/', ' ', $selectors ) );
     83            $clean['theme_bar_selectors'] = substr( $selectors, 0, 300 );
    7684        }
    7785        return $clean;
    … …  
    368376                        <section class="ap-panel" data-ap-panel="announcements" hidden>
    369377                            <div class="ap-page-head"><div><h1><?php esc_html_e( 'Announcements', 'announcement-pilot' ); ?></h1><p><?php esc_html_e( 'Write, style and publish your bar.', 'announcement-pilot' ); ?></p></div></div>
    370                             <details class="ap-card ap-guide" <?php echo false === get_option( 'ap_settings', false ) ? 'open' : ''; ?>><summary>Get started in three steps</summary><ol><li><strong>Write your message.</strong> Choose a template or enter your own announcement. The button is optional.</li><li><strong>Check the preview.</strong> Try Desktop and Mobile, choose your colours and placement, and check the contrast feedback.</li><li><strong>Publish when ready.</strong> Select “Show this announcement on my website”, then “Save announcement”. Use “View website” to check the result.</li></ol><p class="ap-help">Already have an announcement bar? Turn it off in your theme settings to avoid duplicates. To unpublish ours, clear the show checkbox and save. You can reopen this guide any time.</p></details>
     378                            <details class="ap-card ap-guide" <?php echo false === get_option( 'ap_settings', false ) ? 'open' : ''; ?>><summary>Get started in three steps</summary><ol><li><strong>Write your message.</strong> Choose a template or enter your own announcement. The button is optional.</li><li><strong>Check the preview.</strong> Try Desktop and Mobile, choose your colours and placement, and check the contrast feedback.</li><li><strong>Publish when ready.</strong> Select “Show this announcement on my website”, then “Save announcement”. Use “View website” to check the result.</li></ol><p class="ap-help">If you also have an announcement bar in your theme, turn on “Hide my theme’s own announcement bar” above so visitors never see two bars. To unpublish ours, clear the show checkbox and save. You can reopen this guide any time.</p></details>
    371379
    372380            <form id="ap-settings" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
    … …  
    408416                    <section class="ap-card"><h2><?php esc_html_e( 'Placement & behaviour', 'announcement-pilot' ); ?></h2><div class="ap-fields">
    409417                        <?php foreach ( array( 'position' => array( 'Top of page', array( 'top' => 'Top of page', 'bottom' => 'Bottom of page' ) ), 'devices' => array( 'Show on', array( 'all' => 'All devices', 'desktop' => 'Desktop only', 'mobile' => 'Mobile only' ) ) ) as $key => $field ) { ?><div class="ap-field"><label for="ap-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( 'position' === $key ? 'Position' : $field[0] ); ?></label><select id="ap-<?php echo esc_attr( $key ); ?>" name="ap_settings[<?php echo esc_attr( $key ); ?>]"><?php foreach ( $field[1] as $value => $label ) { ?><option value="<?php echo esc_attr( $value ); ?>" <?php selected( $s[ $key ], $value ); ?>><?php echo esc_html( $label ); ?></option><?php } ?></select></div><?php } ?>
    410                     </div><?php self::checkbox( 'dismissible', __( 'Visitors can close the announcement', 'announcement-pilot' ), $s ); ?><div class="ap-actions"><?php submit_button( __( 'Save announcement', 'announcement-pilot' ), 'primary', 'submit', false ); ?></div></section>
     418                    </div><?php self::checkbox( 'hide_theme_bar', __( "Hide my theme's own announcement bar so visitors never see two bars", 'announcement-pilot' ), $s ); ?><p class="ap-help">We hide the common announcement bar markup used by WordPress themes. If your theme still shows its own bar, add its CSS selector below.</p><?php self::field( 'theme_bar_selectors', __( 'Extra CSS selectors to hide (optional)', 'announcement-pilot' ), $s ); ?><?php self::checkbox( 'dismissible', __( 'Visitors can close the announcement', 'announcement-pilot' ), $s ); ?><div class="ap-actions"><?php submit_button( __( 'Save announcement', 'announcement-pilot' ), 'primary', 'submit', false ); ?></div></section>
    411419                </div><section class="ap-card"><h2><?php esc_html_e( 'Live preview', 'announcement-pilot' ); ?></h2><div id="ap-preview-size" role="group" aria-label="Preview device"><button type="button" data-ap-device="desktop">Desktop</button><button type="button" data-ap-device="mobile">Mobile</button></div><div id="ap-preview"></div><p id="ap-preview-status" aria-live="polite"></p><p id="ap-contrast-status" class="ap-help" aria-live="polite"></p></section></div>
    412420            </form>
    … …  
    524532        if ( $rendered || ! $s['enabled'] || '' === trim( $s['message'] ) || is_admin() || is_feed() || ! apply_filters( 'announcement_pilot_should_render', true, $s ) ) { return; }
    525533        $rendered = true;
     534        if ( ! empty( $s['hide_theme_bar'] ) ) {
     535            $selectors = array(
     536                '.announcement-bar:not(.ap-site-bar)',
     537                '.announcement-bar-wrapper',
     538                '.announcement-banner',
     539                '.header-announcement',
     540                '.header-announcements',
     541                '.site-announcement',
     542                '.site-announcement-bar',
     543                '.top-announcement',
     544                '.top-announcement-bar',
     545                '[class*="announcement-bar"]:not(.ap-site-bar)',
     546                '[id*="announcement-bar"]:not(.ap-site-bar)',
     547                '[class*="announcement-banner"]',
     548                '[data-announcement-bar]',
     549            );
     550            if ( '' !== trim( (string) $s['theme_bar_selectors'] ) ) {
     551                $selectors[] = $s['theme_bar_selectors'];
     552            }
     553            echo '<style id="announcement-pilot-theme-bar">' . implode( ',', $selectors ) . '{display:none!important}</style>';
     554        }
    526555        $style = sprintf( '--ap-bg:%s;--ap-color:%s;--ap-btn-bg:%s;--ap-btn-color:%s;--ap-font:%dpx;--ap-mobile-font:%dpx;--ap-space:%dpx;--ap-weight:%d;', $s['background'], $s['color'], $s['button_background'], $s['button_color'], $s['font_size'], $s['mobile_font_size'], $s['padding_y'], $s['bold'] ? 700 : 400 );
    527556        echo '<aside id="announcement-pilot-bar" class="ap-site-bar ap-site-bar--' . esc_attr( $s['position'] ) . ' ap-site-bar--' . esc_attr( $s['devices'] ) . '" aria-label="' . esc_attr__( 'Announcement', 'announcement-pilot' ) . '" style="' . esc_attr( $style ) . '"><span class="ap-site-message">' . esc_html( $s['message'] ) . '</span>';
  • pilot-announcement-bar/trunk/readme.txt

    r3777392 r3780926  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.2.0
     7Stable tag: 1.2.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    3232
    3333= Does this change theme files or hide another announcement bar? =
    34 No. It uses standard WordPress hooks. Disable a theme's existing bar in the theme settings if you do not want both bars to appear.
     34By default, yes. The plugin hides common theme announcement bar markup with CSS while its own bar is live, so visitors see one bar. You can turn this off under Placement & behaviour, and add your theme's CSS selector if its bar uses unusual markup.
    3535
    3636= Does closing a bar set cookies? =
    … …  
    4646
    4747== Changelog ==
     48
     49= 1.2.1 =
     50* Automatically hides your theme's own announcement bar when the plugin bar is live, so visitors never see two bars.
     51* Added an option to turn that off and a field for extra CSS selectors if your theme uses unusual markup.
    4852
    4953= 1.2.0 =
Note: See TracChangeset for help on using the changeset viewer.