I am trying to load in custom styles via JS using roots.register.filters
, however, no matter what I do, I cannot get any of these to load in. I am trying to follow the documentation on Bud’s website, but it’s a bit vague on how it’s meant to filter or pull in. I’m not sure if I’m missing an import or what.
The editor.js
file is enqueued, and I can see the code in browser if I visit the URL. Even if I add a console.log or an alert, nothing triggers.
setup.php
/**
* Register the theme assets with the block editor.
*
* @return void
*/
add_action('enqueue_block_editor_assets', function () {
bundle('editor')->enqueue();
}, 100);
This is all I have in my editor.js
roots.register.blocks('@scripts/backend/blocks');
roots.register.filters('@scripts/backend/filters');
roots.register.formats('@scripts/backend/formats');
roots.register.plugins('@scripts/backend/plugins');
roots.register.styles('@scripts/backend/styles');
roots.register.variations('@scripts/backend/variations');
and this is in my /backend/filters/button.filter.js
/**
* @see {@link https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/#blocks-registerblocktype}
*/
export const hook = 'blocks.registerBlockType';
/**
* Filter handle
*/
export const name = 'core/button';
/**
* Filter callback
*
* @param {object} settings
* @param {string} name
* @returns modified settings
*/
export function callback(settings, name) {
if (name !== 'core/button') return settings;
return {
...settings, // merging the styles, or replacing does nothing
styles: [
{
label: 'Button',
name: 'btn',
inlineStyle: '.btn',
isDefault: true,
},
{
label: 'Arrow Left Button',
name: 'arrow-left',
inlineStyle: '.btn.arrow-left'
},
{
label: 'Arrow Right Button',
name: 'arrow-right',
inlineStyle: '.btn.arrow-right'
},
{
label: 'Secondary Button',
name: 'btn--secondary',
inlineStyle: '.btn.btn--secondary'
},
{
label: 'Large Button',
name: 'btn--large',
inlineStyle: '.btn.btn--large'
},
{
label: 'Large Secondary Button',
name: 'btn-secondary-large',
inlineStyle: '.btn.btn--secondary.btn--large'
},
],
};
}