How to display a message about updates in the plugin list

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.

Read More

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

Related posts

Leave a Reply

1 comment

  1. Problems with you code:

    1. You don’t need to check for $pagenow, that action will only fire in the Plugins screen.

    2. 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.

    3. An action hook doesn’t return values, you do your stuff and that’s all.

    Working code:

    $file   = basename( __FILE__ );
    $folder = basename( dirname( __FILE__ ) );
    $hook = "in_plugin_update_message-{$folder}/{$file}";
    add_action( $hook, 'your_update_message_cb', 10, 2 ); // 10:priority, 2:arguments #
    
    function your_update_message_cb( $plugin_data, $r )
    {
        echo 'Hello World';
    }
    

    Of course, this hook doesn’t work if the plugin is inactive.