/** * Flush images for all folders set. */ public function flush() { if (!beans_post('beans_flush_compiler_cache')) { return; } beans_remove_dir(beans_get_compiler_dir()); }
/** * Flush images for all folders set. */ public function flush() { if (!beans_post('beans_flush_edited_images')) { return; } beans_remove_dir(beans_get_images_dir()); }
/** * Remove a directory and its files. * * @since 1.0.0 * * @param string $dir_path Path to directory to remove. * * @return bool Will always return true. */ function beans_remove_dir($dir_path) { if (!is_dir($dir_path)) { return false; } $items = scandir($dir_path); unset($items[0], $items[1]); foreach ($items as $needle => $item) { $path = $dir_path . '/' . $item; if (filetype($dir_path . '/' . $item) === 'dir') { beans_remove_dir($path); } else { @unlink($path); } unset($items[$needle]); } @rmdir($dir_path); return true; }
/** * Flush cached compiler files. * * Each compiler has its own folder which contains the cached CSS and JS files. Cached files format * can be specified if needed. * * @since 1.0.0 * * @param string $id The compiler ID. Similar to the WordPress scripts $handle argument. * @param string|bool $file_format Optional. Define which files format should be removed. Both CSS and JS * files will be removed if set to false. Accepts 'false', 'css' or 'js'. * @param bool $admin Optional. Whether it is an admin compiler or not. */ function beans_flush_compiler($id, $file_format = false, $admin = false) { static $beans_flushed = false; $cache_dir = beans_get_compiler_dir($admin); // Always flush beans global chache. if (!$beans_flushed) { $beans_flushed = true; beans_flush_compiler('beans', $file_format, $admin); } $dir = trailingslashit($cache_dir) . $id; // Stop here if directory doesn't exist. if (!is_dir($dir)) { return; } // Remove only specified format files. if ($file_format) { $items = scandir($dir); unset($items[0], $items[1]); foreach ($items as $item) { if (stripos($item, '.' . $file_format) !== false) { @unlink(trailingslashit($dir) . $item); } } } else { beans_remove_dir($dir); } }