• Hi Ben,

    How difficult would it be to get this working for image uploads from the frontend?

    Current frontend Jquery for attching files is this function:

    galleryPostFormatUploadImage: function(){
        var file_frame = "";
        jQuery(".dt-open-media-for-gallery-post").click(function(e) {
                e.preventDefault();
    
          // If the media frame already exists, reopen it.
            if ( file_frame ) {
              file_frame.open();
              return;
            }
    
            file_frame = wp.media.frames.file_frame = wp.media({
              multiple: true,
              title : "Upload / Select Media",
              button :{ text : "Insert Image" }
            });
    
            file_frame.on( 'select', function() {
              var attachments = file_frame.state().get('selection').toJSON();
              var holder = "";
    
              jQuery.each( attachments,function(key,value){
                var full = value.sizes.full.url,
                imageID = value.id,
                thumbnail =  value.sizes.thumbnail.url,
                name = value.name;
    
                holder += "<li class='gallery-thumb'>" +
                "<div class='gallery-thumb-holder'>" +
                "<img src='"+thumbnail+"'/>" +
                "</div>" +
                "<a class='mark-featured' data-property-id='"+imageID+"' href='#mark-featured'><i class='fa fa fa-star-o'></i></i></a>" +
                "<span class='dt-image-name' >"+name+"</span>" +
                "<input type='hidden' class='dt-image-name' name='items_name[]' value='"+name+"' />" +
                "<input type='hidden' name='items[]' value='"+full+"' />" +
                "<input type='hidden' name='items_thumbnail[]' value='"+thumbnail+"' />" +
                "<input type='hidden' name='items_id[]' value='"+imageID+"' />" +
                "<span class='remove_image' data-attachment-id='"+imageID+"'><i class='fa fa-times-circle'></i></span>" +
                "</li>";
              });
              jQuery("ul#dt-frontend-uploaded-filelist").append(holder);
            });
    
            file_frame.open();
    
        });

    And of course, wp_enqueue_media(); used prior.

    I would have assumed by using wp_media it would have attached automatically as it does backend, but no..

    Any help??

    PS: good luck with Master exam June
    https://www.ads-software.com/plugins/custom-upload-dir/

  • The topic ‘Working with frontend uploading and wp_media’ is closed to new replies.