Thank you for your patience while I worked on a new MLA example plugin to meet your requirements. I am happy to report that I have an initial version you can experiment with and give me your feedback.
I decided that the best solution within the MLA context would be to make the WFU File Data available as a custom data source/substitution parameter. This approach makes the results useful for MLA’s mapping rules, bulk editing, shortcode display and so forth. The new example plugin lets you convert the WFU values to more useful formats and values by writing “conversion rules”. You can find detailed information in the Settings/MLA WFU Data Documentation tab, but I will outline an example.
As you know, WFU stores ckeckbox data as text “true” or “false” values, which is not very useful for your application. You wrote “I want to add the blackcolor tag to the uploaded picture when the “black” check box is “true”.” Another way to state the requirement is “I want to convert one or more checkboxes to term names and assign them to uploaded pictures”. The example plugin does the conversion, and an MLA mapping rule does the assignments.
First, define the conversion rules in the new example plugin:
Colors,element(black,blackcolor,' ')
Colors,element(white,whitecolor,' ')
Colors,list(',')
The element rules have three arguments; the WFU File Data label (“black,white”), the “true” value (“blackcolor,whitecolor”) and the optional false” value (‘ ‘, the empty value). The list rule provides an optional delimiter between the list elements. The three rules create a new data source named “Colors” that will contain all of the non-empty values in the element rules separated by the delimiter. So, if both boxes are checked for an upload, the “Colors” list will contain “blackcolor,whitecolor”.
Second, define an IPTC/EXIF mapping rule that uses the new data source to assign terms to uploaded items:
- Go to the Settings/Media Library Assistant IPTC/EXIF tab.
- If you want to apply the rule to new items as they are uploaded, check the “Enable IPTC/EXIF Mapping when adding new media” and “Enable IPTC/EXIF Mapping when updating media metadata” boxes.
- Find the rule name that corresponds to the taxonomy you are using, e.g., Att. Tags
- Hover over the rule name and click the “Edit” rollover action.
- In the “IPTC Value” dropdown control leave the default, “- None (select a value) -” value in place.
- In the “EXIF/Template Value” text box, enter
template:([+wfu:Colors+])
. This assigns the terms named in the new data source.
- In the “Priority” dropdown, select “EXIF”.
- In the “Existing Text” dropdown, select “Replace” to replace the current field content, or select “Keep” to retain any terms assigned by other means.
- In the “Status” text box, select “Active”.
- Scroll down to the bottom of the screen and click “Update”.
Once you define the rule you can update existing pictures by applying it to a single item, multiple items or all items:
- To map a single item, go to the Media/Assistant submenu and click the thumbnail of the item you want (or click the “Edit” rollover action) to get the Media/Edit Media screen. You can click the “Map IPTC/EXIF metadata” link to run your rules on this item, then look at the “Menu Order” text box to inspect the results.
- To map two or more items, go to the Media/Assistant submenu and click the checkbox next to the items you want. Then, select “Edit” from the “Bulk Actions” dropdown above the checkboxes and click “Apply” to open the Bulk Edit area. Click the “Map IPTC/EXIF metadata” button to run your rule on the selected items.
- To map all of your items, stay on the Settings/Media Library Assistant IPTC/EXIF tab and click the “Execute” rollover action for your custom rule. This may take a while.
The first two methods will apply all active IPTC/EXIF rules to the selected item(s). This won’t be a problem if you have only the one rule, but the third method might be the best if you have other rules in place.
I have uploaded a new MLA Development Version dated 20220717 that contains the new example plugin. You can find step-by-step instructions for using the Development Version in this earlier topic:
PHP Warning on media upload with Polylang
Once the Development Version is installed you must install and activate the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “WFU” in the text box and click “Search Plugins” to filter the table.
You are looking for the “MLA WFU Data Source” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate the example plugin as you would any other plugin. Make sure you have the latest version, 1.00, installed.
Once the Development Version and new example plugin are installed and active you can navigate to the Settings/MLA WFU Data admin screen and configure the plugin for your application. You will find a Documentation tab with quite a bit of instructions and information. I would be very interested in any suggestions you have about the documentation content.
This example plugin will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and the example plugin and let me know if it works for you. Thanks for inspiring this MLA improvement.
NOTE: I am traveling next week and will not be able to post any updates until I return.