Mar.13

Creating Custom Media Upload with user value

Creating Custom Media Upload with user value

Customizing WordPress Media :

wp.media({

});

function provide the option for stetting up the custom value on Upload light box screen.

I have customized the Upload preference up wordpress light box for uploading audio file with it suitable lable and command.

$(document).on(‘click’, ‘.pcs_audio_upload’, function() {
current = $(this);
var post_id = current.attr(‘data-post-id’);
if( null != current) {
var pkb_uploader = wp.media({
title: ‘Service News – Select Audio file only’,
button: {
text: ‘Set Audio’
},
multiple: false,
}).on(‘select’, function() {

var attachment = pkb_uploader.state().get(‘selection’).first().toJSON();
console.log(attachment);
var FileName = attachment.url;
var link = FileName.split(‘wp-content’);
var file_path = ‘/wp-content’+link[1];
$(‘.audio_open_file’).attr(‘href’,FileName);
$(“.audio_removeLinks”).show();
current.addClass(“file_exist”);
$(‘input#pcs_audio_upload’).val(file_path);
}).open();
}
return false;
});

And Next On update option of Upload button :

//Prepare frame
var frame = wp.media({
title : ‘Pick the images for this work’,
multiple : true,
library : { type : ‘image’},
button : { text : ‘Insert’ },
});
frame.on(‘close’,function() {
// get selections and save to hidden input plus other AJAX stuff etc.
var selection = frame.state().get(‘selection’);
console.log(selection[“_byId”]);
});
frame.on(‘open’,function() {
var selection = frame.state().get(‘selection’);

//Get ids array from
ids = jQuery(‘#<?php echo $this->id; ?>’).val().split(‘,’);
ids.forEach(function(id) {
attachment = wp.media.attachment(id);
attachment.fetch();
selection.add( attachment ? [ attachment ] : [] );
});
});
frame.open();

audio_add

 

Share this Story:
  • facebook
  • twitter
  • gplus

Leave a comment

Facebook Comment