实际上WordPress主题和插件更新如何工作。处理该系统的核心class
是什么?WordPress如何从远程服务器处理此HTTP
请求。
您能帮我提供一些basic guide
?
核心类:
...wp-includesupdate.php
update.php file
在API.Wordpress.org服务器上对WordPress服务器进行检查。仅检查WordPress是否未安装。
//Every 12 hours it check version
function wp_version_check(){}
//If Available new plugin version than call
function wp_update_plugins(){}
//If Available new theme version than call
function wp_update_themes(){}
如何工作:
每12小时,您的WordPress博客将检查新的插件版本,并存储在名为'update_plugins'
的站点瞬态中发送的请求和响应。以下代码将显示此瞬态的内容:
add_filter ('pre_set_site_transient_update_plugins', 'display_transient_update_plugins');
function display_transient_update_plugins ($transient)
{
var_dump($transient);
}
12小时左右后,刷新您的博客插件页面,您应该获得与以下内容相似的输出:
object(stdClass)[18]
public 'last_checked' => int 1333808132
public 'checked' =>
array
'access/access.php' => string '1.0' (length=3)
'adpress/wp-adpress.php' => string '3.1' (length=3)
...
'wp-paypal/plug.php' => string '1.0' (length=3)
public 'response' =>
array
'akismet/akismet.php' =>
object(stdClass)[13]
public 'id' => string '15' (length=2)
public 'slug' => string 'akismet' (length=7)
public 'new_version' => string '2.5.5' (length=5)
public 'url' => string 'http://wordpress.org/extend/plugins/akismet/' (length=44)
public 'package' => string 'http://downloads.wordpress.org/plugin/akismet.2.5.5.zip' (length=55)
'update.tmp/plugin.php' =>
object(stdClass)[12]
public 'slug' => string 'plugin' (length=6)
public 'new_version' => string '1.1' (length=3)
public 'url' => string 'http://localhost/update.php' (length=27)
public 'package' => string 'http://localhost/update.php' (length=27)
在WP-INCLUDES/UPDATE.PHP文件的第223行的WordPress Core中定义了12小时的等待期,它是$timeout
变量。
版本比较并检查新版本:
// If a newer version is available, add the update
if (version_compare(1.2, 1.3, '<')) {
$obj = new stdClass();
$obj->slug = $this->slug;
$obj->new_version = $remote_version;
$obj->url = $this->update_path;
$obj->package = $this->update_path;
$transient->response[$this->plugin_slug] = $obj;
}
检查版本后是否有新版本。WordPress句柄通过此过滤器更新 -
add_filter ('pre_set_site_transient_update_plugins', 'display_transient_update_plugins');
function display_transient_update_plugins ($transient)
{
$obj = new stdClass();
$obj->slug = 'hello.php';
$obj->new_version = '1.9';
$obj->url = 'http://anyurl.com';
$obj->package = 'http://anyurl.com';
$transient['hello.php'] => $obj;
return $transient;
}
从远程服务器处理此HTTP请求:
有三个用于更新WordPress插件的教程和远程服务器的主题 - https://code.tutsplus.com/tutorials/a-guide-to-the-the-wordpress-http-api-automatic-plugin-updates-wp-25181
http://w-hadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/[仅适用于Apache Server]
https://kaspars.net/blog/wordpress/automatic-unmatic-updates-for-plugins-and-themes-hosted-hosted-wordpress-wordpress-extend
希望这会有所帮助。