I am trying to use the hook in_plugin_update_message
in order to display a one line message below the name of my plugin in the admin plugin list section.
However, the function called in the hook does not seem to be triggerd: no message is displayed.
I can’t figure out what I am doing wrong.
Building the hook
global $pagenow;
if ( 'plugins.php' === $pagenow )
{
$file = basename( __FILE__ );
$folder = basename( dirname( __FILE__ ) );
$hook = "in_plugin_update_message-{$folder}/{$file}";
add_action( $hook, 'your_update_message_cb');
}
Callback function
function your_update_message_cb( $plugin_data, $r )
{
echo 'Hello World';
$output = 'Hello World';
return print $output;
}
Should I use another hook or is there an error in my code?
thanks for your help
Problems with you code:
You don’t need to check for
$pagenow
, that action will only fire in the Plugins screen.The action takes two arguments, present in your callback function, but absent in the action declaration. If you had
WP_DEBUG
enabled, you’d have seen the notice.An action hook doesn’t return values, you do your stuff and that’s all.
Working code:
Of course, this hook doesn’t work if the plugin is
inactive
.