Advertisement
w0lfiesmith

Wordpress Ajax comment post - PHP for functions.php

Mar 31st, 2012
3,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. add_action('comment_post', 'ajaxify_comments',20, 2);
  2. function ajaxify_comments($comment_ID, $comment_status){
  3.     if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
  4.     //If AJAX Request Then
  5.         switch($comment_status){
  6.             case '0':
  7.                 //notify moderator of unapproved comment
  8.                 wp_notify_moderator($comment_ID);
  9.             case '1': //Approved comment
  10.                 echo "success";
  11.                 $commentdata=&get_comment($comment_ID, ARRAY_A);
  12.                 $post=&get_post($commentdata['comment_post_ID']);
  13.                 wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
  14.             break;
  15.             default:
  16.                 echo "error";
  17.         }
  18.         exit;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement