个性化阅读
专注于IT技术分析

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

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

你能帮我给一些基本的指导吗?


#1


核心课程:

...\wp-includes\update.php

update.php文件在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小时左右后, 刷新你的Blog插件页面, 你应该获得与以下类似的输出:

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

希望对你有所帮助。

赞(0)
未经允许不得转载:srcmini » WordPress主题和插件更新如何从远程服务器工作

评论 抢沙发

评论前必须登录!