Googling (or searching here) on "open" is hard :)
The readme for MediaUpload gives this example:
<MediaUpload
onSelect={ ( media ) => console.log( 'selected ' + media.length ) }
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ mediaId }
render={ ( { open } ) => (
<Button onClick={ open }>
Open Media Library
</Button>
) }
/>
And, indeed, in the MediaPlaceholder
core component it gets used that way:
<MediaUpload
// ...
render={ ( { open } ) => {
return (
<Button
isTertiary
onClick={ ( event ) => {
event.stopPropagation();
open();
} }
>
{ __( 'Media Library' ) }
</Button>
);
} }
/>
But I can't figure out what that "open()" is, where it's documented, etc....
If someone can point me at it, I'm happy to go read documentation and/or UTSL; but, in case there's a better way, or I'm barking up the wrong tree, what I'm actually trying to accomplish is to use the MediaPlaceholder in my new block, and have it open a specific directory (not the default uploads directory). I've looked at the upload_dir
and wp_handle_upload_prefilter
filters, which might work, but I can't figure out any way to only set them when they're called by clicking on my block. I've also considered adding a new REST endpoint and attaching that to the button, but ... it seems like there must be an easier way, so I thought I'd look at this open
function before I go down that path.