Implementing CubePoints Reputation and Rank in WP comments

After installing CubePoints(+CubePoints Buddypress Integration) plugin I was disappointed that I didn't found reputation points and ranks for users in their comments on blog and bbpress forum. I think that this is important part of such plugin - show user's reputation to public.
After couples of hours of searching for solution, I did found only that. But nobody told there how to embed this correctly in WP.
Anyway I've found solution after reading some topics and WP functions descriptions. Here is result:

CubePoints and Ranks in WordPress Comments

I think your theme contains comments.php and this file calls wp_list_comments function to show replies. Something like that:

1
<?php wp_list_comments(); ?>

or this:

1
<?php wp_list_comments(array('avatar_size' => 70)); ?>

Don't modify wp-includes/comment-template.php! It is not correct and will be removed after your next WP update.
We can set for wp_list_comments callback function, the function that will be called instead of main part of start_el.

Ok, here is my example of making CubePoints and Ranks displayed in comments for WordPress 3.3.1
For wp_list_comments I've set callback-function comment_template_cp (comments.php file of my wp theme):

1
2
3
4
5
6
<?php
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (is_plugin_active('cubepoints/cubepoints.php')) {
  wp_list_comments(array('avatar_size' => 70, 'callback' => 'comment_template_cp'));
}else{wp_list_comments(array('avatar_size' => 70));}
?>

In functions.php file of my theme I've inserted comment_template_cp function (modified start_el):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function comment_template_cp($comment, $args, $depth) {
 
    $GLOBALS['comment'] = $comment;
    extract($args, EXTR_SKIP);
 
    if ( 'div' == $args['style'] ) { $tag = 'div'; $add_below = 'comment';
      } else { $tag = 'li'; $add_below = 'div-comment'; }
?>
    <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
    <?php if ( 'div' != $args['style'] ) : ?>
    <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
    <?php endif; ?>
    <div class="comment-author vcard">
    <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
    <?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()) ?> 
<?php
$user = get_userdata($comment->user_id);
if(function_exists('cp_displayPoints') && $user->ID){
  echo '<span class="cubepoints_buddypress">'; cp_displayPoints($user->ID); echo '</span>';
  if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($user->ID).'</span>';
}
?>
<span class="says"></span>
    </div>
  <?php if ($comment->comment_approved == '0') : ?>
    <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
    <br />
  <?php endif; ?>
 
    <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
      <?php
        /* translators: 1: date, 2: time */
        printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
      ?>
    </div>
 
    <?php comment_text() ?>
 
    <div class="reply">
    <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    </div>
    <?php if ( 'div' != $args['style'] ) : ?>
    </div>
    <?php endif; ?>
<?php
}

Here is our code for showing cubepoints if you don't see that in function above.

1
2
3
4
5
6
7
<?php
$user = get_userdata($comment->user_id);
if(function_exists('cp_displayPoints') && $user->ID){
  echo '<span class="cubepoints_buddypress">'; cp_displayPoints($user->ID); echo '</span>';
  if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($user->ID).'</span>';
}
?>

Ok, next my step is implementation CubePoints to bbPress replies.

VN:F [1.9.17_1161]
Rating: 8.8/10 (9 votes cast)
Implementing CubePoints Reputation and Rank in WP comments, 8.8 out of 10 based on 9 ratings
permalinkRead More CommentComments (11) CatWordpress

11 Responses to “Implementing CubePoints Reputation and Rank in WP comments”

  1. Daniel Says:

    Hi! I run a multi-author site and i need your help to implement this on my post-entry besides the author of the post. I do not use buddypress. I want it to show the points and rank of the author. Any thoughts on this? Please help me, my php-knowledge is slim.Best regardsDaniel

    VA:F [1.9.17_1161]
    Rating: 5.0/5 (1 vote cast)
  2. admin Says:

    Try this code in your single.php :

    <?php cp_displayPoints($authordata->ID); ?>
    VN:F [1.9.17_1161]
    Rating: 4.7/5 (3 votes cast)
  3. Daniel Says:

    ok, done!
    It shows the points now in author bio.

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  4. admin Says:

    Great! :)
    Is that what you need?
    Do you know what to do next with that?

    VN:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  5. Daniel Says:

    Thank you so much! Yes but could you just help me how to show the rank of the author also, i would be so happy =)

    and if i want to style the points, like bigger number and a nice image/icon behind it, where do i go for that?

    Im not sure where to put it in post-entry. I tried but i doesnt show up.

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  6. admin Says:

    1)
    If it works and you plan use it on your site, replace our previous code (< ?php cp_displayPoints($authordata->ID); ?>) by this:

    <?php
    if(function_exists('cp_displayPoints') && $authordata->ID){
      echo '<span class="cubepoints_buddypress">'; cp_displayPoints($authordata->ID); echo '</span>';
      if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($authordata->ID).'</span>';
    }
    ?>

    - it will be safe when you disable cubepoints and should add user rank.

    2)
    For styling I use default cubepoints CSS for buddypress.

    span.cubepoints_buddypress, span.cupepoints_buddypress_rank, span.cupepoints_buddypress_donate {
        -moz-border-radius: 3px 3px 3px 3px;
        background: -moz-linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0)) repeat scroll 0 0 #FFEAA6;
        border: 1px solid #E1CA82;
        display: inline-block;
        font-size: 11px;
        font-weight: normal;
        line-height: 170%;
        margin-bottom: 7px;
        margin-top: 3px;
        padding: 1px 8px;
        vertical-align: middle;
    }

    3)
    Check your post-entry.php, you should find that:
    <span class="authorspan">...</span>

    Add php code between spans

    <span class="authorspan">...</span>
    <?php
    $curauthor = get_the_author_meta('ID');
    if(function_exists('cp_displayPoints') && $curauthor){
      echo '<span class="cubepoints_buddypress">'; cp_displayPoints($curauthor); echo '</span>';
      if(function_exists('cp_module_ranks_getRank')) echo ' <span class="cupepoints_buddypress_rank">'.cp_module_ranks_getRank($curauthor).'</span>';
    }
    ?>
    <span class="datespan">...
    VN:F [1.9.17_1161]
    Rating: 4.8/5 (4 votes cast)
  7. Peter Says:

    *Just to note that this is an excellent article, I needed a fix for this as well.

    VA:F [1.9.17_1161]
    Rating: 5.0/5 (1 vote cast)
  8. Ante Says:

    Just to add, if you want to echo the rank outside the styling provided above, you can just insert: <?php echo cp_module_ranks_getRank($authordata->ID); ?>

    Thank you for this awesome article and the replies that in my opinion should be in its own article. The documentation for this plugin is very poor and so is the support (with respect to the developers). So helpful things like this is excellent.

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  9. admin Says:

    Ante, Thanks for sharing your experience!

    VN:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  10. Roger Says:

    *Hello, 

    I was reading in your blog that you have some experience with cubepoints.

    And I though that you can help me achieve something!

    I am using a plugin called WP-User Badges, and I want to integrate it with cubepoints points.

    So here what I want to do:

    If a user has "x" points the plugin User badges will display a badge for it.

    The problem: I dont know how to specify to my plugin the points of a user.

    I think it is something related to this:

    if(cp_points > 100 && cp_points < 500)

    $ad .= userbadges_show_badge("Have more than 100 Points");

    Can you help?

    Thank you

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  11. Ben Says:

    I know this is an old post - but did you find a solution for bbpress??

    I've been searching for a good solution for a while now....

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

You must be logged in to post a comment.

CSS Template by RamblingSoul | Tomodachi theme by Theme Lab