• Resolved finnj

    (@finnj)


    Hi,

    Notifications only fire if status is changed from draft to publish

    If you publish immediately, the post will have auto-draft status.

    I fixed this by adding this in line 95 in bnfw.php:

    add_action( 'auto-draft_to_publish' , array( $this, 'publish_post' ) );

    Let me know if you will implement this change.

    Thanks

    PS – I really like your plugin. Reason why I did 3 post instead of one, was to make it easier for you to work with this.

    https://www.ads-software.com/plugins/bnfw/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author bnfw

    (@voltronik)

    Hi finnj,

    Using auto-draft_to_publish instead of draft_to_publish is something we’ve covered in a support thread before. See here for details: https://www.ads-software.com/support/topic/plugin-better-notifications-for-wordpress-suggestion?replies=9

    We found in testing that it triggered notifications all the time for various post types, such as the ones used in plugins, so it wasn’t ideal.

    I’ve tested this and using draft_to_publish works well for publishing new posts and posts from custom post types.

    Does this help answer your question?

    Thanks,
    Jack

    Thread Starter finnj

    (@finnj)

    Hi,

    Problem is that draft_to_publish do not fire always. I am using this with Frontier Post (I am the author of the plugin), and there are several use cases where where neither auto-draft_to_publish and draft_to_publish works. I have several users that using using pending status, and then the post is published from this.

    They way I have solved this for notifications (email to author when a post is published by admin):

    function frontier_email_on_transition(  $new_status, $old_status, $post )
    	{
    
        if( $post->post_type !== 'post' )
            return;    //Don't touch anything that's not a post (i.e. ignore links and attachments etc. )
    
        //If some variety of a draft is being published, dispatch an email
        if(  $old_status != 'pending'  && $new_status == 'pending' && fp_get_option("fps_mail_to_approve", "false") == "true")
    		{
    		$author_name	= get_the_author_meta( 'display_name', $post->post_author );
            $to      		= get_option("frontier_post_mail_address") ? fp_get_option("fps_mail_address") : get_settings("admin_email");
            $subject 		= __("Post for approval from", "frontier-post").": ".$author_name ." (".get_bloginfo( "name" ).")";
            $body    		= 		__("Post for approval from", "frontier-post").": ".$author_name ." (".get_bloginfo( "name" ).")"."\r\n\r\n";
    		$body    		= $body."Title:: ".$post->post_title."\r\n\r\n";
    		$body    		= $body."Link to approvals: ".site_url('/wp-admin/edit.php?post_status=pending&post_type=post')."\r\n\r\n";
    
    		//error_log('sending email: '.$subject.' To: '.$to);
    
            if( !wp_mail($to, $subject, $body ) )
    			error_log(__("Message delivery failed - Recipient: (", "frontier-post").$to.")");
    
    		}
    
    	if(  $old_status == 'pending'  && $new_status == 'publish' && fp_get_option("fps_mail_approved", "false") == "true"  )
    		{
    		if ( $post->post_author == get_current_user_id() )
    			return; // no reason to send email if current user is able to publish :)
    
    		$to      		= get_the_author_meta( 'email', $post->post_author );
            $subject 		= __("Your post has been approved", "frontier-post")." (".get_bloginfo( "name" ).")";
            $body    		= __("Your post has been approved", "frontier-post").": ".$post->title ." (".get_bloginfo( "name" ).")"."\r\n\r\n";
    		$body    		= $body."Title:: ".$post->post_title."\r\n\r\n";
    
    		//error_log('sending email: '.$subject.' To: '.$to);
    
            if( !wp_mail($to, $subject, $body ) )
    			error_log(__("Message delivery failed - Recipient: (", "frontier-post").$to.")");
    
    		}
    	}
    
    add_action('transition_post_status', 'frontier_email_on_transition', 10, 3);

    The above is different than what is needed in your plugin – a suggestion could be to change the trigger to:

    function xx_email_on_transition(  $new_status, $old_status, $post )
    	{
    
        if( $post->post_type !== 'post' )
            return;    //Don't touch anything that's not a post (i.e. ignore links and attachments etc. )
    
    	if(  $old_status != 'publish'  && $new_status == 'publish'  )
    		{
    		// add code that build the notifications		}
    	}
    
    add_action('transition_post_status', 'xx_email_on_transition', 10, 3);

    Plugin Author bnfw

    (@voltronik)

    Hi finnj,

    Ok, so the reason for this in BNFW is that a number of plugins use variations of the publish hook and if you have notifications set-up for these, they can trigger a lot. auto-draft_to_publish for example, can fire when things are saved and you don’t want random email notifications going out to your users. In extensive testing, the way BNFW is now is the most robust that i’ve found.

    If BNFW is to work with a large range of other plugins, a better solution needs to be found for trying to deal with all of the variations of this hook that are used.

    On it’s own and with handfuls of other plugins, BNFW works very well and notifications are sent out as expected. On the other hand, there are a lot of plugins that BNFW won’t work well with out-of-the-box.

    I am always investigating better ways for BNFW to integrate with other plugins but until I find a solution that I feel is a bit more all-encompassing, I can’t provide support on a per-plugin basis – it just isn’t a feasible use of my time and instead, I would prefer to spend it developing new features and fixing bugs.

    Hope that explains my position a bit and what the future might hold for better 3rd-party plugin integration.

    Many thanks,
    Jack

    Thread Starter finnj

    (@finnj)

    Hi,

    I respect that you are carefull with implementing features that can impact the core plugin.

    Random (or unexpected) email should be always be avoided.

    And I dont expect you to do a specific integration for Frontier Post. I believe my request does not relate to Frontier Post alone.

    I can see the auto-draft_to_publish isn’t a good approach,

    What I suggest is for BNFW to send a notification once a post is published, and only once. In other words, when the post is changing status to publish (from any other status) a notification should be sent – so the designated reciepients is notfied at the same time as the post goes live on the site.

    I have had several users who has looked for a notification plugin, and BNFW is by far the best alternative, only challenge is that with multible authors publishing content from the frontend, it is impossible to ensur that they remember to save the post to status draft first, and then publish. I could force an extra save from auto-draft to draft as workaround, but I dont like adding records without it is absolutely neccessary.

    I will see if I can come up with a better suggestion, and test it, before suggesting a change.

    I like the the logic and simplicity of BNFW, and I do not want to suggest rocket science that doesn’t make sense in the long run ??

    Plugin Author bnfw

    (@voltronik)

    Hi finnj,
    Thanks for this. I appreciate your input and thoughts on the issue.

    I think sending something out only when something is published regardless or where the hook originated would be a good solution. I’ll look to integrate something in the near future after sufficient testing.

    Thanks,
    Jack

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘No notfications from auto-draft’ is closed to new replies.