[Resolved] CubePoints and BuddyPress Intregration?
-
I’ve been using CubePoints with my single WP install to get people on contribute to my site.
They get points for posts, comments, forum posts, daily visit. I have giveaways and they
donate there points to a lottery account that I randomly pick from.
http://wordpress.org/extend/plugins/cubepoints/
Anyway, they provide a simple API, so I was just wondering where I could put this code.
if( function_exists('cp_alterPoints') && is_user_logged_in() ){ cp_alterPoints(cp_currentUser(), 10); }
So if they create a group they get some points, if they post an update/reply, etc.
-
Cool plugin! I’ll have to play around with this at some point.
Anyway, back to your question.
Look around the BP code and find anything that says “do_action”; this is where you can hook your functions into a BP action.
For instance, to add 10 CubePoints when creating a group, add the following to your theme’s functions.php or /wp-content/plugins/bp-custom.php.
function my_bp_create_group_add_cppoints() {
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints(cp_currentUser(), 10);
cp_log('User created a group -- +10 points', cp_currentUser(), 10, 1);
}
}
add_action('groups_group_create_complete','my_bp_create_group_add_cppoints');In this case, we hooked the cp_alterPoints() and cp_log() functions to the groups_group_create_complete hook found in /buddypress/bp-groups.php.
In the next little while, I’m going to try and add a bit of documentation to the codex.
Cool. I tried that. It gave points for each step of the group creation process. Instead of just the first step. I put the code in my themes functions.php file fyi
I couldn’t find the bb-custom.php file though. Is that something I have to create?
But it worked
I’ll still searching to find the spot to put the code so it gives points for updates/replies.
Thanks Ray!
Every step, huh? Looks like I hooked into the wrong group action
I modified the post above to the correct action now.
Functions.php is fine.
Perfection Your the man!
Where should I start looking for giving points for updates/replies in BuddyPress?
Thanks Again
I’m going to let you try this on your own
Don’t worry! I’ll give you some hints.
Create a function like the above and then find the appropriate BP action to hook your function to.
Look in /buddypress/bp-activity.php. Do a search for “do_action”.
If you want more hints, the BP actions are:
– bp_activity_posted_update
– bp_activity_comment_posted
You might want to subtract points if someone deletes their own activity as well.
I got it working Adding a update or reply, they get points. If a user deletes his/her own update it’s takes points away.
Only thought I had if I where to delete another users comment/update. It deletes the points from my account instead of theres.
Here is how I’m deleting points:
// Remove 5 points for comment delete
function my_bp_delete_comment_add_cppoints() {
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints(cp_currentUser(), -5);
cp_log('Comment Removed', cp_currentUser(), -5, Community);
}
}
add_action('bp_activity_action_delete_activity','my_bp_delete_comment_add_cppoints');inside the function you could add
if ( !is_site_admin() )
return false;you should package up all the small updates into a simple plugin – this sounds very cool to add.
I’d love to, but I’ve never made a plugin before. But it’s something I’m willing to tackle. Would be nice to have an option in the backend so people could change how much points people get.
I’ll try that admin code snippet when I get home tonight. Thanks!
very useful
one question tho, i dont want my users going to the dashboard to see points..
how do i get to display a buddypress displayed users points, it currently only displays a logged in users points no matter wat page ur on when using cp_displaypoints..
anyone know how to do this???
when will this be fulle buddypress compatible?
@dre1080 this is something I’d like to see myself.
I have points given for the following, and it’s all working great!
blog posts, comments, logging in daily, forum post/creation (simplepressforum), update/reply (buddypress), creation of a group (buddypress).
Is it possible to use this with “likes” and “dislikes” ?
Assuming that the BP-Likes plugin has hooks… then yes, otherwise no.
Just seen this code snippet above.
if ( !is_site_admin() )
return false;I’d suggest doing it like this, as it saves database queries on regular WP:
global $bp;
if ( !$bp->loggedin_user->is_site_admin )
return false;Cool! Didn’t know about that!
Learn something new everyday!
I found the hooks but I cant figure out to give points to poster/author instead of logged in user.
I want posters to get points when someone else likes their post or comment etc. a sitewide point system.
Like:
if( function_exists(‘cp_alterPoints’) && is_user_logged_in() ){
cp_alterPoints(the_author_ID(), 5);
}
This is what the docs says:
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.
@tomteduck – where are the like hooks??
I can do the rest, but looked and could find no hooks
Thanks for introducing this interesting plugin to us. Are you still planning to package this into a buddypress plugin?
Looks like you managed to get it working with a lot of actions. Please consider documenting your steps so others can also benefit from them.
Also, would love to see your implementation if you can post a link. Thanks!
I’ve never made a plugin before, so not sure how that goes. But I’m more than willing to learn! Any tips on where to start?
@DJPaul (Paul Gibbs)
Where should I put this code?
global $bp;
if ( !$bp->loggedin_user->is_site_admin )
return false;
Looks like it’s working! Awesome sauce!
Hey Tosh,
Never made a plugin myself so can’t help you in that matter. But thanks a lot for making the effort, your plugin will be very useful once its ready.
Ok, guys. I requested for it to be added to the WordPress.org Plugin Directory. Wish me luck! How long does it take to get accepted for the first time?
BTW, where should I add this chunk of code so when admins delete a update they don’t get points taken away.
global $bp;
if ( !$bp->loggedin_user->is_site_admin )
return false;
Hey Tosh,
Do let us know when the plugin is available for download in the directory. Thanks!
Will do! I’ll create a thread dedicated to it once it’s live. I also fixed it so when a admin deletes an activity they don’t get docked points
Go Tosh, go !!!
- The topic ‘[Resolved] CubePoints and BuddyPress Intregration?’ is closed to new replies.