should_display() ) { return; } $is_test = 'test' === Payment_Helper::get_payment_mode(); $variant = $is_test ? 'test' : 'live'; $label = $is_test ? __( 'SureDonation: Test Mode', 'suredonation' ) : __( 'SureDonation: Live', 'suredonation' ); $tooltip = $is_test ? __( 'SureDonation is in test mode — no real payments are being accepted. Click to switch to live mode.', 'suredonation' ) : __( 'SureDonation is in live mode — real payments are being accepted.', 'suredonation' ); $title = sprintf( '%2$s', esc_attr( $variant ), esc_html( $label ) ); $wp_admin_bar->add_node( [ 'id' => self::NODE_ID, // Anchor to the right-hand group so the mode reads as a status // indicator rather than a navigation item. 'parent' => 'top-secondary', 'title' => $title, 'href' => Payment_Helper::get_settings_url(), 'meta' => [ 'title' => $tooltip ], ] ); } /** * Register the inline toolbar styles when the indicator will show. * * Attached to the always-registered core `admin-bar` stylesheet so the * badge is styled in both the admin and the front-end toolbar. * * @return void * @since 1.3.0 */ public function enqueue_style() { if ( ! is_admin_bar_showing() || ! $this->should_display() ) { return; } $css = '#wpadminbar #wp-admin-bar-' . self::NODE_ID . ' .ab-item{display:flex;align-items:center;}' . '#wpadminbar .sd-admin-bar-mode__dot{display:inline-block;width:8px;height:8px;margin-right:7px;border-radius:50%;background:currentColor;}' . '#wpadminbar .sd-admin-bar-mode--test{color:#f0c33c;}' . '#wpadminbar .sd-admin-bar-mode--live{color:#5fd07a;}'; wp_add_inline_style( 'admin-bar', $css ); } /** * Whether the payment-mode indicator should be shown to the current user. * * @return bool * @since 1.3.0 */ private function should_display() { return current_user_can( 'manage_options' ) && Payment_Helper::is_any_gateway_connected(); } }