I wish to replicate the media selector library in my plugin:
(I’ve a button, I click on on this, the media library show, I choose pictures and add in a div under)
Once I choose one picture or a number of pictures the button "checked" show for every picture (in the fitting up nook).
These chosen pictures show properly in my div but when I click on once more on the media library button my chosen pictures are usually not checked.
I can not discover the javascript documentation who clarify how I get the chosen picture id permitting the library to outline these pictures as chosen.
I attempted to do this with the script in remark however plainly the script "media_selector_print_scripts" does not exist anymore.
the under script is positioned in a php file relying of principal php file of plugin.
/*operate media_selector_print_scripts() {
$my_saved_attachment_post_id = get_option( 'media_selector_attachment_id', 0 );
}
add_action( 'admin_footer', 'media_selector_print_scripts' );*/
var myplugin_media_upload;
//var wp_media_post_id = wp.media.mannequin.settings.submit.id; // Retailer the outdated id
//var set_to_post_id = <?php echo $my_saved_attachment_post_id; ?>; // Set this
$('#btnFiles').click on(operate(e) {
e.preventDefault();
if( myplugin_media_upload ) {
//myplugin_media_upload.uploader.uploader.param( 'post_id', set_to_post_id );
myplugin_media_upload.open();
return;
}/*else {
wp.media.mannequin.settings.submit.id = set_to_post_id;
}*/
myplugin_media_upload = wp.media.frames.file_frame = wp.media({
title:"Add a file",
a number of: true
});
myplugin_media_upload.on( 'choose', operate(){
var attachments = myplugin_media_upload.state().get('choice').map(
operate( attachment ) {
attachment.toJSON();
return attachment;
});
var i;
for (i = 0; i < attachments.size; ++i) {
$('#block_file').preprend(
'<img src="' +
attachments[i].attributes.url + '" class="getFile">'
);
}
});
myplugin_media_upload.open();
});