【问题标题】:Check for a latest version in Interval using php and json使用 php 和 json 在 Interval 中检查最新版本
【发布时间】:2015-04-04 12:49:12
【问题描述】:

我希望 WordPress 在检查 json 文件后有新版本可用时会显示通知。但问题是我希望所有这些功能只在时间间隔上运行,比如每 2 天或 1 周 ..不想要把额外的负担服务器。

function myfun_notice() {
$my_theme = wp_get_theme();
$a=$my_theme->get( 'Version' );
// Read 14 characters starting from the 21st character
$section = file_get_contents('http://www.example.com/file.json', NULL, NULL, 16, 5);
if ($a !== $section){


        $return = '<div class="updated activation"><p><strong>';
        $my_theme = wp_get_theme();
        {
            $return .= sprintf( __( '%s New Version is available.', 'textdomain' ), $my_theme->get( 'Name' ) );
        }
        $return .= '</strong> <a href="' . home_url( '/' ) . '">' . __( 'Visit site', 'textdomain' ) . '</a></p>';

        $return .= '</p></div>';
        echo $return;
    }
}
add_action( 'admin_notices', 'textdomain_notice' );

我在这里找到了另一个代码,但似乎不起作用。所以有人知道可以工作的代码吗?

<?php
$interval=60; //minutes
set_time_limit(0);
while (true)
{
$now=time();
include("the_script.php");
sleep($interval*60-(time()-$now));
}
?>

【问题讨论】:

  • 您的问题是什么?

标签: php json wordpress


【解决方案1】:
  1. 默认情况下,当核心更新可用时,WordPress 已经显示。您是试图覆盖核心行为还是只是不知道它的存在?

  1. WordPress 3.7 开始,它甚至会自动为您更新网站。

  2. 即使您每分钟运行一个请求,您也不会“给服务器增加负担”。

如果您想控制 WordPress 如何处理自动更新,请参阅代码中的Configuring Automatic Background Updates。如果需要,您可以完全禁用,但不建议这样做,以免您在具有已知安全漏洞的代码上运行您的网站。

【讨论】:

  • 是的,我已经知道了。如果向任何人提供自定义插件或主题,以便只能从我的服务器获取更新,那么该怎么做?
  • 好的,您没有指定插件/主题更新。听起来您想在 WordPress 核心更新可用时发出警报。看看我在另一个线程上给出的这个答案,我想这就是你要找的:wordpress.stackexchange.com/questions/183278/…
猜你喜欢
  • 2019-09-02
  • 2016-04-19
  • 2021-12-29
  • 1970-01-01
  • 1970-01-01
  • 2022-06-26
  • 1970-01-01
  • 2014-11-19
  • 2017-10-26
相关资源
最近更新 更多