Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. var file_frame;
  2. var wp_media_post_id;
  3. var set_to_post_id;
  4.  
  5. var image_place;
  6. var id_place;
  7.  
  8. jQuery( document ).ready( function( $ ) {
  9. wp_media_post_id = wp.media.model.settings.post.id;
  10. set_to_post_id = <?php echo $my_saved_attachment_post_id; ?>;
  11.  
  12.  
  13. jQuery( 'a.add_media' ).on( 'click', function() {
  14. wp.media.model.settings.post.id = wp_media_post_id;
  15. });
  16.  
  17. jQuery("#aggiungi_immagine").click(function(){
  18. jQuery('.container-images').append(codice);
  19. // If the media frame already exists, reopen it.
  20. });
  21.  
  22.  
  23. });
  24.  
  25. function cancella(button){
  26. jQuery(button).parent().remove();
  27. }
  28.  
  29. function modifica(button){
  30. image_place = jQuery( button ).siblings(".image-preview-wrapper").children();
  31. id_place = jQuery( button ).siblings( '.image_attachment_id' );
  32. if ( file_frame ) {
  33. // Set the post ID to what we want
  34. file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
  35. // Open frame
  36. file_frame.open();
  37. return;
  38. } else {
  39. wp.media.model.settings.post.id = set_to_post_id;
  40. }
  41.  
  42. file_frame = wp.media.frames.file_frame = wp.media({
  43. title: 'Select a image to upload',
  44. button: {
  45. text: 'Use this image',
  46. },
  47. multiple: false // Set to true to allow multiple files to be selected
  48. });
  49. file_frame.open();
  50.  
  51. file_frame.on( 'select', function() {
  52. attachment = file_frame.state().get('selection').first().toJSON();
  53. image_place.attr( 'src', attachment.url ).css( 'width', 'auto' );
  54. id_place.val( attachment.id );
  55. wp.media.model.settings.post.id = wp_media_post_id;
  56. });
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement