Can someone help me create custom tab in WordPress media library. With WordPress version 4 i used to media_upload_tabs
function to build that nice work. But now, in WordPress version 5 the function is not working.
1 Answer
The only way I could get this to work in WP 5 was to install the Classic Editor.
Then I could use media_view_settings to add the tab.
add_filter('media_view_settings', 'addMediaTab');
function addMediaTab($settings) {
$settings['tabs'] = array('mymediatab' => 'My Media Tab');
return $settings;
}
BUT it appears the new UI doesn’t include those sections in Gutenberg, you will end up with something like this if you use the Classic Editor.
You can also do this with JS.
var Library = wp.media.controller.Library;
var oldMediaFrame = wp.media.view.MediaFrame.Post;
wp.media.view.MediaFrame.Post = oldMediaFrame.extend({
initialize: function () {
oldMediaFrame.prototype.initialize.apply(this, arguments);
var options = this.options;
this.states.add([
new Library({
id: 'inserts',
title: 'My New Tab',
priority: 20,
toolbar: 'main-insert',
filterable: 'all',
library: wp.media.query(options.library),
multiple: false,
editable: false,
library: wp.media.query(_.defaults({
newtab: 'newtab',
}, options.library)),
displaySettings: true,
displayUserSettings: true
}),
]);
},
});
More Info
Ticket with more info about Media_upload_tabs & WP5
JS Demo Example