钩子构建要明确动作钩子的名称:
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 );
}
挂钩回调函数函数本身有两个
$variables
附件:
$plugins_data
&;
$r
, 可以通过插件访问。
/**
* 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:
可以在Internal link checker 插件Addition:
plugin_basename(__FILE__)
可以用来代替上面的两行。此外,检查当前页面是否是插件页面并不是真正必要的,因为该函数无论如何只会由该页面调用。(非常小的)好处仍然是您没有附加另一个回调。由于这个答案已经很老了,虽然这种方法仍然可以正常工作,但现在可以对照
get_current_screen()
.