pivot
Forum Replies Created
-
It works!! ?? Thank you so much, David! This is really awesome work and great service. I am so thank for creating MLA and for your dedication to improve this already awesome plugin. You can probably close this topic now. And, have a great day!
Thank you @dglingren
As usual you are great at following up on support-cases and eager to help out. A much appreciated quality!
Unfortunately these changes you added in the new development version didn’t solve the problem, and the custom mapping is still not triggered when adding new media through the Bulk Media Eegister cron plugin.
I will send you an email now!
@dglingren hanks for following up on this!
Its an add-on for the plugin I mention here: https://www.ads-software.com/support/topic/unable-to-map-attachment-file-metadata-such-as-pngdream/#post-16769114
its a premium plugin with a one time fee, and it makes the Bulk Media Register plugin capable of being triggered by cron, command line, watchdog or similar bash execution.
But, unfortunately the MLA_AJAX_EXCEPTIONS didn’t work for the premium add-on, only for the base plugin, so when its triggered by the bash command “php /var/www/wp-content/plugins/bulk-media-register-add-on-wpcron/lib/bmrcroncli.php” it doesn’t trigger the same functions as the base plugin..
I can send you the plugin by e-mail and yo can have a look?
For example, if you just want to run mapping for one or a few new items and you know their IDs, I can adjust my solution.
Yes, that would be optimal. But, at the moment I am not sure how to fetch this, because the command “php /var/www/wp-content/plugins/bulk-media-register-add-on-wpcron/lib/bmrcroncli.php” runs silently. If you find anything in the code for it that I can use then that’s great, and I could also contact the plugin author to ask (but from the plugin settings I cannot see any simple way of fetching this when running the command)
so, in addition to having the watchdog trigger the execution of mapping rules there could be other ways too:
hooking on to the bulk-media-register-add-on-wpcron/lib/bmrcroncli.php script
or “simply” writing a new function/plugin that watch for some relevant hook (or action?) and then triggering the custom fields mapping. this could be a whole range of things, I’m sure, but it would possibly be something related to the internal processes of wordpress registering new media to the media library
I’m thinking that this might also introduce another benefit: not needing to execute custom field mapping for every single image, but instead trigger it for only the new media (or the ones missing)…right?
I have looked at various automation plugins for wordpress too but they are all way overkill for what I need at the moment, and figuring out how to use them could be a bigger task than just figuring out a code for a php script ??
- This reply was modified 1 year, 5 months ago by pivot.
@bernardberry646 no worries ??
at the moment I have a “watchdog” monitoring /var/www/wp-contents/uploads directory (inotify-hookable). whenever changes happen (new file uploaded, changed metadata in a file, file deleted, etc) it will trigger a command.
right now the watchdog trigger 2 commands every time a change happens:
1. php /var/www/wp-content/plugins/bulk-media-register-add-on-wpcron/lib/bmrcroncli.php (a plugin I use to add new files to media library if they dont exists already)
2. wp media delete-missing (add-on for wp-cli that I use to delete any media in media library that doesn’t have a source file in /var/www/wp-content/uploads)with this I am able to always keep my wordpress media library in sync with a source folder on another host. I am able to sync metadata to various custom fields in wordpress by manually executing the rulles from MLA backend, but so far I have not been able to fully automate it.
@bernardberry646 any suggestions?
Thanks for your reply!
That’s ok, I solved my primary need by using this add-on for wp-cli: https://github.com/unapersona/wp-cli-delete-missing-attachments/blob/main/README.md
And I could potentially use this add-on if that need arises: https://github.com/wpup/wp-cli-media-restore
The wp-cli routine I have automated, but I will still use your plugin for manual processing.
@bernardberry646 nope. I can also execute a php script through regular command line (linux bash)
Thank you, David. I’m looking forward to it! Im looking at both “wp media import” and “wp media regenerate” as possible candidates to also trigger MLA custom field mapping
PS: wp-cli is not an absolute requirement, it can be some other command line method also. I can trigger a php script through command line by executing “php <location of script>” too, and as far as I know its possible to make sure all wp functions and plugin functions are loaded and available for the php-script by setting require to location of wp-load.php.
Thank you for your reply!
Yes, i did find that topic, but unfortunately I didn’t find the actual solution for the issue.
I have also looked over both the example plugins during these last days, and I’ve been pulling my hair out in frustration for not understanding how I am going to actually “use” them… I have edited php and various functions in WordPress for many years, when needed, but for some reason I always struggle with seeing the logic of it all. And in the end I’m just happy with getting something to work, without properly understanding “why” it worked (or admit defeat and try to put it aside and forget about it).
I guess my coding-gene is not properly activated ??
can you give me an example of a php script that trigger the “execute all rules” function found in the custom fields mapping?
If I have a php script that I can trigger from the cli with something like “php customfieldmapping.php” I could easily have it triggered by cron, a watchdog and similar
Tryng to learn (although this doesn’t work):
Could I trigger execution of mapping existing custom fields function by f.ex “php customfieldmapping.php” in wp-content dir?
<?PHP require_once(explode("wp-content", __FILE__)[0] . "wp-load.php"); do_action('mla_mapping_settings', 'rating', '5449', 'custom_field_mapping', ''); ?>
Or, of course: trigger a php-function directly from the command line.
Maybe something like “mla_begin_mapping” or “mla_mapping_custom_value”?You, sir, are a legend. Thank you, that worked great!
I managed to map various values from the PNG files to its respective custom field (ACF) like this:I have done this for “png:Dream”, “png:sd-metadata” and even for “xmp:xmp.Rating” which XnView writes to the PNG files when I rate the image.
I am sure that I can map all kinds of metadata using this method, and splitting them into various custom fields gives me a lot of possibilities for using those to filter and search the images in the future.
I have a couple of follow-up questions that are connected to this:
- Is there some formula or method for processing the metadata further when mapping them to custom fields? For example: Can I “format” template so that it will only take out “model_id” from png:sd-metadata and place it in the referenced custom field?
- Is it possible to trigger the execution of all rules from CLI, or maybe a php-script? I am using a plugin called “Bulk Media Register” to add new png-files found in /wp-content/uploads (automatically uploaded using sftp) but it seems that this won’t trigger the required wp hooks or functions to also trigger mapping rules in MLA. A solution might be to trigger it through a watchdog, or just by cron, to make sure all new images are mapped.
- How would I create a [mla_gallery] that look up any image with a png:Dream metadata that contains the word “Photohelper”?
I have a few more questions that might be better to open new support-threads for, but I can mention them here just in case you see it beneficial to answer them in this thread instead:
- Is it possible to make [mla_gallery] responsive? Right now I only found a way to set a defined number of columns, so for phone-screens the thumbnails will be too small and for large screens they will be too big.
- I plan on using Elementor for some of the functionalities available there, like star-rating populated by the number found in a custom field, and possibility to define rules for what fields are displayed where. Is it possible to integrate MLA with Elementor, for example by having MLA populate the images for a dynamic gallery in Elementor?
- Im assuming this is well outside of the scope of MLA, but when observing your skill-level and willingness to help us users I feel inclined to ask: Is it possible to use MLA to write metadata back to the PNG files?
Again, thank you for this amazing plugin of yours! It truly is like a magic wand for my rather special user case.
D
Now I only need to figure out how to get this solution of hijacking the query to work with “related posts” too.
Any suggestions?
I figured it out myself. A short code is needed in functions.php (or add to your plugin) to hijack the wp_query and set certain arguments that are preventing attachments to be listed:
https://wordpress.stackexchange.com/questions/29635/how-to-create-an-attachments-archive-with-working-paginationI needed the is_category and is_tag too, like in this post: https://wordpress.stackexchange.com/questions/187629/creating-attachments-archive-in-tags-and-categories