I found an example how to How To AJAX-ify WordPress Comments. I tweak it little bit and so far everything works fine but I want to understand the code.

  1. Where did the arguments $comment_ID, $comment_status come from? I cannot find any reference about the arguments that are available. Can I use any other? More importantly do I have to use above names and what are the values for $comment_status?
  2. Do I have to call wp_notify_moderator() and wp_notify_postauthor() functions or they would be called by WordPress when inserting the comment into database?
  3. I don't understand syntax of these two lines $commentdata=&get_comment($comment_ID, ARRAY_A); $post=&get_post($commentdata['comment_post_ID']) what does the & does and what is ARRAY_A

Could some one answer my questions about below function that is called from this action. I know that 2 means that ajaxify_comments can accept two arguments but where did they come from? What about the names? Values? Possible values?

add_action('comment_post', 'ajaxify_comments',20, 2);

and the function code is like

function ajaxify_comments($comment_ID, $comment_status){
    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
        //If AJAX Request Then

            case '0':
                echo "success1";                        // send a message to ajax
                wp_notify_moderator($comment_ID);       // notify moderator of unapproved comment
            case '1':                                   // approved comment
                echo "success2";                            // send a message to ajax
                $commentdata=&get_comment($comment_ID, ARRAY_A);
                wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
                echo "error";                           // send a message to ajax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.