Add CSS, LESS or JS fragments to a compiler.
This function should be used in a similar fashion to wp_enqueue_script().
beans_compiler_add_fragment( string $id, string|array $fragments, string $format )
Return: (void)
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$id | string | true | - | The compiler ID. Similar to the WordPress scripts $handle argument. |
$fragments | string|array | true | - | File(s) absolute path. Internal or external file(s) url accepted but may increase compiling time. |
$format | string | true | - | Compiler format the fragments should be added to. Accepts 'css', 'less' or 'js'. |
Source
function beans_compiler_add_fragment( $id, $fragments, $format ) {
if ( empty( $fragments ) ) {
return false;
}
global $_beans_compiler_added_fragments;
foreach ( (array) $fragments as $key => $fragment ) {
// Stop here if the format isn't valid.
if ( ! isset( $_beans_compiler_added_fragments[ $format ] ) ) :
continue;
// Register new compiler id if it doesn't exist and add fragment.
elseif ( ! isset( $_beans_compiler_added_fragments[ $format ][ $id ] ) ) :
$_beans_compiler_added_fragments[ $format ][ $id ] = array( $fragment );
// Add fragment to existing compiler.
else :
$_beans_compiler_added_fragments[ $format ][ $id ][] = $fragment;
endif;
}
}