• Resolved shemakeswebsites

    (@shemakeswebsites)


    Hi, I’m having an issue with a duplicate notification that is being sent on a “pending” status of a custom type posting. My site is still in development stages so it’s not accessible by the public. Please help.

    Thank you.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter shemakeswebsites

    (@shemakeswebsites)

    Hello again, I think I figured something out. My theme adds another status : ‘pending approval’ to my posts. I think this is somehow causing a conflict. How do I get the plugin to recognized all status options available?

    Thank you.

    Plugin Author bnfw

    (@voltronik)

    Hi @shemakeswebsites,
    Thanks for your message.

    Custom post statuses aren’t available within BNFW yet unfortunately. At this time, it’s limited to the notifications available. You should be able to use the standard ‘pending’ status though, if that helps.

    Thread Starter shemakeswebsites

    (@shemakeswebsites)

    Yes, I am able to use the ‘pending’ status, but the problem is that two emails are being triggered. Any ideas? Not sure how I could get you my login credentials as there is no ‘private’ options for this forum.

    Thank you for always being so prompt.

    Plugin Author bnfw

    (@voltronik)

    Hi @shemakeswebsites,
    How are you triggering the notifications? Is this via the WP Admin or via a front-end form?

    Thread Starter shemakeswebsites

    (@shemakeswebsites)

    Hi Jack,

    I’m back. Unfortunately, it’s not been resolved.

    So my user does not have publishing capabilities. The theme I’m using is using a modified version of WP Jobs, so it uses front-end submission options. Upon submission, the post goes into pending status and is published by admin.

    According to my email log, two emails are submitted to the author to notify them of the pending submission. They are triggered at the exact same time. When I turn off better notifications, no emails are being sent – not even from my theme or any WP notifications.

    Plugin Author bnfw

    (@voltronik)

    Hi @shemakeswebsites,
    How are you triggering the notification? Are you using a front-end form or the WP Admin?
    If you’re triggering from a front-end form, can you please take a look at this document and see if it helps?

    Additionally, it might be worth installing the Post SMTP plugin to improve email delivery.

    Let me know how you get on.

    Thread Starter shemakeswebsites

    (@shemakeswebsites)

    Hi, adding that snippet generates four emails. So it’s being duplicated again.

    The theme I’m using is using a modified version of WP Jobs, so it uses front-end submission options. I also have SMPT setup.

    Plugin Author bnfw

    (@voltronik)

    Hi @shemakeswebsites,
    I think the issue is that the theme is conflicting, most likely due to a wp_update_post hook somewhere in there. I don’t think there’s anything we can do in this situation however because this hook doesn’t provide any post status transitions and so won’t allow us to trigger notifications correctly.

    The only two suggestions I have are:
    1. Try another theme
    2. See if you can modify the theme to fit your needs

    Thread Starter shemakeswebsites

    (@shemakeswebsites)

    Hello again. I have reported back to the theme author and this is what was suggested. Is this something that can be done to address the problem?

    “I am not familiar with this plugin but if the problem is with wp_update_hook then the plugin author can use a global variable to store the updated post ids so he can stop the functionality if the hook is being triggered multiple times.”

    Plugin Author bnfw

    (@voltronik)

    Thanks @shemakeswebsites,
    Let me do some investigation and see what I can do.

    Just throwing my situation in here, as its the closest to my issue as I can find.

    I want to create this plugin correctly, so I’m asking direction.
    I have a simple form (title, post, cat) and on $post I am literally only doing this:

    $post_status = "pending";
    $articleToPost = array(
    'post_title' => $post_title,
    'post_content' => $post_content,
    'post_category' => $cat,
    'post_status' => $post_status, 
    'post_type' => $post_type,);
    $theId = wp_insert_post($articleToPost); 

    And I am getting two notifications. I’ve tried:
    add_filter( 'bnfw_trigger_insert_post', '__return_true' );

    I’ve even tried using wp_update_post

    I’ve even tried doing manual post transitions using wp_transition_post_status

    I’ve seen you mention not creating plugins right in previous duplicate email threads, but what exactly is the correct way of adding an article to only generate one notification via a plugin?

    Note: I do not get duplicates in admin.

    I’ve been trying to pair this down to the bare minimum in order to figure it out.

    • This reply was modified 6 years, 5 months ago by wadethefade.
    • This reply was modified 6 years, 5 months ago by wadethefade.
    Plugin Author bnfw

    (@voltronik)

    Hi @wadethefade,

    Can you try adding your code to a function and then adding do_action( "{$old_status}_to_{$new_status}", $post ); at the end of the function (changing the old and new post status variables, of course) and seeing if this helps? You should be able to use wp_insert_post but this must be coupled with transitioning the post through the correct statuses in order for BNFW to be able to trigger a notification for it.

    Plugin Author bnfw

    (@voltronik)

    @wadethefade,

    Perhaps something like this?

    
    function bnfw_add_post() {
        $post_status = "pending";
        $articleToPost = array(
            'post_title' => $post_title,
            'post_content' => $post_content,
            'post_category' => $cat,
            'post_status' => $post_status,
            'post_type' => $post_type,
        );
    
        $post_id = wp_insert_post($articleToPost);
        $post = get_post( $post_id );
    
        do_action( "draft_to_{$post_status}", $post );
    }
    
    • This reply was modified 6 years, 5 months ago by bnfw.

    I think I tried something similar, but let me see about this. I know I’ve read that bnfw uses transition hooks to fire…

    Oh I have also tried – inserting the post as draft with wp_insert_post and then doing a wp_update_post that had this directly after it:
    wp_transition_post_status( 'pending', $old_status, $postToStatus );

    And… I just tried your suggestion: nope, I expected to get a 2nd round of duplicates.. but no change. I still get duplicate emails.

    $theId = wp_insert_post($articleToPost); 
    $postToTransition = get_post( $theId );
    do_action( "draft_to_{$post_status}", $postToTransition );

    WAIT.

    THAT DID IT. I guess I had all the pieces but didn’t have them put together at the right times.

    I also never thought about querying the post back out with get_post before updating it.

    This gives me a single notification:

    
    $articleToPost = array(
    'post_title' => $post_title,
    'post_content' => $post_content,
    'post_category' => $cat, 
    'post_status' => "draft", 
    'post_type' => $post_type 
    );
    $theId = wp_insert_post($articleToPost); 
    $postToTransition = get_post( $theId );
    wp_transition_post_status( 'pending', $post_status, $postToTransition );
    

    Thanks for the prompt replies

    • This reply was modified 6 years, 5 months ago by wadethefade.
Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Duplicate Notifications’ is closed to new replies.