|
1 | 1 | <?php |
2 | 2 | /* |
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 |
7 | 8 | */ |
8 | 9 |
|
9 | 10 | add_action( 'init', function() { |
10 | 11 | } ); |
11 | 12 |
|
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