Skip Navigation

[Resolved] Posts created through Post Form that are in draft status still send emails

This thread is resolved. Here is a description of the problem and solution.

Problem:
Posts created with a Toolset Form that are set to expire send a warning notification ahead of the expiration.

If a post is trashed, how can those notifications be turned off?

Solution:
Details of the notification are stored in a hidden custom field '_cred_post_expiration_notifications', and this field can be deleted when a post is trashed, using the wp_trash_post hook.

Here's an example of such code:

function ts_remove_expiry_notification( $post_id ){
 
    $notification = get_post_meta( $post_id, '_cred_post_expiration_notifications' );
 
    if ( !empty( $notification ) ){
        delete_post_meta( $post_id, '_cred_post_expiration_notifications' );
    }
}
add_action( 'wp_trash_post', 'ts_remove_expiry_notification' );
This support ticket is created 5 years, 3 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.

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 6 replies, has 2 voices.

Last updated by daveG-7 5 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1322565

We have user posts created through a CRED post form that, when users choose to take them off the site, are turned to drafts so they can be reactivated later if need be. These posts have expiration dates set when they are created, and automatic emails sent when the expiration time nears. Posts that are drafts still send the automatic emails. Is there a way to stop this, so that emails are only sent from published posts?

#1322719

Nigel
Supporter

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

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

What's the process for users taking their posts offline (i.e. switching them to drafts)?

The solution I'm thinking of would be to remove the post expiration date automatically when that happens, so there is no email notification to send.

Would that work?

What would happen if the users re-activate posts? Should they have a post expiration (the same as before, or different)?

#1323235

We use the cred_delete_post_link shortcode (full code follows). It says the action is trash, but I know that somehow they're going to draft instead (we set this up a few years ago and I can't remember how exactly it works). Removing the post expiration when that happens would be just fine. The accounts are reactivated by admins, and that happens rarely, so they could just add an expiration back manually when it they reactivated the account.

[cred_delete_post_link class='cred-refresh-after-delete' text='Deactivate' message='Are you sure you want to deactivate this Land Seeker Listing? Note: if it says deleting it is not a problem, we will still have your post when you want to reactivate it.' message_after='Thank you for deactivating/deleting your post. To reactivate it, or if you have deleted it in error, please contact EMAIL REMOVED with the email address and user name of your account.' message_show='1' action='trash']

#1324167

Nigel
Supporter

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

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

If you are using that shortcode to trash the posts but they are actually being changed to draft it must be that you are already using some custom code to intervene in the process, which we could modify to wipe the post expiration date.

If you are sure that this is happening (i.e. posts are switched to draft instead of trashed) can you find the code that is used and share it with me? (Check your theme's functions.php, or any plugin used for adding custom PHP snippets.)

#1326591

It appears I was remembering incorrectly - they really are going to the trash, not being saved as drafts.

#1326805

Nigel
Supporter

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

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

OK, thanks for clarifying.

In which case I can see when creating a test with the same set-up that a hidden custom field is added to posts that manages the notification related to post expiration, so we can simply delete that rather than removing the expiration itself.

We can hook into when a post is trashed, then strip that hidden custom field if it exists.

Something like this should work:

function ts_remove_expiry_notification( $post_id ){

    $notification = get_post_meta( $post_id, '_cred_post_expiration_notifications' );

    if ( !empty( $notification ) ){
        delete_post_meta( $post_id, '_cred_post_expiration_notifications' );
    }
}
add_action( 'wp_trash_post', 'ts_remove_expiry_notification' );
#1327641

That seems like it should work. I'll mark this as resolved for now. Thanks!