wordpress主题和插件更新如何从远程服务器工作

时间:2017-02-27 11:24:54

标签: wordpress http server wordpress-theming auto-update

实际上wordpress主题和插件如何更新工作。什么是核心class来处理这个系统。 wordpress如何处理来自远程服务器的HTTP请求。

你能帮我提一些basic guide吗?

1 个答案:

答案 0 :(得分:2)

核心课程:

...\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小时等待期是在wp-includes / update.php文件的第223行的WordPress核心中定义的,它是$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服务器]

https://kaspars.net/blog/wordpress/automatic-updates-for-plugins-and-themes-hosted-outside-wordpress-extend

  

希望你会有所帮助。