Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.