Home Forums Newsletter Plugin Support wpml support

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #45659

    hi 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.php

    as 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’..?!



    i 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..?



    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 = [
        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 );
        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);

    i inserted
    $url = apply_filters( 'tnp_show_message_url', $url );

    and in my functions.php i wrote

    function 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 );
        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:

    <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 name="newsletter_subscription_template">
    <key name="template"/>

    under wpml > string translation two new domains will show up: admin_texts_newsletter and admin_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..



    hello support.
    would you please be so kind to at least respond in any way or even better: implement these filters..?
    k thx bye


    so 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 );
        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' )

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.