Thank you for contacting WPML support. While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with the first debugging steps or if I can help with the issue quickly.
I understand that the add_attachment hook (https://developer.wordpress.org/reference/hooks/add_attachment/) is only triggered for the original language's attachment after uploading it in the media library. You believe it should be triggered for every attachment in every language.
Hi Ahmed - that's correct! I am a developer for a plugin that uses the "add_attachment" hook to automatically generate alternative text for images when they are added. So my goal is to make sure our plugin is notified whenever new images are created so that we can call our service to generate alt text. WPML is only notifying on the original image, not any of the translations.
Thank you for contacting WPML support, I'd be happy to help you with this issue.
I can see that issue on my demo site. I think there is a workaround by using the filter hook "wpml_object_id" to get the translation attachment ID. For example:
Hi - the problem is I do not know ahead of time the language to use. And the site may have more than one language.
Is it possible to get a list of *ALL* translations of the attachment inside the "add_attachment" handler? I tried using wpml_post_duplicates() (https://wpml.org/wpml-hook/wpml_post_duplicates/) but this just returns an empty array.
The filter "wpml_post_duplicates" works when you duplicate a post/page into second languages. It does not work with media items in this case.
the problem is I do not know ahead of time the language to use. And the site may have more than one language.
Then you can use the filter hook "wpml_active_languages" to get all active languages on your site and use the filter hook "wpml_object_id" above to get translation attachment ID based on the languages.
Refer to the documentation https://wpml.org/wpml-hook/wpml_active_languages/
Look forward to your reply.
Thanks
The topic ‘[Closed] add_attachment not called when media is duplicated’ is closed to new replies.