I saw this message today when accessing my plugin page:
So, how do I create this if I want to update my own plugins that's hosted on wordpress?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThis 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.
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 );
}
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.
Addition:
plugin_basename(__FILE__)
can be used instead of those two lines above. Also checking if the current page is the plugin page is not really necessary as the function will only be called by that page anyway. The (very minor) benefit still is that you don't have another callback attached. As this answer is quite old, you would, while this approach still works without a problem, now check against the object returned by get_current_screen()
.
http://plugins.trac.wordpress.org/browser/YOUR_PLUGIN_FOLDER_NAME_IN_THE_OFFICIAL_REPO/trunk/readme.txt?format=txt'
as seen in the answer. Put it in a local file, change what you need. Then change the link to target your local file. The function can read local file contents without a problem. See the PHP docs for that.
file_get_contents
?
1
) also why don!t use the more general echo? And if you would happen to be updating the answer, please also update the callback to be an anonymous function instead of the hardcoded name? :) Thanks :) (I know it was 2011 back then, but it's 2020 :) ) - otherwise the solution still works :)