wordpress 主题和插件更新如何从远程服务器工作
How wordpress theme and plugin update work from remote server
实际上 wordpress 主题和插件更新是如何工作的。处理这个系统的核心是什么class
。 wordpress 如何处理来自远程服务器的 HTTP
请求。
你能帮我送一些吗basic guide
?
核心Class:
...\wp-includes\update.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)
12 小时的等待时间在 WordPress 核心中定义在 wp-includes/update.php 文件的第 223 行,它是 $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-wordpress-http-api-automatic-plugin-updates--wp-25181
http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/ [仅适用于 Apache 服务器]
Hope it would be helpful.
实际上 wordpress 主题和插件更新是如何工作的。处理这个系统的核心是什么class
。 wordpress 如何处理来自远程服务器的 HTTP
请求。
你能帮我送一些吗basic guide
?
核心Class:
...\wp-includes\update.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)
12 小时的等待时间在 WordPress 核心中定义在 wp-includes/update.php 文件的第 223 行,它是 $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-wordpress-http-api-automatic-plugin-updates--wp-25181
http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/ [仅适用于 Apache 服务器]
Hope it would be helpful.