Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var file_frame;
- var wp_media_post_id;
- var set_to_post_id;
- var image_place;
- var id_place;
- jQuery( document ).ready( function( $ ) {
- wp_media_post_id = wp.media.model.settings.post.id;
- set_to_post_id = <?php echo $my_saved_attachment_post_id; ?>;
- jQuery( 'a.add_media' ).on( 'click', function() {
- wp.media.model.settings.post.id = wp_media_post_id;
- });
- jQuery("#aggiungi_immagine").click(function(){
- jQuery('.container-images').append(codice);
- // If the media frame already exists, reopen it.
- });
- });
- function cancella(button){
- jQuery(button).parent().remove();
- }
- function modifica(button){
- image_place = jQuery( button ).siblings(".image-preview-wrapper").children();
- id_place = jQuery( button ).siblings( '.image_attachment_id' );
- if ( file_frame ) {
- // Set the post ID to what we want
- file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
- // Open frame
- file_frame.open();
- return;
- } else {
- wp.media.model.settings.post.id = set_to_post_id;
- }
- file_frame = wp.media.frames.file_frame = wp.media({
- title: 'Select a image to upload',
- button: {
- text: 'Use this image',
- },
- multiple: false // Set to true to allow multiple files to be selected
- });
- file_frame.open();
- file_frame.on( 'select', function() {
- attachment = file_frame.state().get('selection').first().toJSON();
- image_place.attr( 'src', attachment.url ).css( 'width', 'auto' );
- id_place.val( attachment.id );
- wp.media.model.settings.post.id = wp_media_post_id;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement