How to Use Mail To Commenter Plugin in Threaded Comments
Last post I told you to make wordpress theme support threaded comments. There is a simple idea. Copy the build-in template. But the idea can not work when you installed Mail to Commenter plugin and still want to use it in your threaded comments supported wordpress themes. So how to solve this problem? I’ll tell you the solution to use Mail to Commenter plugin in threaded comments.
In the \wp-includes\comment-template.php you will find the code:
onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")' |
So if you want to use start Mail to Commenters function, you should edit this line. But you should remember one point. You need to judge the threaded comments levels deep. Here is the judgement function:
if ( $max_depth |
So I get the idea now. Mail to Commenter plugin will check the comments if there is a @user or @user: in it. If it find one, it will mail to comment author. So we need to add a Javascript on the “Reply” link. Here is the JS code:
RE_CON.reply('< ?php echo $add_below-$comment->comment_ID ?>','< ?php echo $comment->comment_ID ?>','comment'); |
Then you should add this JS code to your theme:
(function() { function $(id) { return document.getElementById(id); } window['RE'] = {}; window['RE']['$'] = $; function reply(authorId, commentId, commentBox) { var author = RE.$(authorId).innerHTML; var insertStr = '<a href="#' + commentId + '">@'+ author.replace(/\t|\n|\r\n/g, "")+':</a> \n'; insertReply(insertStr, commentBox); } function insertReply(insertStr, commentBox) { if(RE.$(commentBox) && RE.$(commentBox).type == 'textarea') { field = RE.$(commentBox); } else { alert("The comment box does not exist!"); return false; } if (field.value.indexOf(insertStr) > -1) { alert("You've already appended this reply!"); return false; } if (field.value.replace(/\s|\t|\n/g, "") == '') { field.value = insertStr; } else { field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr; } } window['RE_CON'] = {}; window['RE_CON']['reply'] = reply; })(); |
After this, we are now able to use Mail to Commenters in our threaded comments. My solution to Use Mail To Commenter Plugin in Threaded Comments is like this:
< ?php if(!function_exists('mailtocommenter_button')) {comment_reply_link(array_merge( $args, array('reply_text' => 'Reply', 'depth' => $depth, 'max_depth' => $args['max_depth']))); } else if(function_exists('mailtocommenter_button')&& $depth <a class="comment-reply-link" onclick="onclick='return addComment.moveForm(' href=" rel="nofollow">comment_ID', '< ?php echo $add_below-$comment->comment_ID ?>', '< ?php echo $respond_id ?>', '< ?php echo $post->ID ?>')';RE_CON.reply('< ?php echo $add_below-$comment->comment_ID ?>','< ?php echo $comment->comment_ID ?>','comment'); "> < ?php _e('Reply'); ?> </a> < ?php } else { ?> <a class="comment-reply-link" onclick="RE_CON.reply('< ?php echo $add_below-$comment->comment_ID ?>','< ?php echo $comment->comment_ID ?>','comment'); " href="javascript:void(0);" rel="nofollow"> < ?php _e('Reply'); ?> </a> <!--?php }?--> |
