• Resolved tezalsec

    (@tezalsec)


    Hi again,

    I am trying to override some texts in your emails, but for some reason the variables do not get replaced.

    In below example, {username} does not get replaced with the actual value. Do you have any hint why it is not getting replaced?

    function my_new_user_approve_approve_user_message() {
    
    	$message .= "Hi {username}\r\n\r\n";
    	return $message;
    }
    add_filter('new_user_approve_approve_user_message', 'my_new_user_approve_approve_user_message');

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tezalsec

    (@tezalsec)

    After some research, it looks like you made it impossible to use apply_filters for editing messages containing smart tags, as you translate the smart tags before the filter, instead of after.

    Is this a deliberate choice? If you would just apply your nua_do_email_tags() function AFTER the filter instead of before, the smart tags would get translated.

    In your function ‘approve_user’ for instance, all you would have to do, is place the following code below instead of above the filter ‘new_user_approve_approve_user_message’ :

    $message = nua_do_email_tags( $message, array(
                'context'    => 'approve_user',
                'user'       => $user,
                'user_login' => $user_login,
                'user_email' => $user_email,
            ) );

    This is like 5 seconds of work..

    Thanks.

    PS. I got that I missed adding the $message parameter in the example code in the above post, but that was not causing this issue.

    • This reply was modified 2 years, 12 months ago by tezalsec.

    Hi @tezalsec,

    We have tested on our staging site, the default tags work fine without needing to do any changes. If somehow they are not working on your site. you can customize the message and add custom tags using this code.

    add_filter('new_user_approve_approve_user_message_default', 'nua_custom_approve_message', 20);
    
    function nua_custom_approve_message($message) {
        $message = "Hi {username_custom}\r\n\r\n";
        $message .= __( 'You have been approved to access {sitename_custom}', 'new-user-approve' ) . "\r\n\r\n";
    	
    	return $message;
    }

    and you can add the value for the custom tag using this filter.

    add_filter('new_user_approve_approve_user_message', 'nua_replace_tags_in_approve_message', 20, 2);
    
    function nua_replace_tags_in_approve_message( $message, $user) {
        $message = str_replace('{username_custom}', $user->user_login, $message);
        $message = str_replace('{sitename_custom}', 'Test Site' , $message);
    	return $message;
    }

    Thanks

    Thread Starter tezalsec

    (@tezalsec)

    Hi, thank you for your response, and your alternative solution, I really appreciate it. However, I stand by my point that it does not work correctly.

    Your example refers to your default message, not your overriding message. I get that it works on your default message, as your code suggests that it does. Look however at the order of the handling of functions in your new-user-approve.php file, around line 670.

    First the default message is set, then the tags are replaced. So that means it works fine for your default message, as your test suggests. To test this issue, your test should have been done not on the default, but on the overriding filter that follows the translation function.

    See your code below:

    
    $message = nua_default_approve_user_message();
    $message = nua_do_email_tags( $message, array(
                'context'    => 'approve_user',
                'user'       => $user,
                'user_login' => $user_login,
                'user_email' => $user_email,
    ) );
    $message = apply_filters( 'new_user_approve_approve_user_message', $message, $user );

    In the last line the overriding filter ‘new_user_approve_approve_user_message’ is applied, but AFTER the tag replacement function, so the tags do not get translated.

    Simply shifting the order of the code would solve this, like I tested:

    
    $message = nua_default_approve_user_message();
    $message = apply_filters( 'new_user_approve_approve_user_message', $message, $user );
    $message = nua_do_email_tags( $message, array(
                'context'    => 'approve_user',
                'user'       => $user,
                'user_login' => $user_login,
                'user_email' => $user_email,
    ) );

    In this order both the default and the overriding filter tags get replaced.

    I had already solved it for myself by repeating the nua_do_email_tags() function within my filter function, that worked, but it is not clean and no option for non-programmers, and it does not address the base issue.

    I hope you will take a look at it again.

    Thanks.

    • This reply was modified 2 years, 11 months ago by tezalsec.
    • This reply was modified 2 years, 11 months ago by tezalsec.
    • This reply was modified 2 years, 11 months ago by tezalsec.
    • This reply was modified 2 years, 11 months ago by tezalsec.

    Hi @tezalsec,

    Thank you for your suggestion, We have forwarded it to our technical team. If the changes are approved we will release them in our upcoming version.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Merge tag variables not being replaced’ is closed to new replies.