beans_flush_compiler

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

NameTypeRequiredDefaultDescription
$idstringtrue-The compiler ID. Similar to the WordPress scripts $handle argument.
$file_formatstring|boolfalsefalseDefine which files format should be removed. Both CSS and JS files will be removed if set to false. Accepts 'false', 'css' or 'js'.
$adminboolfalsefalseWhether 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 );

	}

}