Skip to content

Instantly share code, notes, and snippets.

@sharazghouri
Created February 17, 2019 06:07
Show Gist options
  • Save sharazghouri/6c9ba5dadbf6ba53e8ec744553e4d3f4 to your computer and use it in GitHub Desktop.
Save sharazghouri/6c9ba5dadbf6ba53e8ec744553e4d3f4 to your computer and use it in GitHub Desktop.
import { Button } from '@wordpress/components';
import { MediaUpload, MediaUploadCheck } from '@wordpress/editor';
const ALLOWED_MEDIA_TYPES = [ 'audio' ];
function MyMediaUploader() {
return (
// will check user have permission to upload media
<MediaUploadCheck>
<MediaUpload
onSelect={ ( media ) => console.log( 'selected ' + media.length ) }
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ mediaId }
render={ ( { open } ) => (
<Button onClick={ open }>
Open Media Library
</Button>
) }
/>
</MediaUploadCheck>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment