Subscribe-API and localization with Polylang
-
Hi,
I’m working on a plugin for TNP that brings more flexible ways to subscribe to the newsletter system. In that stage, I also use Polylang to localize my website. TNP supports Polylang, since I can localize all the emails (i.e. welcome email, etc.), but it does not seem to work for the API. Since I don’t use the newsletter form of TNP, I rely on the API to be able to get or take the relevant information what language the user prefers.
Here is some example code to illustrate the problem:
$email = "[email protected]"; $name = "Foo Bar"; $result = TNP::subscribe([ 'email' => $email, 'name' => $name, 'status' => '' ]); if (is_wp_error($result)) { error_log($result->get_error_message()); }This code will add the subscription. TNP::subscribe() will not take any language argument, so I cannot enforce any localization. In result, the user will get the default english welcome email.
The API should be complete by allowing me to provide a language parameter. Can this be implemented in the next update? How can I bypass this issue now?
The second issue is that error messages aren’t localized either. So if you re-run this code after the user has been subscribed, this will log “Email address already exists” to the debug.log.
If the API would take an argument for the language and localize error messages that can be displayed to the user, this would be great.
The topic ‘Subscribe-API and localization with Polylang’ is closed to new replies.