'W3 Total Cache', 'method' => 'w3tc_flush_all', ), array( 'name' => 'WP Super Cache', 'method' => 'wp_cache_clean_cache', ), array( 'name' => 'WP Fastest Cache', 'class' => 'wpFastestCache', 'method' => 'deleteCache', ), array( 'name' => 'Comet Cache', 'class' => 'WebSharks\CometCache\Classes\ApiBase', 'method' => 'clear', ), ); $installedPlugins = get_plugins(); $pluginNames = array(); foreach ($installedPlugins as $installedPlugin) { $pluginNames[$installedPlugin['Name']] = $installedPlugin; } foreach ($pluginsToClear as $plugin) { $currentPlugin = (isset($pluginNames[$plugin['name']]) ? $pluginNames[$plugin['name']] : false); if ($currentPlugin) { switch ($plugin['name']) { case 'W3 Total Cache': $method = $plugin['method']; if (function_exists($method)) { $method(); } break; case 'WP Super Cache': global $file_prefix; $method = $plugin['method']; if (function_exists($method)) { $method($file_prefix); } break; case 'WP Fastest Cache': case 'Comet Cache': $object = $this->createCacheObject($plugin['class']); if ($object) { $this->clearCache($object, $plugin['method']); } break; } } } } /** * @param string $class * @return object|bool */ public function createCacheObject($class) { return (class_exists($class) ? new $class() : false); } /** * @param object $object * @param string $method */ public function clearCache($object, $method) { if (method_exists($object, $method)) { $object->$method(); } } }