Editor extensions
Two JavaScript filters (from @wordpress/hooks) let another plugin add to the slider's
sidebar.
Add settings to a panel
Each settings panel ends with whatever glidepress-slider.inspector.<panel> returns.
The filter receives the elements other filters have added (an empty array to start)
and the block's edit props, plus device, the device the editor is previewing.
| Panel | Filter names |
|---|---|
| Layout | layout, and responsive from 2.x |
| Motion | motion, and transition and autoplay from 2.x |
| Controls | controls, and navigation from 2.x |
| More settings | advanced, and general from 2.x |
The 2.x names keep working: each renders at the end of the panel that took its settings over. A panel the current slider type hides still appears when a filter adds to it.
A setting needs an attribute to live in. Attributes added this way are saved in the block comment only, so the slider's markup, and so block validity, is unaffected:
wp.hooks.addFilter( 'blocks.registerBlockType', 'acme/ken-burns', ( settings, name ) =>
name === 'glidepress/slider'
? {
...settings,
attributes: {
...settings.attributes,
acmeKenBurns: { type: 'boolean', default: false },
},
}
: settings
);
wp.hooks.addFilter(
'glidepress-slider.inspector.motion',
'acme/ken-burns',
( items, { attributes, setAttributes } ) => [
...items,
wp.element.createElement( wp.components.ToggleControl, {
key: 'ken-burns',
label: 'Ken Burns zoom',
checked: attributes.acmeKenBurns,
onChange: ( acmeKenBurns ) => setAttributes( { acmeKenBurns } ),
} ),
]
);
Read the attribute in PHP from $block['attrs']['acmeKenBurns'] in the
config filter, and act on it with an
add-on feature.
Add choices to a select
glidepress-slider.options.<attribute> extends the choices of a built-in select or
button group, such as glidepress-slider.options.effect:
wp.hooks.addFilter( 'glidepress-slider.options.effect', 'acme/cube', ( options ) => [
...options,
{ label: 'Cube', value: 'cube' },
] );
The front end only acts on values its allowlist knows, so a new choice also needs an add-on feature that reads it. A slider holding a value no choice offers shows it as "(saved value)" rather than quietly displaying the first choice.