我会这样做:
首先在您的主题目录中创建一个文件,文件名用哈希表示-这个是md5(“foobar”):
3858f62230ac3c915f300c664312c63f.php
该文件中的内容如下:
//Use the file name as an API key of sorts
$file = explode(\'.\', basename(__FILE__));
$key = $file[0];
//Trigger the WP function - corresponds to the foo_w3tc_flush_cron() function
define(\'FOO_W3TC_FLUSH\', true);
define(\'FOO_W3TC_FLUSH_KEY\', $key);
//Set headers
Header(\'Cache-Control: no-cache\');
Header(\'Pragma: no-cache\');
//Set W3TC Constants
define(\'DONOTMINIFY\', true);
define(\'DONOTCACHEDB\', true);
define(\'DONOTCACHEPAGE\', true);
//Set WP Constants
define(\'DOING_AJAX\', true);
//Load WP
if(file_exists($_SERVER[\'DOCUMENT_ROOT\'].\'/wp-load.php\'))
require_once($_SERVER[\'DOCUMENT_ROOT\'].\'/wp-load.php\');
die();
向函数中添加函数。php文件类似于以下内容:
$api_key_plaintext = \'foobar\';
define(\'FOO_W3TC_FLUSH_API_KEY\', md5($api_key_plaintext));
add_action(\'plugins_loaded\', \'foo_w3tc_flush_cron\', 1);
function foo_w3tc_flush_cron(){
$update = FOO_W3TC_FLUSH_UPDATE;
$key = FOO_W3TC_FLUSH_UPDATE_KEY;
if($update && $key == FOO_W3TC_FLUSH_API_KEY){
if (function_exists(\'w3tc_pgcache_flush\')){
if(w3tc_pgcache_flush())
wp_mail(\'[email protected]\', \'Success!\', \'Hello, this is an automatically scheduled email from WordPress.\');
else
wp_mail(\'[email protected]\', \'Failure\', \'Hello, this is an automatically scheduled email from WordPress.\');
}
echo "Foo W3TC Cache Message"; //For logger
die(); //We don\'t need the rest of WP to load
}
}
最后,我将添加以下crontab以在晚上11:59(您的服务器时间)运行,并包括一个到主目录的文件路径以记录结果:
59 23 * * * curl --header \'Cache-Control: max-age=0\' http://your-domain.com/wp-content/themes/your-theme/3858f62230ac3c915f300c664312c63f.php >> /home/myuser/w3tc-flush.log
希望这有帮助!