【发布时间】: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));
}
?>
【问题讨论】:
-
您的问题是什么?