WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] plugging wp_notify_postauthor causes stall on wp-comment-post.php (2 posts)

  1. Branch
    Member
    Posted 5 years ago #

    I'm working on a plugin to do html notifications of comments that will work nicely with 2.7's threaded comments, and I'm running into a rather strange problem.

    The plugin works charmingly, does just what I want. Except that, whenever it is enabled and I post a new comment I don't get redirected back to the post page. Instead I wind up looking at a blank wp-comment-post.php page. The comment *is* posted. If I back-button and reload the page, it shows up. The notification even gets sent. I just can't get back to my post page, and any plugins that rely on the action hook 'comment_post' fail to activate.

    I've poked the code and tried subtracting all my added if statements, but they seem to not be at fault; redirect still fails without them. If anyone has any ideas on this I'd be very grateful. The plugin code is below:

    if ( ! function_exists('wp_notify_postauthor') ) :
    
    function wp_notify_postauthor($comment_id, $comment_type='') {
    	$comment = get_comment($comment_id);
    	$parent_id = $comment->comment_parent;
    	$parent = get_comment($parent_id);
    	$post    = get_post($comment->comment_post_ID);
    	$user    = get_userdata( $post->post_author );
    
    	if ('' == $user->user_email) return false; // If there's no email to send the comment to
    
    	$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
    
    	$blogname = get_option('blogname');
    	$permalink = get_permalink($comment->comment_post_ID);
    
    	$delete = admin_url("comment.php?action=cdc&c=$comment_id");
    	$spam = admin_url("comment.php?action=cdc&dt=spam&c=$comment_id");
    
    	if ( $parent->user_id == $post->post_author ) {
    		$fore_author = "You";
    		}
    	else {
    		$fore_author = $parent->comment_author;
    		}
    
    	if ( ($parent_id == '') || ($parent_id == $comment->comment_post_ID) ) { //if this is unthreaded or a top-level comment
    		$fore_content = '<p><strong>You wrote:</strong><blockquote>' . $post->post_content .'</blockquote></p>'; }
    	else { //if it's a threaded comment
    		$fore_content = '<p><strong>' . $fore_author . ' wrote:</strong><blockquote>' . $parent->comment_content .'</blockquote></p>'; }
    
    	if ( empty( $comment_type ) ) $comment_type = 'comment';
    
    	if ('comment' == $comment_type) {
    		$notify_message  = '<html><body>
    			<p>New comment on your post "'.  $post->post_title .'"</p>
    			<p>Author: '. $comment->comment_author .' <br />
    			IP: <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=' . $comment->comment_author_IP .'">'. $comment->comment_author_IP .'</a><br />
    			E-mail: '. $comment->comment_author_email .'</br>
    			<a href="' . $comment->comment_author_url .'">' . $comment->comment_author_url .'</a></p>' .
    			$fore_content
    			. '<p><strong>'. $comment->comment_author . ' replied:</strong> <blockquote>' . $comment->comment_content . '</blockquote></p>';
    		$subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
    	}
    	elseif ('trackback' == $comment_type) {
    		$notify_message  = '<html><body>
    			<p>New trackback on your post "' .$post->post_title . '</p>
    			 <p>Website: <a href="' .$comment->comment_author_url .'">'. $comment->comment_author .'</a> <br />
    			 IP: <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=' . $comment->comment_author_IP .'">'. $comment->comment_author_IP .'</a></p>
    			 <p>Excerpt: ' . $comment->comment_content . '</p>';
    		$subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
    	}
    	elseif ('pingback' == $comment_type) {
    		$notify_message  = '<html><body>
    			<p>New pingback on your post "' .$post->post_title . '</p>
    			 <p>Website: <a href="' .$comment->comment_author_url .'">'. $comment->comment_author .'</a> <br />
    			 IP: <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=' . $comment->comment_author_IP .'">'. $comment->comment_author_IP .'</a></p>
    			 <p>Excerpt: ' . $comment->comment_content . '</p>';
    		$subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
    	}
    	$notify_message .= '<br />
    		<p><a href="' . $permalink . '#comment-' .$comment_id.'">View the comment</a><br />
    		<a href="'. $permalink .'">View the post</a><br />
    		<a href="'. $delete .'">Delete comment</a><br />
    		<a href="'. $spam .'">Mark comment as spam</a></p>
    		</body></html>';
    
    	$wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
    
    	if ( '' == $comment->comment_author ) {
    		$from = "From: \"$blogname\" <$wp_email>";
    		if ( '' != $comment->comment_author_email )
    			$reply_to = "Reply-To: $comment->comment_author_email";
    	} else {
    		$from = "From: \"$comment->comment_author\" <$wp_email>";
    		if ( '' != $comment->comment_author_email )
    			$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
    	}
    
    	$message_headers = "$from\n"
    		. "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n";
    
    	if ( isset($reply_to) )
    		$message_headers .= $reply_to . "\n";
    
    	//$notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
    	$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
    	$message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
    
    	if ( $comment->user_id == $post->post_author ) { die; } //why did I need to add this?
    	else {
    	@wp_mail($user->user_email, $subject, $notify_message, $message_headers);
    	}
    
    	return true;
    }
    endif;
  2. Branch
    Member
    Posted 5 years ago #

    Happily, this appears to have been a beta glitch, and it doesn't happen in beta2.

Topic Closed

This topic has been closed to new replies.

About this Topic