Skip to content

Commit 46dd027

Browse files
authored
Put a "Hello World" message in the admin bar
Updated plugin metadata and functionality to replace Hello Dolly in the admin bar with a custom message.
1 parent 1379726 commit 46dd027

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

plugin.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
<?php
22
/*
3-
Plugin Name: Mock Plugin
4-
Description: A simple mock WordPress plugin for testing purposes.
5-
Version: 1.0.0
6-
Author: Your Name
3+
Plugin Name: Hello From My Plugin
4+
Description: Puts "Hello from my plugin" into the admin bar where Hello, Dolly normally shows quotes.
5+
Version: 0.1
6+
Author: You
7+
Text Domain: hfmp
78
*/
89

910
add_action( 'init', function() {
1011
} );
1112

12-
add_action( 'wp_head', function() {
13-
echo '<script>console.log("hello world");</script>';
14-
} );
15-
/**/
16-
/**/
17-
/**/
18-
/**/
19-
/**/
20-
/**/
21-
/**/
22-
/**/
23-
/**/
24-
/**/
25-
/**/
26-
/**/
27-
/**/
13+
if ( ! defined( 'ABSPATH' ) ) {
14+
exit;
15+
}
16+
17+
/* Replace Hello Dolly's node (if present) and add our own in the admin bar. */
18+
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
19+
// only run when the admin bar is actually showing
20+
if ( ! is_admin_bar_showing() ) {
21+
return;
22+
}
23+
24+
// if Hello Dolly exists, remove it so our string takes the same id/position
25+
$wp_admin_bar->remove_node( 'hello-dolly' );
26+
27+
// add a simple, non-linked text node
28+
$wp_admin_bar->add_node( [
29+
'id' => 'hello-dolly', // reuse the same id so placement mirrors Hello Dolly
30+
'title' => __( 'Hello from my plugin', 'hfmp' ),
31+
'href' => false,
32+
'meta' => [
33+
'class' => 'hfmp-hello ab-item',
34+
'title' => __( 'Hello from my plugin', 'hfmp' ),
35+
],
36+
] );
37+
}, 999 );

0 commit comments

Comments
 (0)