0

So my team and I are running into an issue when trying to fire off code when a comment is approved from the Wordpress dashboard with no results. We are only trying to send user information to the Social Annex API and need it to sen out once blog comment has been APPROVED by an admin. Need to know if there is more we need to write up for this solution. Currently we have the following code inside a child-theme functions.php file:

function my_approve_comment_callback($new_status, $old_status, $comment) {
    if($old_status != $new_status) {
        if($new_status == 'approved') {
            $baseUrl = "http://s15.socialannex.net/api";
            $user_email = $comment->comment_author_email; //provide here email address of user who posted comment on blog.
            $fname = $comment->comment_author; //provide here first name of user who posted comment on blog.
            $lname = '';  //provide here last name of user who posted comment on blog.
            $access_token = '***************';
            $siteid = *******;
            $action_id = ***;

            /*CREATE USER*/
            $requestURL= $baseUrl."/user/".$siteid."/".$user_email."?access_token=".$access_token;
            $data = array('fname'=>$fname,'lname'=>$lname);
            $response = makeRequest($requestURL,'POST',$data);

            /*EXAMPLE FOR POST REQUEST, USE THIS CTA WHEN BLOG POST COMMENT GETS APPROVED*/
            $requestURL= $baseUrl."/userpoints/".$siteid."/".$user_email."?access_token=".$access_token;
            $data = array('action_id'=>$action_id,'action_use'=>'4');
            $response = makeRequest($requestURL,'POST',$data);
        }
    }
}
add_action('transition_comment_status', 'my_approve_comment_callback', 10, 3);

I am fairly new to this type of functionality and was wondering if there were any use cases out there for getting code to fire off once a blog comment is approved. Thanks!

EDIT:

function filter_handler( $approved , $commentdata ){
    if($approved) {
        $baseUrl = "http://s15.socialannex.net/api";
        $user_email = $comment->comment_author_email; //provide here email address of user who posted comment on blog.
        $fname = $comment->comment_author; //provide here first name of user who posted comment on blog.
        $lname = '';  //provide here last name of user who posted comment on blog.
        $access_token = '****';
        $siteid = ****;
        $action_id = **;

        /*CREATE USER*/
        $requestURL= $baseUrl."/user/".$siteid."/".$user_email."?access_token=".$access_token;
        $data = array('fname'=>$fname,'lname'=>$lname);
        $response = makeRequest($requestURL,'POST',$data);

        /*EXAMPLE FOR POST REQUEST, USE THIS CTA WHEN BLOG POST COMMENT GETS APPROVED*/
        $requestURL= $baseUrl."/userpoints/".$siteid."/".$user_email."?access_token=".$access_token;
        $data = array('action_id'=>$action_id,'action_use'=>'4');
        $response = makeRequest($requestURL,'POST',$data);
        return $response;

    }
}
add_filter( 'pre_comment_approved' , 'filter_handler' , '99', 2 );
1
  • I think I may need to somehow call my_approve_comment_callback() when the comment is approved. How would I go about calling this when an admin approves a comment? Jan 12, 2018 at 20:57

1 Answer 1

0

I would take a look at pre_comment_approved (https://codex.wordpress.org/Plugin_API/Filter_Reference/pre_comment_approved)

1
  • Thank you for giving some insight. So what I am attempting to do is just have the form data that is submitted/stored fire off and send to the Social Annex API. From a Wordpress standpoint this seems like it should be straight forward as I am hooking into the comment approval hook. I have edited the code above to reflect what I am attempting. Jan 23, 2018 at 17:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.