我今天在访问插件页面时看到这条消息:
那么,如果我想更新自己在wordpress上托管的插件,我该如何创建它呢?
我今天在访问插件页面时看到这条消息:
那么,如果我想更新自己在wordpress上托管的插件,我该如何创建它呢?
此邮件由创建W3_Total_Cache->in_plugin_update_message()
连接到"in_plugin_update_message-$file"
在里面wp_plugin_update_row()
.
它在解析自述文件和显示changelog中的信息方面做得很好,但总的来说,您可以像使用任何其他钩子一样重复一些内容。
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()
.如果我写一个私有插件,有没有办法使用WordPress自动更新机制来更新它 我想封装这个功能,但它是我自己的5个博客特有的,所以它不是公共插件资源的好候选。但我喜欢这种简单的更新机制 有没有办法做到这一点