I wonder how I can add a file picker (the default wordpress librairy would be perfect) into my tinymce visual editor’s popup.
at the moment I have a field where I have to past the url of the picture, if I could add a button to pick a picture from my library instead, it would be great !
Here is what I have so far
editor.addButton('thumbnail', {
title: 'Thumbnail',
image: url+'/../images/icon-thumbnail.png',
onclick: function() {
// Open window
editor.windowManager.open({
title: 'Thumbnail',
width: 940,
height: 150,
body: [
//I have to change this line---------> {type: 'textbox', name: 'url', label: 'Media URL'},<----- Is there an option to put a filepicker here ?
{type: 'textbox', name: 'caption', label: 'Caption'},
{type: 'checkbox', name: 'lightbox', value: '1', label: 'Lightbox'}
],
onsubmit: function(e) {
if(e.data.url==''){
alert('you have to provide the media's URL');
e.stopPropagation();
e.preventDefault();
}else{
// Insert content when the window form is submitted
var shortCode = '[thumbnail url="'+e.data.url+'"';
if(e.data.caption != ''){
shortCode = shortCode+' caption="'+e.data.caption+'"';
}
if(e.data.lightbox){
shortCode = shortCode+' lightbox=true';
}
shortCode = shortCode+' ]';
editor.insertContent(shortCode);
}
}
});
}
});
You can read this useful article, this also may help.
I dont’t want to copy-paste the text from articles, but basically you have to create custom PHP function in your theme’s
functions.php
file which will handle media dialog display, and then include it withadd_action()
on eventadmin_print_scripts
.The last part is usage of some JavaScript and the uploader inside, like this: