• Resolved arcanetech

    (@arcanetech)


    BrikPanel replaces the native WordPress admin bar with its own topbar (Brikpanel_Dashboard_Topbar). The topbar already has a solid per-item visibility and audience system (brikpanel-topbar-items.php) covering its 9 built-in controls, but that system only manages existing items. There’s no way for a plugin to register a new item into the topbar programmatically.

    Problem

    Because the native admin bar is hidden (not removed, just CSS-hidden via the brikpanel-has-topbar body class), any plugin using add_action('admin_bar_menu', ...) to add nodes still fires, but renders into a bar nobody sees. The only workaround BrikPanel currently offers is custom_link: a single, owner-typed label+URL pair, entered manually in settings. That’s fine for one static shortcut. It doesn’t scale to a plugin wanting to add a live counter, a dropdown menu, or a status indicator the way create or notifications do internally.

    Requested solution

    Add a filter, e.g.:

    php

    apply_filters( 'brikpanel_topbar_items', array $items )

    fired inside Brikpanel_Dashboard_Topbar::render() before or after the built-in items, so a plugin can register a new item using the same shape BrikPanel’s own items already use: an id, a render callback (or icon + label + href for the simple case), and optionally a position (left/right, before/after a given built-in key).

    Why this specific approach

    The existing visibility/audience code in brikpanel_topbar_item_is_visible() and brikpanel_topbar_item_audience_allows() is keyed by item id and already backward-compatible with unknown keys (defaults to visible). If registered items are pushed through brikpanel_topbar_items_label_map() (or a merged version of it) before the settings UI renders, the existing toggle-switch and per-role audience UI in brikpanel_render_topbar_items_field() extends to cover developer-registered items automatically, with no new UI work. This is the same pattern BrikPanel already uses for brikpanel_product_editor_boxes in the hooks API: register via filter, let the existing render/priority/visibility machinery handle it.

    Suggested minimal shape

    php

    add_filter( 'brikpanel_topbar_items', function ( $items ) {
        $items['my_plugin_status'] = [
            'label'    => __( 'Sync status', 'my-plugin' ),
            'position' => 'right',   // or 'left'
            'priority' => 15,
            'callback' => function () {
                echo '<span class="my-plugin-topbar-badge">Synced</span>';
            },
        ];
        return $items;
    } );

    Open question for the BrikPanel team

    Should registered items pass through brikpanel_topbar_item_is_visible() by default (inheriting the toggle/audience system for free), or should that require an explicit opt-in flag per item? Defaulting to “inherited” matches how brikpanel_product_editor_boxes behaves and avoids every third-party plugin needing to duplicate visibility logic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support latti

    (@niyht)

    Thank you very much, I’ve made all the changes you requested and released the new version 3.2.60 . If you notice anything missing, please let me know here. In the meantime, you need to download and install the new version from the plugin’s wp.org page because the update notification will appear after 6 hours.

    By the way, if you like the plugin, leaving a review would also be a huge help to me 🙏

    Thread Starter arcanetech

    (@arcanetech)

    Thank you so much for shipping this so quickly. I’m loving what you’ve built so far.

    For this change, I appreciate the clean API design (anchoring, priority, capability gating, and settings-integration all handled in one filter).

    This reply is mainly informational. I wanted to follow up with a quick example for anyone else picking this up, since a few people have asked how to register one item that works correctly whether BrikPanel’s topbar is active or not.

    Adding a top bar item that works with both the native WP admin bar and BrikPanel’s topbar

    The two hooks have different contracts, so you can’t reuse one callback directly, but you can share the render logic. Here’s a small helper that does the branching for you:

    php

    /**
     * Register a top bar item that works whether BrikPanel's topbar is
     * rendering or not. Falls back to the native admin bar automatically.
     */
    function my_register_topbar_item( $id, array $args ) {
        $render = $args['render'];
    
        add_action( 'init', function () use ( $id, $args, $render ) {
            $brikpanel_active = is_admin()
                && class_exists( 'Brikpanel_Dashboard_Topbar' )
                && Brikpanel_Dashboard_Topbar::is_enabled();
    
            if ( $brikpanel_active ) {
                add_filter( 'brikpanel_topbar_items', function ( $items ) use ( $id, $args, $render ) {
                    $items[ $id ] = [
                        'label'    => $args['label'] ?? $id,
                        'position' => $args['position'] ?? 'right',
                        'before'   => $args['before'] ?? 'user',
                        'priority' => $args['priority'] ?? 10,
                        'settings' => $args['settings'] ?? true,
                        'callback' => $render,
                    ];
                    return $items;
                } );
                return;
            }
    
            // Native WP admin bar fallback.
            add_action( 'admin_bar_menu', function ( $wp_admin_bar ) use ( $id, $args, $render ) {
                ob_start();
                $render();
                $html = ob_get_clean();
                if ( trim( $html ) === '' ) {
                    return;
                }
                $wp_admin_bar->add_node( [
                    'id'     => $id,
                    'parent' => $args['parent'] ?? 'top-secondary',
                    'title'  => $html,
                    'meta'   => $args['meta'] ?? [],
                ] );
            }, $args['priority'] ?? 10 );
        }, 20 ); // must run after BrikPanel's own init (priority 10)
    }

    Usage: for example, I created an environment badge that only shows outside production:

    php

    my_register_topbar_item( 'my-env-badge', [
    'label' => 'Environment badge',
    'settings' => false, // always on, no toggle in BrikPanel settings
    'position' => 'left',
    'after' => 'live',
    'render' => function () {
    $env = wp_get_environment_type();
    if ( 'production' === $env ) {
    return;
    }
    echo '<span style="padding:4px 12px;background:#1d4ed8;color:#fff;border-radius:8px;font-size:11px;font-weight:600;text-transform:uppercase;">'
    . esc_html( ucfirst( $env ) ) . '</span>';
    },
    ] );

    Notes:

    • The init priority 20 matters. BrikPanel’s own bootstrap (brikpanel_init_admin) also hooks init at the default priority 10, and requires the topbar file there. If your check runs at the same priority, load order determines whether the class exists yet, which is inconsistent across setups. Hooking at 20 guarantees you check after BrikPanel has had a chance to load.
    • Brikpanel_Dashboard_Topbar::is_enabled() respects the store owner’s own master on/off switch for the topbar, so this correctly falls back to the native bar if they’ve turned it off without deactivating the plugin.
    • Valid before/after anchors on the BrikPanel side: brand, live, search, create, notifications, hidden_notices, custom_link, view_site, user. Unrecognized anchors just fall back to the default slot instead of erroring.
    • 'settings' => false keeps your item out of BrikPanel’s Settings → Dashboard toggle list if you don’t want the owner switching it off. Leave it true (or omit) if you do.

    Hope this saves someone the debugging round trip I went through.

    Thanks again for the fast turnaround on this.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.