/**
  * Flush images for all folders set.
  */
 public function flush()
 {
     if (!beans_post('beans_flush_compiler_cache')) {
         return;
     }
     beans_remove_dir(beans_get_compiler_dir());
 }
Ejemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param array $args Setting arguments.
  */
 public function __construct($args)
 {
     $defaults = array('id' => false, 'type' => false, 'format' => false, 'fragments' => array(), 'depedencies' => false, 'in_footer' => false, 'minify_js' => false, 'version' => false);
     $this->compiler = array_merge($defaults, $args);
     $this->cache_dir = beans_get_compiler_dir(is_admin()) . $this->compiler['id'];
     if (!$this->maybe_make_dir()) {
         return false;
     }
     $this->set_fragments();
     $this->set_filname();
     if (!$this->cache_file_exist()) {
         $this->cache_file();
     }
     $this->enqueue_file();
 }
Ejemplo n.º 3
0
 /**
  * Constructor.
  *
  * @param array $args Setting arguments.
  */
 public function __construct($args)
 {
     // Modify the WP Filsystem method.
     add_filter('filesystem_method', array($this, 'filesystem_method'));
     $defaults = array('id' => false, 'type' => false, 'format' => false, 'fragments' => array(), 'depedencies' => false, 'in_footer' => false, 'minify_js' => false, 'version' => false);
     $this->compiler = array_merge($defaults, $args);
     $this->dir = beans_get_compiler_dir(is_admin()) . $this->compiler['id'];
     $this->url = beans_get_compiler_url(is_admin()) . $this->compiler['id'];
     $this->set_fragments();
     $this->set_filname();
     if (!$this->cache_file_exist()) {
         $this->filesystem();
         $this->maybe_make_dir();
         $this->cache_file();
     }
     $this->enqueue_file();
     // Keep it safe and reset WP Filsystem method.
     remove_filter('filesystem_method', array($this, 'filesystem_method'));
 }
Ejemplo n.º 4
0
/**
 * 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);
    }
}