RJ Solusoft

There are many functionalities on the web that were just begging to be AJAXified.  Whether it be voting on a poll or simply commenting on a blog post, there’s really no reason to reload an entire page for something so simple.  This blog has featured AJAX comments in WordPress for years, but only recently did I find the most optimized way to process those comments.  Here’s how to handle the WordPress PHP side of AJAX comment systems.


Add the following function with your theme’s function.php file:

// 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…

View original post 184 more words