Created
January 25, 2021 01:09
-
-
Save BenBroide/d47c958bacfa34a2874bb8deddab0332 to your computer and use it in GitHub Desktop.
src/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {registerPlugin} from '@wordpress/plugins'; | |
import {select, dispatch} from '@wordpress/data'; | |
import {BlockControls} from '@wordpress/block-editor'; | |
import {ToolbarButton, ToolbarGroup} from '@wordpress/components'; | |
import {trash, group} from '@wordpress/icons'; | |
const CloneButton = () => (<ToolbarButton | |
icon={group} | |
onClick={cloneSelectedBlocks} | |
label={'Clone Block'} | |
/>) | |
const DeleteButton = () =>(<ToolbarButton | |
icon={trash} | |
label={'Remove Block'} | |
onClick={deleteSelectedBlocks} | |
/>) | |
const deleteSelectedBlocks = () => { | |
const {removeBlocks} = dispatch('core/block-editor'); | |
const block_ids = select('core/block-editor').getSelectedBlockClientIds(); | |
removeBlocks(block_ids); | |
}; | |
const cloneSelectedBlocks = () => { | |
const block_ids = select('core/block-editor').getSelectedBlockClientIds(); | |
dispatch('core/block-editor').duplicateBlocks(block_ids) | |
}; | |
const CustomButtonsToolbar = () => { | |
return ( | |
<BlockControls> | |
<ToolbarGroup> | |
<div className={`customgutbuttons`}> | |
<CloneButton/> | |
<DeleteButton/> | |
</div> | |
</ToolbarGroup> | |
</BlockControls> | |
); | |
} | |
registerPlugin( | |
'custom-buttons-toolbar-mods', | |
{ | |
render: CustomButtonsToolbar | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment