maybe_add_mode_node( $bar );
$this->maybe_add_noindex_node( $bar );
}
/**
* Maintenance / Coming Soon pill.
* Orange for Coming Soon, red for Maintenance, nothing when Off.
*/
private function maybe_add_mode_node( \WP_Admin_Bar $bar ): void {
$mode = admbud_get_option( 'admbud_maintenance_mode', 'off' );
if ( $mode === 'off' ) {
return;
}
$settings_url = admin_url( 'admin.php?page=admbud&tab=maintenance' );
// SVG icons - inline in the admin bar node title (WP_Admin_Bar accepts HTML).
$rocket_svg = '';
$wrench_svg = '';
if ( $mode === 'coming_soon' ) {
$icon = $rocket_svg;
$label = __( 'Coming Soon', 'admin-buddy' );
$class = 'ab-bar-node ab-bar-node--coming-soon';
} else {
$icon = $wrench_svg;
$label = __( 'Maintenance', 'admin-buddy' );
$class = 'ab-bar-node ab-bar-node--maintenance';
}
$bar->add_node( [
'id' => 'ab-mode-indicator',
'title' => '' . $icon . esc_html( $label ) . '',
'href' => $settings_url,
'meta' => [
'title' => __( 'Admin Buddy: click to manage site mode', 'admin-buddy' ),
],
] );
}
/**
* Search-engine discouragement pill.
* Yellow warning when WP's "Discourage search engines" is checked.
*/
private function maybe_add_noindex_node( \WP_Admin_Bar $bar ): void {
if ( get_option( 'blog_public' ) !== '0' ) {
return; // Site is indexable - nothing to show.
}
$settings_url = admin_url( 'options-reading.php' );
$bar->add_node( [
'id' => 'ab-noindex-indicator',
'title' => '' . esc_html__( 'Search Engines Blocked', 'admin-buddy' ) . '',
'href' => $settings_url,
'meta' => [
'title' => __( 'Search engines are discouraged from indexing this site. Click to change', 'admin-buddy' ),
],
] );
}
// -- Inline CSS ------------------------------------------------------------
/**
* Tiny inline stylesheet for the pill nodes.
* Kept inline so it works on both admin and front-end admin bar
* without needing to enqueue a separate file for front-end.
*/
public function inline_css(): void {
if ( ! is_admin_bar_showing() ) {
return;
}
// Pull pill colours from options. Read-side: sanitize_hex_field()
// validates the hex format. Output-side: each value is run through
// sanitize_hex_color() again at the concat site below to enforce
// "escape late" — only a valid #rgb / #rrggbb string ever reaches
// the CSS string.
$coming_soon = sanitize_hex_field( admbud_get_option( 'admbud_colours_pill_coming_soon', '' ) ) ?: \Admbud\Colours::COLOR_COMING_SOON;
$maintenance = sanitize_hex_field( admbud_get_option( 'admbud_colours_pill_maintenance', '' ) ) ?: \Admbud\Colours::COLOR_MAINTENANCE;
$noindex = sanitize_hex_field( admbud_get_option( 'admbud_colours_pill_noindex', '' ) ) ?: \Admbud\Colours::COLOR_NOINDEX;
$admin_buddy = sanitize_hex_field( admbud_get_option( 'admbud_colours_pill_admin_buddy', '' ) )
?: ( sanitize_hex_field( admbud_get_option( 'admbud_colours_primary', '' ) ) ?: \Admbud\Colours::DEFAULT_PRIMARY );
// Escape-late: re-run through sanitize_hex_color(); fall back to a
// safe default if the option somehow contains a non-hex value.
$coming_soon = sanitize_hex_color( $coming_soon ) ?: \Admbud\Colours::COLOR_COMING_SOON;
$maintenance = sanitize_hex_color( $maintenance ) ?: \Admbud\Colours::COLOR_MAINTENANCE;
$noindex = sanitize_hex_color( $noindex ) ?: \Admbud\Colours::COLOR_NOINDEX;
$admin_buddy = sanitize_hex_color( $admin_buddy ) ?: \Admbud\Colours::DEFAULT_PRIMARY;
$css = '#wpadminbar #wp-admin-bar-ab-mode-indicator > .ab-item,'
. '#wpadminbar #wp-admin-bar-ab-noindex-indicator > .ab-item,'
. '#wpadminbar #wp-admin-bar-ab-checklist-indicator > .ab-item,'
. '#wpadminbar #wp-admin-bar-admbud > .ab-item,'
. '#wpadminbar .quicklinks #wp-admin-bar-ab-mode-indicator:hover > .ab-item,'
. '#wpadminbar .quicklinks #wp-admin-bar-ab-noindex-indicator:hover > .ab-item,'
. '#wpadminbar .quicklinks #wp-admin-bar-ab-checklist-indicator:hover > .ab-item,'
. '#wpadminbar .quicklinks #wp-admin-bar-admbud:hover > .ab-item,'
. '#wpadminbar.mobile .quicklinks #wp-admin-bar-ab-mode-indicator:hover > .ab-item,'
. '#wpadminbar.mobile .quicklinks #wp-admin-bar-ab-noindex-indicator:hover > .ab-item,'
. '#wpadminbar.mobile .quicklinks #wp-admin-bar-ab-checklist-indicator:hover > .ab-item,'
. '#wpadminbar.mobile .quicklinks #wp-admin-bar-admbud:hover > .ab-item{'
. 'padding:0!important;background:transparent!important;color:inherit!important;}'
. '.ab-bar-node{display:inline-flex;align-items:center;gap:5px;padding:0 10px!important;'
. 'border-radius:20px;font-size:12px;font-weight:600;line-height:1;height:22px;'
. 'margin:5px 3px 0 3px;letter-spacing:0.01em;transition:opacity 0.15s;}'
. '#wpadminbar .ab-bar-node:hover{opacity:0.85;}'
. '.ab-bar-node--coming-soon{background:' . $coming_soon . ';color:#ffffff;}'
. '.ab-bar-node--maintenance{background:' . $maintenance . ';color:#ffffff;}'
. '.ab-bar-node--noindex{background:' . $noindex . ';color:#ffffff;}'
. '.ab-bar-node--admin-buddy{background:' . $admin_buddy . ';color:#ffffff;}'
. '.ab-bar-node--checklist-ok{background:#2d7a2d;color:#ffffff;}'
. '.ab-bar-node--checklist-warn{background:#b45309;color:#ffffff;}'
. '.ab-bar-node--checklist-alert{background:#b42318;color:#ffffff;}';
wp_add_inline_style( 'admin-bar', $css );
}
}