I have a wordpress plugin where I want to create a custom wp.media modal window for users to upload files from the front end. I want to show only the files that have been uploaded by current user. I am not sure where to start filtering this input. Here is my current javascript wp.media function. I am able to restrict library to a specific file type but I have no clue how to then filter by current_user.
function open_media_window() {
var upload = "";
if (this.window === undefined) {
if($(this).hasClass('bizimg-select')){
upload = "bizimg";
}
if($(this).hasClass('vcard-file')){
upload = "vcard";
}
if(upload=='bizimg'||upload==""){
this.window = wp.media({
title: 'Upload my Bizcard Bizimg',
library: {type: 'image/*',
uploadedTo : wp.media.view.settings.post.id},
multiple: false,
button: {text: 'Insert'}
});
}
if((upload=='vcard')){
this.window = wp.media({
title: 'Upload my Bizcard vCard',
library: {type: 'text/x-vcard'},
multiple: false,
button: {text: 'Insert'}
});
}
var self = this; // Needed to retrieve our variable in the anonymous function below
this.window.on('select', function() {
var files = self.window.state().get('selection').toArray();
var first = files[0].toJSON();
wp.media.editor.insert('[myshortcode id="' + first.id + '"]');
//populate selected-bizimg-file with file name
if(upload=='bizimg'){
//populate bizimg_post with post id
$('#bizimg_post').val(first["id"]);
if($('#selected-bizimg-file')){
$('#selected-bizimg-file').text(first['filename']);
}
if('img.bizimg'){
$('img.bizimg').attr("srcset", first['url']).attr("src", first['url']);
$('.bizimg-div').removeClass("border-blue");
}
}
//do the same for vcard
if(upload=='vcard'){
$('#vcard_post').val(first["id"]);
if($('#selected-vcard-file')){
$('#selected-vcard-file').text(first['filename']);
$('#vcard-raw-textarea').load(first['url']);
$('#vcard-upload').css('color','#df9e06');
$('.remove-file').removeClass('daisy-hidden');
}
}
});
}
this.window.open();
return false;
}
This was rather easy after digging awhile. I would like to attribute the answer to caldas who answered this in a previous question. wordpress show only media user has uploaded in wp_editor . If you think this is just a duplicate question, please flag. I thought it was unrelated as I was dealing with a custom wp media modal.