Filters Document Media control by files attached to the current item.

This commit is contained in:
mateuswetah 2021-07-28 17:41:38 -03:00
parent 3057791a6b
commit 6ec5f2873c
1 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,5 @@
export default { export default {
// AttachmentControl: requires upload of new files and accepts multiple files
attachmentControl: wp.customize.MediaControl.extend({ attachmentControl: wp.customize.MediaControl.extend({
/** /**
@ -189,6 +189,7 @@ export default {
} }
}), }),
// CroppedImageControl, with presets for header dimensions // CroppedImageControl, with presets for header dimensions
headerImageControl: wp.customize.CroppedImageControl.extend({ headerImageControl: wp.customize.CroppedImageControl.extend({
@ -286,6 +287,7 @@ export default {
} }
}), }),
// DocumentFileControl: similar to attachment, but used for items where the documents is of type file // DocumentFileControl: similar to attachment, but used for items where the documents is of type file
documentFileControl: wp.customize.MediaControl.extend({ documentFileControl: wp.customize.MediaControl.extend({
/** /**
@ -294,8 +296,11 @@ export default {
initFrame: function() { initFrame: function() {
wp.media.view.settings.post = { wp.media.view.settings.post = {
id: this.params.relatedPostId id: parseInt(this.params.relatedPostId),
wp_customize: 'off'
} }
wp.media.model.settings.post.nonce = this.params.nonce;
wp.media.model.settings.post.id = parseInt(this.params.relatedPostId);
this.frame = wp.media({ this.frame = wp.media({
button: { button: {
@ -305,11 +310,18 @@ export default {
states: [ states: [
new wp.media.controller.Library({ new wp.media.controller.Library({
title: this.params.button_labels.frame_title, title: this.params.button_labels.frame_title,
library: wp.media.query({ library: wp.media.query({
uploadedTo: null uploadedTo: wp.media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC',
posts_per_page: -1,
query: true
}), }),
autoSelect: true,
multiple: false, multiple: false,
date: false, date: false,
sortable: true,
filterable: 'unattached',
uploadedTo: this.params.relatedPostId uploadedTo: this.params.relatedPostId
}) })
] ]