• Resolved devgroupejcl

    (@devgroupejcl)


    Hi,

    We have wrote a plugin that import data from a custom xml file and it has some images attach to this file.

    I was wondering how we could make every images that we upload with the sequence (wp_upload_bits, update_post_meta, wp_insert_attachment, wp_generate_attachment_metadata, wp_update_attachment_metadata) pass in imsanity plugin so every images gets resize and optimize automaticly?

    Yours

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter devgroupejcl

    (@devgroupejcl)

    I found the solution searching on the forum.

    For anyone who wish to upload images programmaticly and make it pass in imsanity.

    $targetPath =wp_upload_dir(); //4
    //$name – file | $ds – directory separator
    $targetFile = $targetPath[‘path’].$ds. $name;
    move_uploaded_file($tempFile,$targetFile); //works fine
    $params[‘type’] = image_type_to_mime_type(exif_imagetype($targetFile));

    $params[‘file’] = $targetFile;

    $params[‘url’] = $targetPath[‘url’].”/”.$name;
    imsanity_handle_upload($params);

    Plugin Author nosilver4u

    (@nosilver4u)

    Well done, that would certainly do it. Normally, Imsanity hooks onto the “wp_handle_upload” filter, so if you implement something using that function as well, it will work.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Import images with imsanity programmaticly’ is closed to new replies.