Created
September 15, 2014 04:05
-
-
Save guoxiangke/9ce6cfb1d3ba0367868b to your computer and use it in GitHub Desktop.
wordpress ajax comment! getCommentHTML???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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