Construção de gancho
Para tornar o nome do gancho de ação claro:
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 );
}
Função de retorno de chamada com gancho
A função em si tem dois $variables
anexados: $plugins_data
& $r
, que pode ser acessado pelo seu plug-in.
/**
* 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;
}
Nota de rodapé:
Essa abordagem pode ser encontrada no Verificador de links internos .
Adição:
plugin_basename(__FILE__)
pode ser usado em vez das duas linhas acima. Também verificar se a página atual é a página do plugin não é realmente necessário, pois a função só será chamada por essa página. O benefício (muito menor) ainda é que você não tem outro retorno de chamada anexado. Como esta resposta é bem antiga, você faria, enquanto esta abordagem ainda funciona sem nenhum problema, agora verifique o objeto retornado por get_current_screen()
.