Recently, I got a lot of request on our forum for supporting global forum with CubePoints BuddyPress Integration plugin by Tosh. I looked into the code of CubePoints buddypress integration plugin and it seemed like an interesting thing to do.
Though the current version of buddypress cubepoints lacked some hook to show the point form and update the settings, I am hopeful that Tosh will add it in next version of BuddyPress cubepoints integration plugin and open a new door for plugin developers to support their own plugin.
Here is what I did to support the global forum with cubepoints plugin.
1. Add a hook to BuddyPress CubePoints Integration plugin admin section to allow showing your form.
So, I put this code there
do_action("bp_cubepoint_main_settings"); //allow other plugin to hook and show their point poption here
That allows any plugin developer to put their own form elements in the CubePoints BuddyPress Integration plugin admin section.
2. Allow plugin developers to update their points/settings when the points table is saved.
Just adding one more hook in the function "cubebp_admin" and everything was setup.
Here is what I added, It may be different when Tosh updates his plugin.
do_action("bp_cubepoint_settings_updated");//allow other plugins to hook here and update their settings on save
Well, the base is ready now. We can easily extend the CubePoints plugin and support our own plugin now.
So, what functionalities we are interested in supporting, Obviously, It narrows down to these two
- Giving/Deducting point on some action performed in our plugin
- Logging the actions
CubePoints core proved a way for that
cp_points($type, $uid, $points, $data)
- $type: your unique action identifier (or let su say It identifies the purpose of the point)
- $uid: the user id to which points should be given
- $points: how many points you want to give
- $data: I am not sure the purpose of it. Perhaps It is used in saving logs
cp_points function adds the point and logs the action.
So, Now you just need to add a function to your action and give points.
$point=get_option("points_for_my_something_happened_action");//how many points you want to give
That will add point for your action. But wait you are not done yet. The cp_points already logs your event but to display it, CubePoints needs your help.
Here is what cube point does while displaying it
do_action('cp_logs_description', $result->type, $result->uid, $result->points, $result->data);
Just hook your function to show a meaningful message on the action "cp_logs_description" and you are done.
Here is the continued code snippet.
do_action('cp_logs_description', "my_hellow_something_happened_log_message",10,4);//4 is for no. of args
if($type!="hello_something_happened")//remember this is same as we used in cp_points
echo "The wonderful action happened";//well you may make it meaning full by using uid and making something like user x did action alpha beta and received $points point
Ok, That was for everyone who want to support cubepoints in their own plugin.
CubePoints For Global Forum
Here is the CubePoints global forum integration plugin.
Download & Install:-
Here is modified cubepoints-buddypress-integration/includes/bp-cubepoint-admin.php. Replace it in cubepoints-buddypress-integration/includes.
And a screenshot of cubepoints admin settings page
If you are using Global forum cubepoints integration plugin, please note there are four actions defined
- new topic create
- topic delete
- new post(or say reply)
- delete post
There is a bug in global forum, the delete actions are called twice, so points will be deducted twice(as of global-forum-v1.0.2). Please make sure to allocate only half of those point to the delete actions. Say, if you wanted to deduct 10 points for post delete, make sure you specify -5 in the admin option. This is a bug with delete option
(for topic/posts) in current global forum. I will update and fix it when the new release comes.
Looking forward to hear your comments
P.s: Special Thanks to Joey for asking me to do this plugin.