I have re-worded this to make more sense.
Ok, I have a plugin that uses a remote service that check for updates, much like default WordPress plugins, in this case it just checks an XML file.
I want to show a menu bubble like this when an update is available.
It can show just a “1” or text like “alert”, it doesn’t matter.
Since my plugin uses an options page (using add_options_page
) the plugin settings show up under the default “Settings” submenu.
I think I need to add the following CSS to get the bubble to show up,
<span class='update-plugins count-1' title='title'><span class='update-count'>1</span></span>
and tie into the global $submenu
. The problem is I cannot use a hard-coded array value for the menu since each site will have different values.
So I cannot use $submenu[80][10] .= <span class='update-plugins count-1' title='title'><span class='update-count'>1</span></span>
How can I find my plugins submenu value, do I have to loop through the array and match the string values?
Also even when I hard-coded the values I could not get the bubble to show up.
//adding plugin to menu
add_action('admin_menu', 'sec_plugin_checker');
function sec_plugin_checker() {
add_options_page(' Plugin Checker', 'Plugin Check', 'activate_plugins',
'sec_plugin_check', 'sec_checker');
// the conditional where I want the bubble to appear
if (!empty($matches)){
echo "Match found !<br />";
global $submenu;
foreach( $submenu as $item ) {
$item[41][20] = sprintf( __( 'Updates %s', 'sec_plugin_checker' ),
"<span class='update-plugins count-1' title='title'>
<span class='update-count'>1</span></span>");
}
}
and here is what a var_dump($submenu);
looks like,
["options-general.php"]=>
array(9){
...
[41]=>
array(4) {
[0]=>
string(20) "Plugin Check"
[1]=>
string(16) "activate_plugins"
[2]=>
string(21) "sec_plugin_check"
[3]=>
string(23) " Plugin Checker"
...
}
I would do this when you call
add_options_page()
, not later. It’s always better to do this with the supported API instead of playing with the internal structures.The plugin updater periodically checks the plugin status and then saves the result in a transient. This means that it only reads this cached status when the menu is created, it doesn’t do the full check on every page load. You can do something similar:
When you do the actual warning check, you save the results in the transient so it can be read later:
Notice that I don’t do anything special when there are no warnings. The bubble doesn’t get displayed because it gets the class
count-0
, which hasdisplay: none
in the css.Or something along these lines – adapt as needed:
(this is to 1) add a menu item for Gravity Forms and 2) show the count of all unread form IDs in the array. You can extend this with submenu pages for specific forms, with their own counts if needed.