Skip Navigation

[Resolved] use custom fields filters for notifications

This support ticket is created 7 years 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 17 replies, has 2 voices.

Last updated by Nicholas 7 years ago.

Assisted by: Nigel.

Author
Posts
#591892
Screen Shot 2017-11-22 at 7.20.57 AM.png

Tell us what you are trying to do?
Hello I am referring to the following documentation:

"When to use field conditions

Many sites with CRED implement ads and other paid-submission content. You might want to notify clients when their ads become ‘featured’. To do this, use custom fields filters for notifications.

You can set up notifications when custom fields change. For example, if you are using a custom field to indicate that an ad is featured, you can trigger notifications when that field is set or cleared.

Please note that you can not use complex fields for this kind of conditions. This includes the WYSIWYG and Multiple Lines fields."

Unfortunately there are no examples.

So on my site I have the following post field for (see screenshot).
I'd like to send an automatic e-mail notification to the author of the post when the dropdown changes from the automatically selected option "Vote" to "Donate"

The settings in CRED tell me to add a custom field first?

Please help.

Also I am using two CRED forms for the same post. One to create it and one to edit it.
I wan't to avoid sending e-mails twice. What's the best way to send automatic emails if you have both a create and edit form?

Furthermore in my case the user can choose to save the post as a draft or publish it for review like so:

 [cred_generic_field field='post_status' type='select' class='sfc-campaign-new-select' urlparam='']
                                        {
                                        "required":0,
                                        "validate_format":0,
                                        "default":["[wpv-post-status]"],
                                        "options":[
                                        {"value":"draft","label":"Save for later"},
                                        {"value":"pending","label":"Submit for review"}
                                        ]
                                        }
                                        [/cred_generic_field]

How do I send the right e-mail notification when he saved his post as a draft? and how do I send the right e-mail when he published it for review (pending)

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

Please let me know if there is more documentation, but that was the only thing I could find.

Regards,
Nick

#592167

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2017-11-22 at 15.21.54.png

Hi Nick

1. Where the form notification UI asks you to add a custom field, it means to specify which custom field will be monitored for changes.

So in the screenshot you can see I am adding a notification that will be sent when the value of the Types status custom field is changed to 1.

So, whenever a post is updated (in the backend or using a CRED form on the frontend) the custom field will be checked to see if it changed to match the condition you specify (e.g. = 1 in my example), and if so the notification will be sent.

2. In terms of which notification will be sent if you have a publish form and an edit form, the answer is whichever one was last used to update the post from the front end. If the post was published with a CRED form that notification will be used. If a post is edited with a CRED form, its notification will be used. What won't happen when the custom field changes is that both are sent.

3. This is possibly more complex, but perhaps not if you are already using the CRED API to set the post status when the form is submitted.

You can trigger a notification when the status *changes*. If you have a form to publish posts with a draft status then adding a notification which is triggered when the status changes to draft won't be triggered if your form submits the post with a draft status in the first case.

But, if your form submits the post with some other status, and then you use the cred_save_data hook—which runs after the post has been created—to modify the status based upon a field in your form, then that would imply a change in status and so should trigger the notification.

You can set up many notifications in the same form with different conditions.

#593071

Please don't close this ticket. I haven't had time yet to get back to it.
Regards,
Nick

#593266

Hello Nigel. Thank you for your thorough answer. This helped me a lot.
I was able to implement part 1) of my question and I understand part 2) better now. But what I still don't understand is when a notification is sent when a custom field changes. You said: "What won't happen when the custom field changes is that both are sent."
Does this mean the notification will be sent only one time regardless of the CRED form? (create or edit)
I guess that would make sense. But does that mean I have to create this notification only one time? Or do I need to set this notification up in both my CRED create and CRED edit form?

3) Yes so I am using the CRED API to set the post status when the form is submitted like so:

//set post status 98 & 216

	function customize_cred_form_98( $post_id, $form_data ){

	    if ( isset( $_POST['post_status'] ) ) {

	        $updates = array(
	            'ID'            =>   $post_id,
	            'post_status'   =>   $_POST['post_status']
	            );
	        wp_update_post( $updates );
	    }
	}
	add_action( 'cred_save_data_98', 'customize_cred_form_98', 10, 2 );
    add_action( 'cred_save_data_216', 'customize_cred_form_98', 10, 2 );

I would like to send the right notification depending on the status the user has selected

[cred_generic_field field='post_status' type='select' class='sfc-campaign-new-select' urlparam='']
                                       {
                                       "required":0,
                                       "validate_format":0,
                                       "default":["[wpv-post-status]"],
                                       "options":[
                                       {"value":"draft","label":"Save for later"},
                                       {"value":"pending","label":"Submit for review"}
                                       ]
                                       }
                                       [/cred_generic_field]

I.e.:
-"You saved your post as a draft" when the user saved the post as a draft
-"Your post is waiting to be reviewed. " when the user saved the post as pending

#593296

Is there a way to use conditional logic in my notification for this?

#593316

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Nick

Regarding your continued uncertainty over point 2, let me restate the key point so that hopefully it is clear:

If you have multiple forms which add the same conditional notification (e.g. a post and an edit form that check to see whether the same field is modified), only the notification of the mostly recently used form for that post with that condition will be sent. When you create a post with a post form, its notification will be in effect, until you edit the post with an edit form, at which time its notification will replace that of the post form and become effective.

Regarding your code, you have used this and the notification is not working?

If you look at the post in the back end is the status updated according to what was selected in the form?

#593318

Thank you Nigel. Everything is clear now regarding part 2) of my queston.

3) Yes exactly. The notification is not sent when I choose to save the post as a "draft" for example.

And yes the status is updated accordingly in the backend according to what I selected in the form.

For the notification I chose: "When post status changes to draft."
Should I choose "When submitting the form"??

#593324

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Nick

Just one more thing. If you update the status of the posts in the backend, e.g. to draft, does it trigger the notification you are expecting to be sent?

#593328

Yes that works.
However when the user submits the form it doesn't.
Should I work with conditional logic here then?

How do I display a conditional mail subject though depending on the status of the post.

#593332

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'll need to do some testing locally and I'll get back to you later when I've confirmed for myself what is expected to work.

#593334

Thanks Nigel.

#593502

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Nick

I did some testing and I found that if I used the cred_submit_complete hook instead of cred_save_data it worked.

Could you try the same? The arguments are the same...

#593578

Thank you. I'll test this out and will get back to you.

#593584

So I tested it and it works if the user saves the post as a pending review.
The notification is sent to the user.

However when the user saves is post as a draft no notification is send.
Do you know why that is?

Maybe because the status of content created or edited by this form is already set to draft?

Thanks,
Nick

#593783

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, that would be it, the status needs to change.

So in my test site the form is set so that the status is 'publish' when submitted. Then the code changes the status according to the select dropdown.