Display Current Database Name in WordPress Admin Bar

The provided code adds a custom item to the WordPress admin bar, displaying the current database name in the admin interface.

function ts_add_db_name_to_admin_bar($wp_admin_bar) {
    // Check if the current user has the 'manage_options' capability
    if (!current_user_can('manage_options')) {
        return; // If the user is not an admin, exit the function early
    }

    $db_name = DB_NAME; // Retrieve the database name from wp-config.php

    $args = array(
        'id'    => 'db-name', // Unique ID for the menu item
        'title' => 'DB Name: ' . $db_name, // Text to be shown on the menu item
        'href'  => false, // Not making it clickable
        'meta'  => array(
            'class' => 'db-name', // CSS class for styling
            'title' => 'The name of the current WordPress database' // Hover text
        )
    );

    $wp_admin_bar->add_node($args); // Add the menu item to the admin bar
}

add_action('admin_bar_menu', 'ts_add_db_name_to_admin_bar', 100);