/** * * METHODS * */ public static function init() { if (defined('MG_CACHE_DIR')) { self::$cacheDir = WP_CONTENT_DIR . '/' . MG_CACHE_DIR . '/' . self::$cacheSubdir; } else { self::$cacheDir = WP_CONTENT_DIR . '/cache/' . self::$cacheSubdir; } $wpContentUrl = preg_replace('/(http|https):\\/\\/' . $_SERVER['HTTP_HOST'] . '\\/(.*)\\/wp-content/', '/wp-content', WP_CONTENT_URL); if (defined('MG_CACHE_PATH')) { self::$cachePath = $wpContentUrl . '/' . MG_CACHE_PATH . '/' . self::$cacheSubdir; } else { self::$cachePath = $wpContentUrl . '/cache/' . self::$cacheSubdir; } if (defined('MG_CACHE_EXTENSION')) { self::$fileExtension = MG_CACHE_EXTENSION; } else { self::$fileExtension = 'cache'; } if (defined('MG_CACHE_DRIVER')) { self::$cacheDriver = CacheProviderFactory::build(MG_CACHE_DRIVER); } // ABSPATH won't work reliably if WP is installed in a subdirectory self::$webRoot = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/'; if (empty(self::$webRoot)) { self::$webRoot = ABSPATH; } if (defined('MG_CACHE_DRIVER')) { self::$cacheDriver = CacheProviderFactory::build(MG_CACHE_DRIVER); } else { self::$cacheDriver = CacheProviderFactory::build('file'); } // test that cache directory is writable (for windows and vagrant... which fail is_writable) try { $testFile = self::$cacheDir . '/__cache.txt'; $fp = fopen($testFile, 'w'); fwrite($fp, 'hello cache!'); if (!file_exists($testFile)) { throw new \Exception(); } MgAssetHelper::registerSettings(); MgAssetHelper::registerFilters(); } catch (\Exception $e) { add_action('admin_notices', array('MgAssetHelper', 'adminErrorNoticeCacheDirectoryWritable')); } }