如果作者评论他自己的帖子插件帮助,不要发送通知?

时间:2011-11-08 作者:jimilesku

有没有办法设置一个IF语句,如果帖子的作者在自己的帖子上发表评论或回复说wp通知没有发送给他,只有当其他用户发表评论时,他才会收到通知?。我正在使用Notify on comment插件。

<?php
/*
Plugin Name: Notify on comment
Plugin URI: http://www.artbits.it
Description: Send a notification on comment to the author of the post
Version: 1.03
Author: Fabio Trezzi 
Author URI: http://www.artbits.it
*/

function notifyOnComment_send($commentID){
global $wpdb;
// Get the email of the post\'s author
$comment = get_comment($commentID);
$post = get_post($comment->comment_post_ID);
$user = get_userdata($post->post_author);
$to = $user->user_email;
// Set the send from
$admin_email = get_option(\'admin_email\');
$headers= "From:[email protected]\\r\\n";
$headers .= "Reply-To:[email protected]\\r\\n";
$headers .= "X-Mailer: PHP/".phpversion();

$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = \'0\'");

$moderationOpt = get_option(\'notifyOnComments_moderationRequired\');

if($moderationOpt == \'true\'){
    // Only send the notification if the comments requires to be moderated
    $approved = $comment->comment_approved;
    if($approved != 0) return;  // No need to send the mail the comment is already approved
}   

$template = get_option(\'notifyOnComments_emailTemplate\'); 
// If not setted load the default from file
if($template || $template == "") $template = file_get_contents(dirname(__FILE__) . \'/defaultTemplate.php\');

// Replace all the constant with the rights values
$template = str_replace("{postID}", $post->ID, $template);
$template = str_replace("{postTitle}", $post->post_title, $template);
$template = str_replace("{author}", $comment->comment_author, $template);
$template = str_replace("{authorIp}", $comment->comment_author_IP, $template);
$template = str_replace("{authorDomain}", $comment_author_domain, $template);
$template = str_replace("{authorEmail}", $comment->comment_author_email, $template);
$template = str_replace("{authorUrl}", $comment->comment_author_url, $template);
$template = str_replace("{commentContent}", $comment->comment_content, $template);
$template = str_replace("{commentLink}", get_permalink($comment->comment_post_ID), $template);
$template = str_replace("{commentID}", $commentID, $template);
$template = str_replace("{commentsWaiting}", $comments_waiting, $template);
$template = str_replace("{siteUrl}", get_option(\'siteurl\'), $template);

$subject = sprintf( __(\'[%1$s] Please moderate: "%2$s"\'), get_option(\'blogname\'), $post->post_title );

@wp_mail($to, $subject, $template, $headers);

return true;

}

function notifyOnComment_menu() {
$path = dirname(__FILE__);
$pathElements = explode(\'/\', $path);
add_options_page(\'NotifyOnComments options\', \'NotifyOnComments\', \'manage_options\',   $pathElements[count($pathElements) - 1] . \'/options.php\');
}

add_action(\'comment_post\', \'notifyOnComment_send\');
add_action(\'admin_menu\', \'notifyOnComment_menu\');

?>

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

未经测试,但从“快速查看”来看,类似这样的操作应该有效:

$comment = get_comment($commentID);
$post = get_post($comment->comment_post_ID);
$user = get_userdata($post->post_author);

if( $comment->user_id == $post->post_author )
    return;

结束

相关推荐

Ajax submit comments

我想通过ajax提交评论。单击comment submit按钮,通过jquery的ajax方法和结果发布评论(“等待审核…”)显示在页面上。我进入了剧本。js文件,并为按钮添加了一个单击处理程序。它验证并执行ajax提交,但这不起作用。单击提交评论仍会重定向到wp评论帖子。php页面。让它发挥作用的秘诀是什么?以下是我在脚本中的内容。js公司:$(\"#my_comment_form\").validate({ submitHandler: function(data){