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.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.