AI Verified

Name

Display Database Name on Admin Bar

About

This snippet will display your WordPress database name on your admin bar for administrator users.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

1. Activate code snippet. This approach limits the visibility of the database name to only administrators. Always consider the broader context of your site's security and privacy policies. Displaying technical information in the admin bar can be very useful for site management but should be used judiciously, especially on sites with multiple administrators or in environments where admin accounts could be compromised.

Codevault

Nestwise

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

21/02/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Display Database Name on Admin Bar

 
                    
1function add_db_name_to_admin_bar($wp_admin_bar) {
2 // Check if the current user has the 'manage_options' capability
3 if (!current_user_can('manage_options')) {
4 return; // If the user is not an admin, exit the function early
5 }
6 
7 $db_name = DB_NAME; // Retrieve the database name from wp-config.php
8 
9 $args = array(
10 'id' => 'db-name', // Unique ID for the menu item
11 'title' => 'DB Name: ' . $db_name, // Text to be shown on the menu item
12 'href' => false, // Not making it clickable
13 'meta' => array(
14 'class' => 'db-name', // CSS class for styling
15 'title' => 'The name of the current WordPress database' // Hover text
16 )
17 );
18 $wp_admin_bar->add_node($args); // Add the menu item to the admin bar
19}
20 
21add_action('admin_bar_menu', 'add_db_name_to_admin_bar', 100);

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

Disable scroll-to-top when editing snippets

Added: 9 months ago

Last Updated: 9 months ago

When using Code Snippets 3.6.0 or later, use this snippet to prevent the automatic scroll-to-top after clicking 'save' when editing a snippet.

WordPress Admin

Pro Verified

0

Hide some items on the Wordpress Sidebar

Added: 1 year ago

Last Updated: 1 year ago

Maybe you want to hide the Plugin item or more from the Wordpress Dashboard Sidebar.

WordPress Admin

AI Verified

0

Block Editor: Alt+Shift+Minus to Toggle Block Outline List View [SnipSnip.pro]

Added: 6 months ago

Last Updated: 6 months ago

ADMIN ONLY • This code snippet enhances the Gutenberg Block Editor in WordPress by adding a keyboard shortcut. By pressing Alt+Shift+Minus, users can toggle the Block Outline List View, which provides...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

5

Display Estimated Read Time For Blog Posts

Added: 6 months ago

Last Updated: 5 months ago

Display the estimated read time of a post with a shortcode. This code snippet produces a shortcode to display the estimated reading time for a post. It strips HTML tags, counts the words, and divi...

WordPress Admin

AI Verified

1

Display External Server IP

Added: 4 months ago

Last Updated: 3 months ago

This WordPress code snippet enhances the admin dashboard by adding a custom item to the WordPress admin bar labeled "Check External IP". This feature allows administrators to fetch and display the ext...

General

AI Verified

0

What's My IP? Display the current users IP address with shortcode

Added: 4 months ago

Last Updated: 4 months ago

Display the users current IP address with shortcode [my-ip]