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.
beans_flush_compiler( string $id, string|bool $file_format = false, bool $admin = false )
Return: (void)
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$id | string | true | - | The compiler ID. Similar to the WordPress scripts $handle argument. |
$file_format | string|bool | false | false | Define which files format should be removed. Both CSS and JS files will be removed if set to false. Accepts 'false', 'css' or 'js'. |
$admin | bool | false | false | Whether it is an admin compiler or not. |
Source
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 ( false !== stripos( $item, '.' . $file_format ) ) {
@unlink( trailingslashit( $dir ) . $item );
}
}
} else { // Remove all format files.
beans_remove_dir( $dir );
}
}