Skip Navigation

[Resolved] Notifications not going out in language of original post

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 35 replies, has 3 voices.

Last updated by simonM-5 2 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1954485

Hi Support

We have Toolset post forms that create a Job Ad post or a Nanny Ad post.

On the form, we set a notification to remind the user in the future that the Ad is about to expire (for example, we want the posts to be 6 months valid and the user to receive a notification 30 days before expiry, around the end of the 5th month).

The notifications are translated into German correctly with WPML, I believe, but the notifications are going out twice in English.

I can understand the logic of why the notification goes out twice (once from the English post, and once from the translated German post. This is not really desirable, but according to previous Toolset and WPML tickets we have opened, it is unavoidable, due to how WPML works). We can live with the notification going out in German and in English, but we don't understand why both notifications are going out in English, if the translations are correctly maintained in String Translation.

Interestingly, the first notification that goes out to tell the user their Ad was created successfully, goes out only once, and only in the language in which the user created the Ad, be it our primary language (English) or our secondary language (German).

How can we ensure the user gets an expiry reminder in German, if the original post was created in German?

Thanks and regards
Simon

#1955603

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot and suggest the best way to achieve this, I'll need to perform some tests on my server.

Do I have your permission to download a clone/snapshot of your website for this testing?
( the Duplicator plugin is already installed )

regards,
Waqar

#1955717

HI Waqar

Of course you may! Please deactivate WordFence once the clone is complete, otherwise we get licence warning emails.

Thanks and best regards
Simon

#1962485

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the permission and I've downloaded the duplicator package.

I'll be performing some tests and will keep you updated on my findings.

Thank you for your patience.

#1970187

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting.

I've performed some tests on my test website as well as the clone of your website, but, I couldn't reproduce this issue on my test website. A form notification set to expired before X amount of time is sent only once and in the language that was used to create the associated post.

Here are the steps that I've used:

1. I created a form to add a new post that expires in 10 minutes and set two notifications:
a). The first is sent at the time of form submission
b). The second is sent 5 minutes before the expiry

2. I added this form to a page in default primary language English and then created a translated copy of the page in German too.

3. After that I added two posts through this form, using the page in English and German, each. As expected the notifications set to be sent on submission, were received right away.

4. After the set time, I also received only two more notifications in the correct language 5 minutes before expiry.

Can you please share the exact steps that you're using for testing on your development website? I have the clone on my server and will test accordingly if that is still reproducible.

#1970311

Good morning Waqar

Thanks for that.

Your steps are basically what I have done on our website.

To reproduce on your clone of our site, you would just follow these steps:

1) Click "Become a Native Nanny" and fill in all the required fields. Only addresses in Germany are possible in the maps part. A new user will be created in the back end with role "Unverified Nanny". You need to change that user's role to "Native Nanny" to enable all functionality for the newly created user.

2) Switch to the German site, and click the Ad icon in the menu bar, and click "Nanny-Anzeige erstellen" (Place a Nanny Ad), making sure to enter something in all the required fields.

3) On submission you should get a notification to the email address of the new Nanny.

4) When you submit, there is Toolset provided custom code on our site ("func-create-ad-language-duplicates-on-submission"), which copies the Ad to all other other languages, so if you create in German, an English duplicate will be produced and vice versa. (We were told on previous tickets that this was necessary, though it has the unfortunate side-effect of having two posts all the time, which is a shame, but necessary due to how WPML works apparently.) Interestingly, when the language duplicate is created, which is a post in its own right, it doesn't send its own notification either. 🤷🏻‍♂️

5) Depending on what the settings are for the reminder notification time is set to, you will receive two notifications, both in English, instead of one in German and one in English.

On this point, from another ticket (https://toolset.com/forums/topic/email-notifications-not-being-sent-for-expiring-posts/) we deduced that when Toolset and WPML are the only active plugins on the site, there are only 4 options available for post expiration settings under Toolset > Settings > Forms > Other > Post expiration > Check for expired posts. The other options come from other plugins (eg 5 minutes options coming from WooCommerce plugins). In my opinion this is a bug and should be fixed by Toolset to show only the options relating to its own plugin and hide the others created by other plugins. (The shortest option coming from the Toolset plugin is "Once Hourly".)

6) Even if you set the reminder to remind you 2 mins after creation by calculating the number of minutes or seconds, the lowest setting is 1 hour for the server to run its cron job "cred_post_expiration_event" looking for expired posts, so you may have to wait for an hour before you get notifications.

I hope this is easy to follow, please let me know if anything is unclear.

Thanks and regards
Simon

#1974313

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing these steps.

I noticed that the pages and forms included in these steps are not available in the clone that I had downloaded earlier. Have you made changes to these pages recently?

Initially, I thought that the custom code to automatically make duplicated language posts ( snippet: func-create-ad-language-duplicates-on-submission ) is responsible for the repeated notifications, but even if I use that same code on my test website, it successfully creates a duplicated posts, but the expiry notifications are sent only once.

