Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Has anyone effectively integrated GD star rating and Cube Points?

From the documentation:

Plugin Integration CubePoints can also be easily integrated with other plugins. Other plugins can be coded such that certain actions trigger the cp_alterPoints() function to add or subtract points from a specified user.

Function

cp_alterPoints( int $uid, int $points ) 

Parameters

int $uid: ID of a Wordpress user. To get the ID of the current logged in user, use the cp_currentUser() function.

int $return: Number of points to add to the specified user.

Example

The following code will add 10 points to the current logged in user. If no user is logged in, no points will be added. You may input negative number to subtract points.

<php
  if( function_exists('cp_alterPoints') && is_user_logged_in() ){
    cp_alterPoints(cp_currentUser(), 10);
    cp_log('hey', cp_currentUser(), 10, 1);
  }
?>

In this case, I would like to add 10 points to the user, if his or her post is voted (GD star rating's thumbs rating system).

But I have no idea how to do that.

Any suggestions?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

From this page, you can see that gdsr_vote_rating_article is the hook you need - it gets called when a post rating is saved.

share|improve this answer
    
Sorry I have little knowledge about php, how that would look like in the function? –  janoChen Mar 23 '11 at 8:30

After some googling and trial and error, here is the solution:

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;
}

This is for *gdsr_vote_thumb_article* hook (thumb up/down), if you want to attach rating hook use *gdsr_vote_rating_article*.

Now this will give a user who rated 1 point regardless of if he voted up or down.

If you want to pass the value of the actual rating you need to $_GET some params from gd-star-rating AJAX call:

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';
    }
    ...
}

...if you want to give points to the author of the post instead of the current logged in user:

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);
}

Cheers! :)

share|improve this answer
    
Thanks for shring mate ;) i need this data –  Sagive SEO Feb 9 at 13:37

protected by Community Feb 3 at 19:02

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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