Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
Created September 15, 2014 04:05
Show Gist options
  • Save guoxiangke/9ce6cfb1d3ba0367868b to your computer and use it in GitHub Desktop.
Save guoxiangke/9ce6cfb1d3ba0367868b to your computer and use it in GitHub Desktop.
wordpress ajax comment! getCommentHTML???
<?php
// Method to handle comment submission
function ajaxComment($comment_ID, $comment_status) {
// If it's an AJAX-submitted comment
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
// Get the comment data
$comment = get_comment($comment_ID);
// Allow the email to the author to be sent
wp_notify_postauthor($comment_ID, $comment->comment_type);
// Get the comment HTML from my custom comment HTML function
$commentContent = getCommentHTML($comment);
// Kill the script, returning the comment HTML
die($commentContent);
}
}
// Send all comment submissions through my "ajaxComment" method
add_action('comment_post', 'ajaxComment', 20, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment