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 );
my_approve_comment_callback()
when the comment is approved. How would I go about calling this when an admin approves a comment?