I have to run some code <b>after an image is inserted into media library</b> (so after a post of an attachment post type is save) but <b>before thumbnails are generated</b>. I also need to know what ACF field has triggered the upload because I have to save the ACF key into attachment meta (don’t ask why, please ;)).
So, in order to do that, I can’t rely on any ACF hook (no, I can’t use the acf/upload_prefilter hook because at this stage an attachment doesn’t exist yet), but I can use a WordPress add_attachment hook.
That’s good, but as it’s a WordPress hook, not an ACF hook, I do not have an access to the ACF field key through the filter parameters. But I do have an access to the ACF field kay through PHP $_POST global:
Nice, it solves my problem, but can I really rely on the _acfuploader variable? It’s not a part of the ACF API, so I’m afraid that this value might change in future and this change will not be documented.
I cannot really answer this question. You should probably contact the developer to get an answer to that and the best way to do that is to submit a support ticket https://support.advancedcustomfields.com/new-ticket/ or to email him directly if you have is email address.
I can say that I’ve been using that $_POST variable for a long time. It’s the only way to know what field a file/image is for during the WP upload process. I use this value to determine the save path of the image in my upload prefilters. ACF also uses this value to set the correct image field after the upload. While this is just a guess, I don’t see that variable going anywhere in the near future.