WordPress exposes media upload component globally, as well the featured image modal with wp.media.featuredImage
so developers can interact with it.
FeaturedImage component uses the wp.media.frame
which is a Backbone component, which has custom event attached to it.
There’s not much documentation on it, you can check the source here.
You can use the following snippet to achieve your needs.
It’s uses the open
event on media frame and set’s content mode to upload
, the default mode is browse
.
function wpse_391259_init_featured_uploader_tab() {
$script = <<<JSS
(function (){
var frame = wp.media.featuredImage.frame();
frame.on( 'open',function() {
frame.content.mode('upload')
});
})();
JSS;
wp_add_inline_script( 'media-editor', $script );
}
add_action( 'wp_enqueue_media', 'wpse_391259_init_featured_uploader_tab' );