Skip to content

Instantly share code, notes, and snippets.

@jorgefilipecosta
Last active June 22, 2018 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgefilipecosta/2dd281f9f5f078258f7c8d4ba4cc34cd to your computer and use it in GitHub Desktop.
Save jorgefilipecosta/2dd281f9f5f078258f7c8d4ba4cc34cd to your computer and use it in GitHub Desktop.
( function() {
const { registerBlockType } = wp.blocks;
const { createElement: el } = wp.element;
const { InnerBlocks } = wp.editor;
registerBlockType( 'acme/product', {
title: 'Product',
icon: {
background: '#7e70af',
src: 'carrot',
},
category: 'common',
edit() {
return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } },
// Only paragraphs, images, and products:
el( InnerBlocks, { allowedBlocks: [ 'core/paragraph', 'core/image' ] } )
// Everything and products:
//el( InnerBlocks )
);
},
save() {
return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } },
el( InnerBlocks.Content )
);
},
} );
registerBlockType( 'acme/buy-button', {
title: 'Buy Button',
icon: {
background: '#7e70af',
src: 'cart',
},
category: 'common',
// Only allow in products:
parent: [ 'acme/product' ],
edit() {
return el(
'button',
{
className: 'buy-button',
style: { display: 'block', margin: '0 auto', padding: '10px 30px' },
},
'Buy Now'
);
},
save() {
return el(
'button',
{
className: 'buy-button',
style: { display: 'block', margin: '0 auto', padding: '10px 30px' },
},
'Buy Now'
);
},
} );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment