-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
editorMediaUpload
, which includes post
context for uplo…
…ads (#6231) * Introduce `editorMediaUpload`, which includes `post` context for uploads * Update media blocks to use `editorMediaUpload` and persist `post` * `mediaUpload()` doesn't return anything * Add JSDoc for function * Use an abstraction that permits passing additional data in request * Mention why this conditional is here
- Loading branch information
1 parent
97cb15d
commit f53590a
Showing
7 changed files
with
46 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { select } from '@wordpress/data'; | ||
import { mediaUpload } from '@wordpress/utils'; | ||
|
||
/** | ||
* Upload a media file when the file upload button is activated. | ||
* Wrapper around mediaUpload() that injects the current post ID. | ||
* | ||
* @param {Array} filesList List of files. | ||
* @param {Function} onFileChange Function to be called each time a file or a temporary representation of the file is available. | ||
* @param {string} allowedType The type of media that can be uploaded. | ||
*/ | ||
export default function editorMediaUpload( filesList, onFileChange, allowedType ) { | ||
let postId = null; | ||
// Editor isn't guaranteed in block context. | ||
if ( select( 'core/editor' ) ) { | ||
postId = select( 'core/editor' ).getCurrentPostId(); | ||
} | ||
mediaUpload( filesList, onFileChange, allowedType, { | ||
post: postId, | ||
} ); | ||
} |
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
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
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
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
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
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