还是一个站点必须手动启动?
我希望我的网站,为了纪念我已故叔叔的二战经历,在11月11日上午11点发布<#>。
发布于 2020-11-06 06:36:00
您应该创建一个小插件来检查时间戳,并在另一个页面或类似的页面上运行。比时间戳大,默认的WordPress运行应该可以工作。举个例子,写出我对这个问题的答案,这个问题不起作用。
方法timestamp是控制加载备用启动页的逻辑的关键。只有当日期是当前日期时,当前示例才加载备用页。因此,在这种方法中,您应该增强逻辑,就像现在比加载启动器定义的日期小一样。
WP环境中的
add_action(
'plugins_loaded',
static function (): bool {
try {
(new Alternate())
->set(__FILE__, '2020-11-06')
->run();
} catch (Throwable $error) {
if (defined('WP_DEBUG') && WP_DEBUG) {
throw $error;
}
return false;
}
return true;
}
);。
use DateTime;
class Alternate
{
private $pluginurl;
private $date;
/**
* @param string $root
* @param string $date
*
* @return Alternate
*/
public function set(string $root, string $date): self
{
$this->pluginroot = plugin_dir_path($root);
$this->pluginurl = plugin_dir_url($root);
$this->date = $date;
return $this;
}
public function run()
{
// Load alternate page or WordPress loop.
if ($this->timestamp()) {
wp_cache_flush();
header('Location: '.$this->placeholderFile(), true, 302);
exit();
}
}
/**
* @return string
*/
private function placeholderFile(): string
{
if (file_exists($this->pluginroot.'assets/placeholder.html')) {
return $this->pluginurl.'assets/placeholder.html';
}
return $this->pluginurl.'assets/placeholder_en.html';
}
private function timestamp(): bool
{
return $this->date === (new DateTime())->format('Y-m-d');
}
}您将在这个解决方案中找到一个类似的想法,在一个违抗日期的页面上飞溅一页。
我的意思是,它也为这个目标提供了免费插件。也许你会去找他们。我没有一个插件在这个想法,但也许插件“维护模式”应该有这个选项。
https://wordpress.stackexchange.com/questions/377734
复制相似问题