Plugin authors can now tie directly into CubePoints Buddypress Integration and add options to the admin menu. Such as setting values for earning/deducting points. You can also log the actions.

Let’s get started. I’ll explain the best I can what these functions do.

cp_points($type, $uid, $points, $data)

  • $type: Your unique action identifier (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: Don’t worry about this one. We can leave it blank. I can be used to show more detailed info in the database if you’d like to run queries on it.
    • Not sure how to fully use this since there is no documentation. But if you place something in there it won’t show on the front end in the logs. Only the database.

Here is the function you need to add to your action to give/remove points.

function give_point_on_something_happened(){
  global $bp;
  cp_points("hello_something_happened",$bp->loggedin_user->id, get_option("points_for_my_something_happened_action"),"");
}

Next thing you need to do it log it correctly. Here is the code block:

// your_do_action_here is a do_action you need to find. give_point_on_something_happened is the same function name as above.
add_action('your_do_action_here','give_point_on_something_happened');
// Log Action
add_action('cp_logs_description', "my_hello_something_happened_log_message",10,4); // 4 is for # of args
 
function my_hello_something_happened_log_message($type,$uid,$points,$data){
  if($type!="hello_something_happened") // This is same as we used in cp_points
  return; 
  echo  "The wonderful action happened"; // This is the text that shows in the logs. So make sure it makes sense according to the action they did to earn/remove points.
}

Last thing to do populate the admin menu of CubePoints Buddypress Integration so admins can change the point values for actions.

Above in the give_point_on_something_happened() function we had this:

get_option(“points_for_my_something_happened_action”)

So make sure you use the same text. In this example it’s points_for_my_something_happened_action

Here is the code for building the admin menu inside of my plugin.

<?php
// Admin Menu for CubePoints Buddypress Integration
function example_cp_update_settings(){
        update_option('points_for_my_something_happened_action', intval($_POST['points_for_my_something_happened_action']));		
}
add_action("bp_cubepoint_settings_updated","example_cp_update_settings");
 
function example_show_cp_settings(){ ?>
                <tr>
			<th colspan="3"><h4 align="center"><?php _e('Below Requires','cp_buddypress'); ?> <a href="http://www.yousite.com/yourpluginURL">Plugin Name</a> [YourSite.com]</h4></th>
		</tr>
                <tr valign="top">
			<th scope="row"><label for="points_for_my_something_happened_action"><?php _e('Points for this action','cp_buddypress'); ?>:</label></th>
			<td valign="middle"><input type="text" id="points_for_my_something_happened_action" name="points_for_my_something_happened_action" value="<?php echo get_option('points_for_my_something_happened_action'); ?>" size="2" /></td>
			<td><input type="button" onclick="document.getElementById('points_for_my_something_happened_action').value='0'" value="<?php _e('Do not add points','cp_buddypress'); ?>" class="button" /></td>
		</tr>
<?php
}
add_action("bp_cubepoint_main_settings","example_show_cp_settings");
?>

Here is the whole required code all placed together along with some other things I didn’t mention above so it’s optional. For example the Point Blocker feature which isn’t required but handy if you need to ban people from earning points for a bit.

<?php
if(!function_exists("cp_ready")) {
	return; // prevent any crash	
}
 
// Add Points for this awesome action
function give_point_on_something_happened() {
	global $bp;
	$bpcpspamlist = explode(',' , get_option( 'bp_spammer_cp_bp' ) );
	foreach ( $bpcpspamlist as $spammer_id ) {
		if ($bp->loggedin_user->id == $spammer_id ) {	
			$is_spammer = true;
			break;
		} else {
			$is_spammer = false;
		}
	}
	if ($is_spammer == false) {
		cp_points("hello_something_happened",$bp->loggedin_user->id, get_option("points_for_my_something_happened_action"),"");
	}
}
 
 
 
// your_do_action_here is a do_action you need to find. give_point_on_something_happened is the same function name as above.
add_action('your_do_action_here','give_point_on_something_happened');
// Log Action
add_action('cp_logs_description', "my_hello_something_happened_log_message",10,4); // 4 is for # of args
function my_hello_something_happened_log_message($type,$uid,$points,$data){
  if($type!="hello_something_happened") // This is same as we used in cp_points
  return; 
  echo  "The wonderful action happened"; // This is the text that shows in the logs. So make sure it makes sense according to the action they did to earn/remove points.
}
 
// Admin Menu for CubePoints Buddypress Integration
function example_cp_update_settings(){
        update_option('points_for_my_something_happened_action', intval($_POST['points_for_my_something_happened_action']));		
}
add_action("bp_cubepoint_settings_updated","example_cp_update_settings");
 
function example_show_cp_settings(){ ?>
                <tr>
			<th colspan="3"><h4 align="center"><?php _e('Below Requires','cp_buddypress'); ?> <a href="http://www.yousite.com/yourpluginURL">Plugin Name</a> [YourSite.com]</h4></th>
		</tr>
                <tr valign="top">
			<th scope="row"><label for="points_for_my_something_happened_action"><?php _e('Points for this action','cp_buddypress'); ?>:</label></th>
			<td valign="middle"><input type="text" id="points_for_my_something_happened_action" name="points_for_my_something_happened_action" value="<?php echo get_option('points_for_my_something_happened_action'); ?>" size="2" /></td>
			<td><input type="button" onclick="document.getElementById('points_for_my_something_happened_action').value='0'" value="<?php _e('Do not add points','cp_buddypress'); ?>" class="button" /></td>
		</tr>
<?php
}
add_action("bp_cubepoint_main_settings","example_show_cp_settings");
?>

Please let me know if you added support for Cubepoints using this method & I’ll update this list:

Via buddydev.com