• Hi,

    Post Author receives 2 emails when new_comment_posted and options[notify_authors] is checked in Admin.

    So when a user posts a new comment, function new_comment_posted() is called. [ wp_subscribe_reloaded.php : L263 ]

    Here is your process

    STEP 1 : notify subscribers
    —————————

    [ wp_subscribe_reloaded.php : L343 ] – loop subscribers
    [ wp_subscribe_reloaded.php : L344 ] – skip the user who posted this new comment
    [ wp_subscribe_reloaded.php : L345 ] – notify_user

    STEP 2 : notify post author
    —————————

    [ wp_subscribe_reloaded.php : L351 ] – If the case, notify the author
    [ wp_subscribe_reloaded.php : L360 ] – notify_user

    Here is the issue,
    In fact Post Author is in the subscriber list. So he was already notified, we dont have to notify him again ( notify_authors option is checked )

    FIX :
    —–
    Do Step 2 before Step 1 and use a flag in Step 2 to inform that Author was already notified.

    HERE THE CODE :
    ————–

    
    // ADD AUTHOR FLAG NOTIFICATION
    $isAuthorNotified = false;
    
    // If the case, notify the author (  MOVE THIS BEFORE ) 
    if ( get_option( 'subscribe_reloaded_notify_authors', 'no' ) == 'yes' ) {
    	
    	$post_author_id = get_post_field( 'post_author', $info->comment_post_ID );
    	$post_author_data = get_userdata( $post_author_id );
    	$post_author_email = $post_author_data->user_email;
    
    	// send email to author unless the author made the comment
    	if ( $info->comment_author_email != $post_author_email ) {
    		$this->notify_user( $info->comment_post_ID, $post_author_email, $_comment_ID );
    		// AUTHOR IS NOTIFIED
    		$isAuthorNotified = true;
    	}
    }
    
    // Send a notification to all the users subscribed to this post
    if ( $info->comment_approved == 1 ) {
    	$subscriptions = $this->get_subscriptions(
    		array(
    			'post_id',
    			'status'
    		), array(
    		'equals',
    		'equals'
    	), array(
    			$info->comment_post_ID,
    			'Y'
    		)
    	);
    	// Now verify if the comments has a parent comment, if so, then this comment is a reply.
    	if ( ! empty( $info->comment_parent ) ) {
    		$subscriptions = array_merge(
    			$subscriptions, $this->get_subscriptions(
    			'parent', 'equals', array(
    				$info->comment_parent,
    				$info->comment_post_ID
    			)
    		)
    		);
    	}
    
    	foreach ( $subscriptions as $a_subscription ) {
    		// Skip the user who posted this new comment
    		if ( $a_subscription->email != $info->comment_author_email ) {
    		
    			// CHECK IF SUBSCRIBER IS AUTHOR
    			if ( $a_subscription->email == $post_author_email && $isAuthorNotified ) {
    				// AUTHOR IS ALREADY NOTIFIED
    			}else{
    				$this->notify_user( $info->comment_post_ID, $a_subscription->email, $_comment_ID );
    			}
    		}
    	}
    }

    Do you think, is it a good thing or not ?

    Take Care,

    jfpwork@gmail.com with periwinkle.fr

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Post Author receives 2 emails’ is closed to new replies.