diff --git a/edit-post/hooks/components/media-upload/index.js b/edit-post/hooks/components/media-upload/index.js index d85a11b2b59ef1..f623a23c37fb06 100644 --- a/edit-post/hooks/components/media-upload/index.js +++ b/edit-post/hooks/components/media-upload/index.js @@ -9,6 +9,7 @@ import { castArray, pick } from 'lodash'; import { parseWithAttributeSchema } from '@wordpress/blocks'; import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import deprecated from '@wordpress/deprecated'; // Getter for the sake of unit tests. const getGalleryDetailsMediaFrame = () => { @@ -75,7 +76,15 @@ const getAttachmentsCollection = ( ids ) => { }; class MediaUpload extends Component { - constructor( { multiple = false, type, gallery = false, title = __( 'Select or Upload Media' ), modalClass, value } ) { + constructor( { + allowedTypes, + type: deprecatedType, + multiple = false, + gallery = false, + title = __( 'Select or Upload Media' ), + modalClass, + value, + } ) { super( ...arguments ); this.openModal = this.openModal.bind( this ); this.onOpen = this.onOpen.bind( this ); @@ -84,6 +93,19 @@ class MediaUpload extends Component { this.onClose = this.onClose.bind( this ); this.processMediaCaption = this.processMediaCaption.bind( this ); + let allowedTypesToUse = allowedTypes; + if ( ! allowedTypes && deprecatedType ) { + deprecated( 'type property of wp.editor.MediaUpload', { + version: '4.2', + alternative: 'allowedTypes property containing an array with the allowedTypes or do not pass any property if all types are allowed', + } ); + if ( deprecatedType === '*' ) { + allowedTypesToUse = undefined; + } else { + allowedTypesToUse = [ deprecatedType ]; + } + } + if ( gallery ) { const currentState = value ? 'gallery-edit' : 'gallery'; const GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame(); @@ -93,7 +115,7 @@ class MediaUpload extends Component { multiple, } ); this.frame = new GalleryDetailsMediaFrame( { - mimeType: type, + mimeType: allowedTypesToUse, state: currentState, multiple, selection, @@ -108,8 +130,8 @@ class MediaUpload extends Component { }, multiple, }; - if ( !! type ) { - frameConfig.library = { type }; + if ( !! allowedTypesToUse ) { + frameConfig.library = { type: allowedTypesToUse }; } this.frame = wp.media( frameConfig ); diff --git a/packages/block-library/src/audio/edit.js b/packages/block-library/src/audio/edit.js index df34522d7d3cb2..9231e2cb1a28b1 100644 --- a/packages/block-library/src/audio/edit.js +++ b/packages/block-library/src/audio/edit.js @@ -21,6 +21,8 @@ import { } from '@wordpress/editor'; import { getBlobByURL } from '@wordpress/blob'; +const ALLOWED_MEDIA_TYPES = [ 'audio' ]; + class AudioEdit extends Component { constructor() { super( ...arguments ); @@ -52,7 +54,7 @@ class AudioEdit extends Component { this.setState( { editing: true } ); noticeOperations.createErrorNotice( e ); }, - allowedType: 'audio', + allowedTypes: ALLOWED_MEDIA_TYPES, } ); } } @@ -109,7 +111,7 @@ class AudioEdit extends Component { onSelect={ onSelectAudio } onSelectURL={ this.onSelectURL } accept="audio/*" - type="audio" + allowedTypes={ ALLOWED_MEDIA_TYPES } value={ this.props.attributes } notices={ noticeUI } onError={ noticeOperations.createErrorNotice } diff --git a/packages/block-library/src/cover-image/index.js b/packages/block-library/src/cover-image/index.js index 63000909d5806a..29c4d6d491bb32 100644 --- a/packages/block-library/src/cover-image/index.js +++ b/packages/block-library/src/cover-image/index.js @@ -54,6 +54,8 @@ const blockAttributes = { export const name = 'core/cover-image'; +const ALLOWED_MEDIA_TYPES = [ 'image' ]; + export const settings = { title: __( 'Cover Image' ), @@ -157,7 +159,7 @@ export const settings = { ( diff --git a/packages/block-library/src/file/edit.js b/packages/block-library/src/file/edit.js index 9a7eb417345b69..49b57c92205478 100644 --- a/packages/block-library/src/file/edit.js +++ b/packages/block-library/src/file/edit.js @@ -56,7 +56,6 @@ class FileEdit extends Component { const file = getBlobByURL( href ); mediaUpload( { - allowedType: '*', filesList: [ file ], onFileChange: ( [ media ] ) => this.onSelectFile( media ), onError: ( message ) => { @@ -149,7 +148,6 @@ class FileEdit extends Component { notices={ noticeUI } onError={ noticeOperations.createErrorNotice } accept="*" - type="*" /> ); } @@ -174,7 +172,6 @@ class FileEdit extends Component { ( { setAttributes( { @@ -168,7 +169,7 @@ class GalleryEdit extends Component { img.id ) } @@ -199,7 +200,7 @@ class GalleryEdit extends Component { } } onSelect={ this.onSelectImages } accept="image/*" - type="image" + allowedTypes={ ALLOWED_MEDIA_TYPES } multiple notices={ noticeUI } onError={ noticeOperations.createErrorNotice } diff --git a/packages/block-library/src/gallery/index.js b/packages/block-library/src/gallery/index.js index 835e85e2b32f42..332a6ac5fd3268 100644 --- a/packages/block-library/src/gallery/index.js +++ b/packages/block-library/src/gallery/index.js @@ -136,7 +136,7 @@ export const settings = { mediaUpload( { filesList: files, onFileChange: ( images ) => onChange( block.clientId, { images } ), - allowedType: 'image', + allowedTypes: [ 'image' ], } ); return block; }, diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 77bd51c8c81740..d54638785f3e74 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -54,6 +54,7 @@ const LINK_DESTINATION_NONE = 'none'; const LINK_DESTINATION_MEDIA = 'media'; const LINK_DESTINATION_ATTACHMENT = 'attachment'; const LINK_DESTINATION_CUSTOM = 'custom'; +const ALLOWED_MEDIA_TYPES = [ 'image' ]; class ImageEdit extends Component { constructor() { @@ -88,7 +89,7 @@ class ImageEdit extends Component { onFileChange: ( [ image ] ) => { setAttributes( { ...image } ); }, - allowedType: 'image', + allowedTypes: ALLOWED_MEDIA_TYPES, } ); } } @@ -221,7 +222,7 @@ class ImageEdit extends Component { ( ); diff --git a/packages/block-library/src/video/edit.js b/packages/block-library/src/video/edit.js index 295f3c0abcd18e..7158496b1a4e28 100644 --- a/packages/block-library/src/video/edit.js +++ b/packages/block-library/src/video/edit.js @@ -24,6 +24,8 @@ import { } from '@wordpress/editor'; import { getBlobByURL } from '@wordpress/blob'; +const ALLOWED_MEDIA_TYPES = [ 'video' ]; + class VideoEdit extends Component { constructor() { super( ...arguments ); @@ -55,7 +57,7 @@ class VideoEdit extends Component { this.setState( { editing: true } ); noticeOperations.createErrorNotice( message ); }, - allowedType: 'video', + allowedTypes: ALLOWED_MEDIA_TYPES, } ); } } @@ -138,7 +140,7 @@ class VideoEdit extends Component { onSelect={ onSelectVideo } onSelectURL={ this.onSelectURL } accept="video/*" - type="video" + allowedTypes={ ALLOWED_MEDIA_TYPES } value={ this.props.attributes } notices={ noticeUI } onError={ noticeOperations.createErrorNotice } @@ -198,7 +200,7 @@ class VideoEdit extends Component { (