Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wp.hooks.addFilter(
- 'blocks.registerBlockType',
- 'myPlugin/quoteButtonAttributes',
- settings => {
- if(settings.name === 'core/pullquote') {
- settings.attributes = {
- ...settings.attributes,
- myPluginShowButton: {
- type: 'boolean',
- default: false,
- },
- myPluginButtonContent: {},
- };
- }
- return settings;
- }
- );
- wp.hooks.addFilter(
- 'editor.BlockEdit',
- 'myPlugin/quoteButtonEdit',
- wp.compose.createHigherOrderComponent(
- BlockEdit => props => {
- if(props.name === 'core/pullquote') {
- const {attributes, setAttributes} = props;
- const {myPluginShowButton, myPluginButtonContent} = attributes;
- return (
- <wp.element.Fragment>
- <BlockEdit {...props} />
- {myPluginShowButton && (
- <button>
- <wp.blockEditor.RichText
- tagName='div'
- placeholder='Click here'
- value={myPluginButtonContent}
- onChange={value => setAttributes({myPluginButtonContent: value})}
- />
- </button>
- )}
- <wp.blockEditor.InspectorControls>
- <wp.components.PanelBody title='Button options'>
- <wp.components.ToggleControl
- label='Show button'
- checked={myPluginShowButton}
- onChange={() => setAttributes({myPluginShowButton: !myPluginShowButton})}
- />
- </wp.components.PanelBody>
- </wp.blockEditor.InspectorControls>
- </wp.element.Fragment>
- );
- }
- return <BlockEdit {...props} />;
- },
- 'withMyPluginQuoteButtonEdit'
- )
- );
- wp.hooks.addFilter(
- 'blocks.getSaveElement',
- 'myPlugin/quoteButtonSave',
- (element, block, attributes) => {
- if(block.name === 'core/pullquote') {
- const {myPluginShowButton, myPluginButtonContent} = attributes;
- if(myPluginShowButton && myPluginButtonContent) {
- return (
- <wp.element.Fragment>
- {element}
- <button>
- <wp.blockEditor.RichText.Content value={myPluginButtonContent} />
- </button>
- </wp.element.Fragment>
- );
- }
- }
- return element;
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement