经过一些谷歌搜索和反复尝试,以下是解决方案:
add_action( \'gdsr_vote_thumb_article\', \'cubepoints_vote_up_down\', 10, 4 );
function cubepoints_vote_up_down() {
global $bp;
cp_points( \'star_rating\', cp_currentUser(), 1, $data );
}
add_action( \'cp_logs_description\', \'cp_admin_logs_desc_star_rating\', 10, 4 );
function cp_admin_logs_desc_star_rating( $type, $uid, $points, $data ) {
global $bp;
if ( $type != \'star_rating\' ) { return; }
$post = get_post( $data );
echo \'Voted for \' . $post;
}
这是给
gdsr_vote_thumb_article
挂钩(拇指向上/向下),但如果要连接评级挂钩,请使用
gdsr_vote_rating_article
.
这将给一个评分为1分的用户,无论他投的是赞成票还是反对票。
如果要传递实际评级的值,需要$_GET
来自的某些参数gd-star-rating
AJAX调用:
function cubepoints_vote_up_down() {
global $bp;
// get voted post id
$post_id = $_GET[\'vote_id\'];
// get the value of rating
$vote = $_GET[\'vote_value\'];
if ( $vote == \'up\' ) {
$point = \'1\';
} else {
$point = \'-1\';
}
}
如果您想给帖子作者评分,而不是给当前登录用户评分:
function cubepoints_vote_up_down() {
global $bp, $wpdb, $post;
$post_id = $_GET[\'vote_id\'];
$vote = $_GET[\'vote_value\'];
$post = get_post( $post_id );
$post_author = $post->post_author;
if ( $vote == \'up\' ) {
$point = \'1\';
} else {
$point = \'-1\';
}
cp_points( \'thumb_up_down\', $post_author, $point, $data );
}