我在服务器中托管了多个WordPress网站,其中一些网站已安装了W3 Total Cache插件。现在,我手动刷新每个站点的缓存,但我想以编程的方式并一起进行缓存。
我正在尝试编写一个将执行此操作的PHP脚本。我正在仪表板上查看此插件的“全部清除缓存”选项所使用的代码,这是这里的内容:
if ( $modules->plugin_is_enabled() ) {
$menu_items['10010.generic'] = array(
'id' => 'w3tc_flush_all',
'parent' => 'w3tc',
'title' => __( 'Purge All Caches', 'w3-total-cache' ),
'href' => wp_nonce_url( network_admin_url(
'admin.php?page=w3tc_dashboard&w3tc_flush_all' ),
'w3tc' ));
所以我猜有两种方法可以做我需要的事情:
1-发出Web请求,但这可能需要身份验证。
2-实例化类并使用方法w3tc_flush_all();
这是我到目前为止所拥有的:
function clean_cache($web)
{
global $path;
$path2 = $path.$web["directory"]."/httpdocs/wp-content/plugins/w3-total-cache/";
if(file_exists($path2)) //Tienen TotalCache instalado
{
require_once $path.'w3-total-cache-api.php';
//if(class_exists("w3-total-cache-api.php"))
//{
$plugin_totalcache = & w3_instance("w3-total-cache-api.php");
//if(function_exists('w3tc_dbcache_flush'))
$plugin_totalcache->w3tc_fush_all();
//}
}
}
任何帮助将不胜感激。