Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I saw this message today when accessing my plugin page: custom plugin update message

So, how do I create this if I want to update my own plugins that's hosted on wordpress?

share|improve this question

3 Answers

up vote 6 down vote accepted

This message is created by W3_Total_Cache->in_plugin_update_message() hooked to "in_plugin_update_message-$file"in wp_plugin_update_row().

It does some nifties to parse readme and display info from changelog, but overall you can just echo some stuff as with any other hook.

share|improve this answer
Ah, that hook is what i'm looking for. Thx – ariefbayu Sep 20 '10 at 13:12

Hook building

To make the action hook name clear:

global $pagenow;
if ( 'plugins.php' === $pagenow )
{
    // Better update message
    $file   = basename( __FILE__ );
    $folder = basename( dirname( __FILE__ ) );
    $hook = "in_plugin_update_message-{$folder}/{$file}";
    add_action( $hook, 'your_update_message_cb', 20, 2 );
}

Hooked callback function

The function itself has two $variables attached: $plugins_data & $r, which can get accessed by your plugin.

/**
 * Displays an update message for plugin list screens.
 * Shows only the version updates from the current until the newest version
 * 
 * @param (array) $plugin_data
 * @param (object) $r
 * @return (string) $output
 */
function your_update_message_cb( $plugin_data, $r )
{
    // readme contents
    $data       = file_get_contents( 'http://plugins.trac.wordpress.org/browser/YOUR_PLUGIN_FOLDER_NAME_IN_THE_OFFICIAL_REPO/trunk/readme.txt?format=txt' );

    // assuming you've got a Changelog section
    // @example == Changelog ==
    $changelog  = stristr( $data, '== Changelog ==' );

    // assuming you've got a Screenshots section
    // @example == Screenshots ==
    $changelog  = stristr( $changelog, '== Screenshots ==', true );

    // only return for the current & later versions
    $curr_ver   = get_plugin_data('Version');

    // assuming you use "= v" to prepend your version numbers
    // @example = v0.2.1 =
    $changelog  = stristr( $changelog, "= v{$curr_ver}" );

    // uncomment the next line to var_export $var contents for dev:
    # echo '<pre>'.var_export( $plugin_data, false ).'<br />'.var_export( $r, false ).'</pre>';

    // echo stuff....
    $output = 'whatever you want to do';
    return print $output;
}

Footnote:

This approach can be found in the Internal link checker plugin.

share|improve this answer

Howdy, thanks to this question (and no thanks to the author of the W3TC plugin -which is a great plugin), I was able to implement a more generic version of this capability in my plugin (It starts with Version 2.1.16, so you need to play with the version of your installed plugin to see it). You can see it in this file.

The callback is near the end, and is called "in_plugin_update_message()".

It's a wee bit clunkier than I'd like, so I'll be asking a different question.

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.