• Resolved Alex Furr

    (@alexfurr)


    Hi,
    We’re using your plugin with the S3 offload media plugin
    https://deliciousbrains.com/wp-offload-media/

    When the files were stored locally this worked perfectly, but we seem to get a new file created, and therefore a new URL when using the two together. Is this a known issue?

    Best wishes,
    Alex Furr

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Gerard Blanco

    (@sixaxis)

    Hi Alex,

    EMR is not officially compatible with WP Offload Media, so it is expected to encounter some issues.

    We are working on releasing official support, although we have no ETA for now.

    Thank you for using EMR anyway!

    Thread Starter Alex Furr

    (@alexfurr)

    Thanks for the swift reply!

    we may have a tweak under the hood to get this working – do you have a custom hook you can recommend we look for to plug into?
    BW,
    Alex

    Plugin Support Gerard Blanco

    (@sixaxis)

    Alex, could you please tell us more details about that? What’s the intention, or what exactly you would like to modify to get this working?

    Thread Starter Alex Furr

    (@alexfurr)

    Hi no problem. We have a dev team who can look at this, but want to point them at an appropriate hook to get started.

    I would image we would create a plugin that extends your class.
    There would be a settings page where we add the S3 bucket details for the site buckets etc. On replacing a media file we bypass your upload and instead:
    a) Removes the old file from S3
    b) Adds the new file to the same location / folder and renames to the old file.

    Something simply like that. I say simple…. ??

    Plugin Author Pedro

    (@petredobrescu)

    Hello @alexfurr,

    Just as a start, we welcome Pull Requests on our public GitHub repo for such nice new features ??

    Coming back to your request, I believe you might achieve this on the current version of EMR because most of the things seem to be in place already.

    Just as a side reference, here’s how we have done the integration with WP Offload Media in our other plugin, SPIO: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser/blob/master/class/external/wp-offload-media.php

    The filesystem module can handle virtual (non-existent) files via a hook. In the SPIO implementation, it checks in the hook if the file is offloaded and returns true if so, then the file is regarded as existing.

    The hook + function in the above file to look at:
    add_filter(‘shortpixel/image/urltopath’, array($this, ‘checkIfOffloaded’), 10,2);

    In EMR both source and target files are built from the result of get_attached_file, which by default gets the unfiltered result. This should point to the file location where the file once was. If so, then this will work OK.

    Secondly, when replacing, the remote file should be removed (can be renamed, etc.) and there is a remove_remote function in the above file from SPIO.

    EMR fires a hook before starting the replacer – do_action(‘wp_handle_replace’, array(‘post_id’ => $post_id)); so it could be hooked into that.

    Note that the Offloading plugin doesn’t allow sending individual files. Everything is bundled as a Media Library item with an attachment ID. This means that anything there will be removed, the replaced file metadata should be regenerated and that result should be offloaded again. The code in replace.php aims to replace data in the installation to reflect changes and compensate for new/missing thumbnail filenames and dimensions.

    When all is done, EMR fires a done hook: do_action(“enable-media-replace-upload-done”, $this->target_url, $this->source_url, $this->post_id);

    This could be used to hook the image_upload function (above file) and offload the result.

    After implementing all this, it should be tested if everything works. Crucial variables are both the source_file and source_url generated by EMR in Replace.php construct (which could be tested easily by logging it) and checking if this mechanism works as intended in EMR.

    Again, this would make a very nice improvement through a PR and we can obviously continue the development discussion there.

    For any other questions, don’t hesitate to write to us!

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Compat with S3 offload media?’ is closed to new replies.