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: [email protected]
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 (https://developer.ww.wp.xz.cn/reference/functions/do_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.
Howdy!
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.
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).
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:
/wp-admin/upload.php?page=media-sync-page&scan_files=1&sub_dir=2020/10
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.
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.
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:
https://ww.wp.xz.cn/plugins/moving-media-library/
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.
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. π
@erolsk8
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).
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.