Thanks for your positive feedback and for your question. Thanks as well for taking the time to dig through the Documentation and example plugin files.
You mentioned the “filter_media_modal_query_final_terms” filter, which I understand to mean that you are hooking the “mla_media_modal_query_final_terms” filter. Is that right?
You can programatically assign taxonomy terms and make other changes to newly-uploaded items by hooking MLA’s mla_update_attachment_metadata_prefilter
filter. Here is some code you can adapt to suit your application:
/**
* @param array attachment metadata
* @param integer The Post ID of the new/updated attachment
* @param array Processing options, e.g., 'is_upload'
*
* @return array updated attachment metadata
*/
function mla_update_attachment_metadata_prefilter_filter( $data, $post_id, $options ) {
if ( $options['is_upload'] ) {
// array of int = hierarchical, comma-delimited string = non-hierarchical.
$term_ids = array( 123, 456 );
$result = wp_set_post_terms( $post_id, $term_ids, 'attachment_category' );
}
}
You will have to change the $term_ids
values and perhaps the taxonomy name, but you get the idea. Be sure to read the Function Reference/wp set post terms to see how it works.
There are two ways a user can upload new items; the “Add Media” button on a post/page and the Media/Add New (Upload New Media) screen. If your users use the Media/Add New screen you may have to hook additional MLA filters because they can assign terms in the Bulk Edit area on that screen.
I hope that gives you the information you need to complete your application. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.
Ah, yes, I meant to say, I hooked into the “filter_media_modal_query_final_terms” filter.
I will experiment with this today, but based on your response it looks like this is precisely what I needed.
Thank you!
Sorry to bug, but I’ve been trying to get this filter to fire, and I’m having a bit of trouble.
I’m hooking into the mla_update_attachment_metadata_prefilter
and just trying to use the example error_log output, to see what I can modify, but I never see anything in my log file. I am assuming the filter should fire whenever a new item is uploaded, is that true? I’ve tried uploading from the media modal and from the Media/Add New screen and I’m still not getting any output.
Thanks!
Ok, I now realize that the mla_update_attachment_metadata_prefilter
is only firing on the Bulk Edit screen. What I’m really looking for is a way to modify uploads as they come in through the media modal, as that is the only way my users can upload items, at the moment.
Thanks again for your time.
Thanks for your updates and for your experiments with the filters.
The first thing to check is the settings on the Settings/Media Library Assistant Custom Field and IPTC/EXIF tabs. the
is only applied when at least one of the four “Enable mapping when adding new media/updating media metadata” options is checked, and the default setting for all four options is unchecked.
I just ran a quick test and the filter is called from the Upload Files tab of the Media Manager Modal (popup) Window when the mapping options are checked.
If that doesn’t solve the problem, any additional information you can provide will help my further investigation.
Thank you for your quick response.
After upgrading to version 2.22 from 2.21, I am now seeing that filter running on all upload screens as expected. Thanks again!
Thanks for your update and the good news about your success. I looked back at the v2.22 Chang Log and found this item:
* Fix: When new Media LIbrary items are uploaded via the Media Manager Modal (popup) Window, mapping rule execution has been restored.
I think that explains it!