Home › Forums › Newsletter Plugin Support › wpml support
- This topic has 4 replies, 1 voice, and was last updated 5 years, 11 months ago by
jnz.
-
AuthorPosts
-
September 21, 2017 at 7:27 pm #45659
jnz
Participanthi tnp!
i have an issue and it is in regard to the wpml issue.
i already digged a little and found a solution to translate the texts, but now i am stuck with the links, that this tool is sending out.
problem in my eyes is the function replace() inside plugin.phpas far as i see it, the problem is that this function is triggered too early, before wpml is loaded, so wpml is not able to filter
$home_url = home_url('/');
(line 1149). if wpml would have been loaded, it would have translated the home_url to the current language (http://example.com/%language_code%/something/something).
so do you see a chance, to register these functions later on, when wordpress triggers ‘plugins_loaded’..?!<3
September 21, 2017 at 7:30 pm #45664jnz
Participanti wonder, if this request makes any sense, since tnp is a plugin itself, but since this replace function might not be needed upfront, when the plugin is ready, maybe it is possible to trigger this particular part later on..?
September 27, 2017 at 4:49 pm #46278jnz
Participanthi.
i managed to transform the urls, but i had to hack the plugin for that.
here is, what i did:in file
plugin.php
in function replace_url i added a filter:
$text = apply_filters( 'tnp_replace_url', $text, $tag, $url );
right before the return statement.this is my filter i added to
functions.php
function jnz_tnp_replace_url( $text, $tag ) { $replace = [ 'SUBSCRIPTION_CONFIRM_URL', 'UNSUBSCRIPTION_CONFIRM_URL', 'UNSUBSCRIPTION_URL', 'FOLLOWUP_SUBSCRIPTION_URL', 'FOLLOWUP_UNSUBSCRIPTION_URL', 'PROFILE_URL', 'UNLOCK_URL', ]; if ( in_array( $tag, $replace ) ) : $newsletter_page = get_permalink( apply_filters( 'wpml_object_id', 81, 'page' ) ); if ( !strpos( $text, $newsletter_page ) ) : $text = str_replace( trailingslashit( site_url() ), $newsletter_page, $text ); endif; endif; return $text; } add_filter( 'tnp_replace_url', 'jnz_tnp_replace_url', 10, 2 );
the page_id (81) is the id of my newsletter page..
the strpos was a bit strange. if i left this out, the language code would be added each time, the function runs (7 iterations), so i had to check, if the url was already set.and then in file
subscription/subscription.php
i edited the function show_message. right before the end of the function:header('Location: ' . self::add_qs($url, 'nm=' . $key . '&nk=' . $user->id . '-' . $user->token, false) . $params); die();
i inserted
$url = apply_filters( 'tnp_show_message_url', $url );
and in my
functions.php
i wrotefunction jnz_tnp_show_message_url( $url ) { $wpml_home = apply_filters( 'wpml_home_url', get_option( 'home' ) ); if ( !strpos( $url, $wpml_home ) ) : $url = str_replace( trailingslashit( site_url() ), $wpml_home, $url ); endif; return $url; } add_filter( 'tnp_show_message_url', 'jnz_tnp_show_message_url', 10, 1 );
this gives me the correct urls, the correct redirects and therefore i now got translated emails, urls in emails and all texts proper.
here is the manual for translation the text, now also including the email template:
create a file called
wpml-config.xml
inside the newsletter plugin folder and include following code:
<wpml-config>
<admin-texts>
<key name="newsletter">
<key name="profile_text"/>
<key name="profile_email_changed"/>
<key name="profile_error"/>
<key name="confirmation_text"/>
<key name="confirmation_subject"/>
<key name="confirmation_message"/>
<key name="confirmed_text"/>
<key name="confirmed_subject"/>
<key name="confirmed_message"/>
<key name="unsubscription_text"/>
<key name="unsubscription_error_text"/>
<key name="unsubscribed_text"/>
<key name="unsubscribed_subject"/>
<key name="unsubscribed_message"/>
</key>
<key name="newsletter_subscription_template">
<key name="template"/>
</key>
</admin-texts>
</wpml-config>
under wpml > string translation two new domains will show up:
admin_texts_newsletter
andadmin_texts_newsletter_subscription_template
translate these and you are good to go.my plan is, to send out different lists do different languages. automated.
will test this next week, lets see how far i come..cheers
October 5, 2017 at 9:52 am #47217jnz
Participanthello support.
would you please be so kind to at least respond in any way or even better: implement these filters..?
k thx byeOctober 6, 2017 at 11:49 am #47394jnz
Participantso today i tested the mails and had some issues, but that was caused by my function
jnz_tnp_replace_url
. it was rewriting almost every url, also img pathes and post pathes etc. so new attempt:function jnz_tnp_replace_url( $text, $tag, $url ) { $parsed_url = parse_url ( $url ); if ( array_key_exists( 'query', $parsed_url ) && !empty( $parsed_url['query'] ) ) : $newsletter_page = get_permalink( apply_filters( 'wpml_object_id', 81, 'page' ) ); $newsletter_page_url = $newsletter_page . "?" . $parsed_url['query']; $text = str_replace( $url, $newsletter_page_url, $text ); endif; return $text; } add_filter( 'tnp_replace_url', 'jnz_tnp_replace_url', 10, 3 );
this function looks for urls with query strings, since all these settings urls of tnp are handled via these. i now only overwrite these specific urls.
works fine over here..as mentioned before, this page is the newsletter page i created, make sure u update this line for your own needs (81 is the ID of my newsletter page and wpml returns the translated ID):
apply_filters( 'wpml_object_id', 81, 'page' )
-
AuthorPosts
- You must be logged in to reply to this topic.