Support » Plugin: Media Sync » Enhancements?

  • Plugin Contributor Simon Kane


    I don’t see any way to contact you to request/collaborate regarding two enhancement ideas I have, so posting here.

    1. My task is to connect product photos to their WooCommerce product.
    From your side of the game, a new filter should be enough.
    “media_sync_file_import_complete” would be a first guess at a filter name.

    At the least, the attachment_id would be needed. The data array sent to wp_insert_attachment would be nice to have if available.

    I can find the product based on the file name just imported, and go from there (updating post_meta of the product). I would also update the wp_posts.post_parent value of the attachment to reflect the connection. Of course, I would provide you with this code so that you could increase your plugin’s functionality if you like.

    2. Allow regeneration of attachment_meta (and resized files) of already imported images. This can be handled in a couple of ways on the front-end, but the core would be the ability to update an existing ‘attachment’. This function should also call the filter mentioned above (or a similar one).

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author erolsk8


    Hi @simonkane, thanks for your interest and suggestions. I’m fine with keeping this conversation here. Maybe someone else will have more suggestions 🙂
    But in case you need it, this is my email:

    So in general, I’m trying to keep this plugin as simple as possible. Because I think that’s what most people need. And I don’t want to slow it down (which is already a problem in some cases) or break something.

    But adding some custom hook functions seems totally fine. There are already two filter hooks by the way (for skipping/ignoring files and setting custom post date).

    But isn’t a hook action ( more suitable for what you’re describing?

    In any case, if you prepare that code and I test it on my end, I’d be glad to add it to this plugin.

    Plugin Contributor Simon Kane



    Great! And before I forget, huge kudos for your extensive error checking code. Everyone should do this sort of thing, but it seems to be a lost art to “modern developers”.

    I have looked at filters vs. actions, and I think this fits better as a filter – which, while I don’t need it, allows for more control over the call to wp_update_attachment_metadata. Return an empty array and that indicates the filter handled it already. Could be useful for more complex handling where the user needs the metadata to be created before they can do other things, or even just add their own metadata to the returned array.

    If I am unclear with the above, it should be obvious when I send you the code – which will hit MediaSync.class.php at line 766. Fortunately, the wp_update_attachment_metadata call which follows is the last thing that function does, so it won’t require conditional code – just an early exit (return).

    I hope to have the code written and tested this weekend.

    We’ll discuss what I’m talking about with the other enhancement a bit later, as this one is the pressing need for the client project I’m on.

    Dear erolsk8!

    I would have a development suggestion. Using meda sync is a bit inconvenient because you can only specify the directory of images to put in the gallery in the settings / media sync space. It would be nice to specify this during media / media sync, because this way you don’t have to jump between menu items.
    The program is very good, I uploaded 8 years of photos via FTP, more than 3000 pieces and I was able to put them into the media in annual processing, 366 pictures at a time. Congratulations on your work.

    Plugin Author erolsk8


    Hey @simonkane, it all makes sense, but yes, I’ll understand it even better when I see the code.

    And all of that error checking didn’t exist until recently. But I was a bit tired of seeing “it doesn’t work” messages without much detail. So I went over the top to catch and display what actually happened (as close as possible).

    Plugin Author erolsk8


    Hi @hobbiasztalos, your suggestion makes sense, though I’m worried it might add too much clutter to the “scan page”. So I’d have to think about it.

    But as a temporary solution, you might try a different way to select a specific directory. You can just edit the URL to end with “&sub_dir=2020/09” for example. So to have something like this:


    Thank you, I’m really glad you’re finding this plugin useful.

    Thanks, I’ll try.

    In the meantime, I also had a new idea. This program is used by most people when they move their entries and images from another CMR to WP. There could also be a new menu item to review entries imported from, for example, XML, rewrite the URLs of the images in them to the URL of the imported image, and rewrite the title of the highlighted image in the entry. Imported entries include the title of the images on the old server, this can be searched well because it is different from the domain name of the current server. All you have to do is enter the name of the old server as the startup parameter and transfer it to the new domain address, complete with the path to the image. This would be a huge help for those who are moving their website.

    Plugin Contributor Simon Kane


    Your idea can very rapidly get very complex.
    There are many widely divergent storage methods used by other CMSs.
    Cross-system code maintenance isn’t just “double”, but exponential.
    Been there, done that, more than once. LOL

    From the plugin’s point of view, filter/action points make the most sense.

    I haven’t researched the existing ones beyond finding they didn’t fit my needs, but the one I am working on (written but not yet tested – see above), may be enough. It will allow for modifying the metadata, and the base attachment (wp_posts row) is already created, so could be directly modified by the filter code.

    I will be using it to connect the newly imported media file to existing items (pages and WooCommerce products) based on the filenames (which I have “controlled” for ease of doing this). Possibly that thought can help your needs.

    Plugin Author erolsk8


    Hey @hobbiasztalos, this seems like something that’s out of the scope for this plugin. And would probably be a separate plugin. But it reminds me of this:
    Not sure how good it is, but you can check it out.

    Also, I’m trying to keep it simple. And to be honest, I don’t really have much time next to my full-time job. And trust me, I have tons of ideas written down for this plugin, just waiting to be developed 🙂
    But thanks for the suggestions in any case.

    And if understood @simonkane correctly, to put it simply – it might be possible to achieve what you suggested with some custom code that’s tailored to that specific need and which sits somewhere on your website. So it doesn’t increase the complexity of this plugin. But that would of course require someone to do the coding.

    Plugin Contributor Simon Kane


    Having looked into the wp_posts and wp_post_meta table entries like post_excerpt, _wp_attachment_metadata, and _wp_attachment_image_alt, it becomes obvious that to use data from “some other CMS”, both a translation of the item name, and it’s location (which table), is needed. It gets very huge very quickly.

    I do note that the standard WordPress Import Tool has add-ons for some other CMSs for importing posts and such — but I see no mention of media files. Possibly there are dedicated plugins that can assist @hobbiasztalos.

    Meanwhile – I have the new filter written, and initial tests are A-OK. I am now off to write my site-specific code that uses it. While I am sure that the filter won’t need to be changed any, I have been wrong before, so I’m going to hold off sending it until I actually test the filter’s operation with the piece that uses the filter. 😉

    Plugin Contributor Simon Kane



    Check your email – I just sent a zip containing the enhanced MediaSync.class.php, and the relevant parts of my child-theme’s functions.php (as an example of why I need this filter).

    Plugin Author erolsk8


    For the record, since we continued in emails, the first enhancement is added to the 1.2.5 version. I mean it’s a filter (hook function) of this plugin, so all the magic happens externally.

    Thanks to Simon for providing the code and details.

    We’re staying in touch about other enhancements.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Enhancements?’ is closed to new replies.