Support » Plugin: Notification - Custom Notifications and Alerts for WordPress » Double Notificaton email on ‘Post Update’

  • Resolved vkj1215

    (@vkj1215)


    I’m using this plugin for notification on post update. Each time the post is updated 2 emails are being received mostly at the same time ( very rarely relayed by 1-2 mins). Using the latest version or wordpress and plugin (5.3.2). Please help.

    • This topic was modified 2 years, 4 months ago by vkj1215.
Viewing 6 replies - 16 through 21 (of 21 total)
  • Okay, i’m testing the following code and not getting any notification. FWIW, when i create a post via the admin UI it works.

    
    add_action( 'notification/trigger/registered', function( $trigger ) {
    
    	// Check if registered Trigger is the one we need.
    	// Adjust the "trip" if this is not your CPT slug.
    	if ( 'wordpress/trip/pending' !== $trigger->get_slug() ) {
    		return;
    	}
    
    	// Add your action.
    	$trigger->add_action( 'trip_saved_notification', 10, 3 );
    
    });
    
    add_action( 'acf/save_post', function( $post_id ) {
    
    	if ( 'trip' !== get_post_type( $post_id ) ) {
    		return;
    	}
    
    	// @link https://wordpress.org/support/topic/double-notificaton-email-on-post-update/#post-11153857
    	do_action( 'trip_saved_notification', 'pending', get_post_status( $post_id ), get_post( $post_id ) );
    
    }, 30 );
    

    Why doesn’t the default “Review” notification trigger when using acf_form() to create the post?

    I tried digging through Notifications code on GitHub but not sure how it’s triggered. I was assuming you hooked into save_post or similar, so regardless of how the post was created it would trigger a notification.

    I love the plugin and really just want to understand what is all happening so I can extend it accordingly.

    I was also just expecting it to send an email without any code since a Trip (CPT) is created with the status of ‘pending’, and that’s what my Notification is setup to do.

    Plugin Author Kuba Mikita

    (@kubitomakita)

    Ahh, it’s all probably related to postponing. If you hook into acf/save_post action, it’s too late. See: https://github.com/BracketSpace/Notification/blob/develop/class/Integration/CustomFields.php

    I apologize for keeping this going, I’m just not understanding. There’s 2 questions at play here I think.

    1. If I use wp_insert_post() or wp_update_post() (or since acf_form() is using this), why aren’t the triggers fired? Everything works with no code if I create/edit a ‘pending’ post of my CPT, but it doesn’t when inserting/updating via code.

    2. If question 1 is how it is intended to work, can you give an example of how to manually trigger the Reviewed (pending) or any other similar trigger in my code? The plugin has a lot of filters/actions but it’s not clear to me how to do it. Notifications seems like a super powerful plugin for devs too, it’s just not clear to me how to do it.

    Even my basic example from above is not doing anything.

    Actually, if I use wp_insert_post() directly to ‘pending’ status, it does trigger correctly. Hmmmm.

    Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi @jivedig, sorry for the delay.

    1. It’s not working because of the actions you are using. Your ACF Form handler is either called to early or too late so the Notification plugin is not picking it up.

    2. I’m thinking… why can’t you setup the post status directly in the acf_form()?

    If I use acf_form() directly to the status we need it does work. We had some other workflow happening post status change from draft to pending, but we can rework it. Everything will work fine out of the box for Notifications if we go right to pending status via acf_form().

    Thanks for your help, and thanks again for such a cool plugin.

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Double Notificaton email on ‘Post Update’’ is closed to new replies.