因此,我和我的团队在Wordpress仪表板上的评论被批准而没有结果时,试图触发代码时遇到了一个问题。我们只是试图将用户信息发送到社交附件API,并需要在博客评论获得管理员批准后将其发送出去。需要知道我们是否需要为这个解决方案编写更多内容。目前,我们在子主题函数中有以下代码。php文件:
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);
我对这种类型的功能相当陌生,我想知道是否有任何用例可以让代码在博客评论获得批准后立即启动。谢谢
编辑:
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 );