This investigation is tricky because it is a complex website, with a number of custom code snippets, however, I've downloaded the latest clone and I'll see if I can narrow it down to the root cause and suggest some workaround accordingly.

Thank you for your patience.

#1974571

Hi Waqar

No problem. That's curious that those forms/pages etc weren't present in your clone before, we haven't removed them and they've been a core part of our site for a long time.

Anyways, please feel free to make as many clones as you need. Please just remember to deactivate the WordFence plugin on each new clone, otherwise we get licence issues with WordFence. Good luck with your investigations! 😉

Kind regards
Simon

#1980561

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting as this investigation took longer than I initially anticipated.

The challenge was that for some reason the duplicate clone of the website didn't carry over the form notifications, fields, and page contents as it is and I had to manually re-create them by looking into your dev website.

During testing, I was able to use the "cred_notification_recipients" filter to avoid the duplicated post expiry notification.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

Example:


add_filter('cred_notification_recipients', 'avoid_duplicate_expire_notification_921', 10, 4);
function avoid_duplicate_expire_notification_921($recipients, $notification, $form_id, $post_id) {
	if( 
		( $notification['event']['type'] == 'expiration_date' ) 
		&& 
		( $form_id == 921 ) 
		&& 
		( !empty(get_post_meta( $post_id, '_icl_lang_duplicate_of', true )) ) 
	) {
		$recipients = array();
	}

	return $recipients;
}

The above code checks if the current notification is for the post-expiration event, related to the form with ID 921 ('Post Form - New Nanny Ad') and is for the post which is a duplicated language post of an original post. If all these conditions are met, it removes the recipients, making the notification unsendable.

I hope this helps.

#1980809

Hi Waqar

Thanks very much for this.

1) Now that you mention that about the duplicator not copying some forms and notifications, it reminded me that the same thing happened to me when I migrated from our .com domain to our .de domain. Some of our forms had to be manually updated after migration. Is this a Toolset bug or a Duplicator bug?

2) Would it be possible to adjust the code above to add the form IDs to an array, so I only have one code snippet which covers Nanny Ads and Job Ads? I'm just not sure of what the exact syntax would be, but it would seem sensible to me to run it all under one code snippet.

The two form IDs would be:
New Nanny Ad (921)
New Job Ad (929)

Thanks and best regards
Simon

#1980889

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

1) Since, we haven't seen this issue when migrating Toolset Forms through the Duplicator plugin on other websites, it seems something specific to your website is involved.

Even the simple page content that is added using Avada's page builder is not carried over properly.

I'll recommend performing a test migration and then share the log with the Duplicator plugin's support team for further analysis.

2) To extend the snippet for the multiple forms, you can use the "in_array" function.
( ref: hidden link )


add_filter('cred_notification_recipients', 'avoid_duplicate_expire_notification', 10, 4);
function avoid_duplicate_expire_notification($recipients, $notification, $form_id, $post_id) {
	$target_forms = array(921, 929);
	if( 
		( $notification['event']['type'] == 'expiration_date' ) 
		&& 
		( in_array($form_id, $target_forms) ) 
		&& 
		( !empty(get_post_meta( $post_id, '_icl_lang_duplicate_of', true )) ) 
	) {
		$recipients = array();
	}

	return $recipients;
}

#1980903

Hi Waqar

Thanks.

I have implemented the code and we are testing it on our site. It may take a little while as we need to wait an hour or so for the server to run through and check if it has to send any notifications after creating the new Ads.

I will update you in the next 1-2 days after we have tested thoroughly from both languages.

Thanks and regards
Simon

#1980965

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Sure please take your time.

#1983585

Hi Waqar

Our tests have shown that the notifications are still not going out correctly despite implementing your code. It looks like still both going out twice in English - no German versions have appeared in our mailboxes yet, even from Ads created in German.

To narrow the problem down, I have added the post title to the expiry notifications for Nanny Ads, and added "EN" or "DE" to the title in a couple of new Nanny Ads. I have also reduced the times drastically for testing for Nanny Ads so we get notifications within the hour. I'll update you later today with further results.

Kind regards
Simon

#1983653

HI Waqar

Further to my previous update, I have installed the handy plugin "WP Control" and am using it to run the cron job "cred_post_expiration_event" manually, which greatly accelerates testing. (WP Admin > Tools > Cron Events)

I set the Nanny Ads to expire in 2 hours (120 Minutes) and then set the expiration notification to be sent out 118 minutes before expiry.

I ran the cron job "cred_post_expiration_event" manually after 3 minuntes and it sent out one notification, however still in English, for Ads created in German.

Furthermore, the expiry notification is not including the user's first name or the title as specified in the notification.
-------
Hi [wpv-user field="user_firstname"]

One of your Nanny Ads will expire in 30 days.
Title: [wpv-post-title]
-------

The same code for the user name works in the first notification which is sent out when the Ad is created, and the user is addressed correctly.

Thanks and regards
Simon

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.