Created
September 7, 2018 23:07
-
-
Save jorgefilipecosta/7a925ac31448832f00fceb0b0caed423 to your computer and use it in GitHub Desktop.
This file contains 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
( function() { | |
var registerBlockType = wp.blocks.registerBlockType; | |
var el = wp.element.createElement; | |
var MediaPlaceholder = wp.editor.MediaPlaceholder; | |
registerBlockType( 'test/media-upload', { | |
title: 'Test Media Upload', | |
icon: 'cart', | |
category: 'common', | |
attributes: { | |
url: { | |
type: 'string', | |
}, | |
}, | |
edit: function( props ) { | |
return el( 'div', { style: { outline: '1px solid gray', padding: 5 } }, | |
props.attributes.url, | |
el( MediaPlaceholder, { | |
onSelect: ( media ) => { | |
props.setAttributes( { url: media.url } ) | |
}, | |
labels: { title: 'Upload an image or a video' }, | |
type: 'image,video', | |
accept: 'image/*,video/*', | |
} ) | |
); | |
}, | |
save: function( props ) { | |
return el( 'div', { style: { outline: '1px solid gray', padding: 5 } }, | |
props.attributes.url | |
); | |
}, | |
} ); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment