
Most tutorials stop at “install BuddyPress, install MyCred, tick a few boxes.” That gets you login points. Login points are boring. Your members already log in.
If you want to reward actual participation like posting updates, replying to threads, joining groups, completing profiles, you need hooks. myCred hook system triggers point events on any BuddyPress action.
Here’s the working code to reward content engagement on BuddyPress using myCred.
What You’ll Need to Trigger myCred Hooks on BuddyPress Community Website
- WordPress
- BuddyPress (or BuddyBoss Platform, as most hooks are shared, but some BuddyPress-specific behaviors may differ; test on your platform)
- myCred with the Hooks component activated under myCred → Components in wp-admin (it’s on by default)
- A child theme or custom plugin for the code
Always use a child theme’s functions.php or a custom plugin. Never edit a WordPress plugin file directly.
How MyCred Hooks Work on BuddyPress Community Website
myCred wraps WordPress hooks in its own class structure. A hook class extends myCred_Hook, registers the WordPress actions it listens to, and calls myCred->add_creds() when the action triggers.
The mycred_add() signature:
myCred_add($reference, $user_id, $amount, $entry, $ref_id, $data, $type)
- $reference — string for grouping log entries
- $user_id — who gets the points
- $amount — positive or negative
- $entry — log text (required, cannot be empty)
- $ref_id — the activity/comment ID
- $data — optional serialized data
- $type — point type slug, default mycred_default
How to Reward Activity Updates on BuddyPress Community Websites
BuddyPress triggers bp_activity_add when someone posts to the activity stream. It passes an array of parsed arguments as the first parameter and the activity ID as the second.
add_action(‘bp_activity_add’, ‘reward_bp_activity_post’, 10, 2);
function reward_bp_activity_post($r, $activity_id) {
if (empty($r[‘type’]) || $r[‘type’] !== ‘activity_update’) {
return;
}
$user_id = $r[‘user_id’];
// Prevent duplicate awards for this specific activity
$already_awarded = get_user_meta($user_id, ‘bp_activity_rewarded_’ . $activity_id, true);
if ($already_awarded) {
return;
}
myCred_add(
‘bp_activity_post’,
$user_id,
5,
‘Posted an activity update’,
$activity_id,
”,
‘mycred_default’
);
update_user_meta($user_id, ‘bp_activity_rewarded_’ . $activity_id, true);
}
The duplicate check: We use a unique meta key per activity (bp_activity_rewarded_123). If we used a single key like bp_activity_rewarded, the meta would exist after the first post and every subsequent post would be rejected. The user would earn points once, ever.
How to Reward Comments and Replies on BuddyPress Community Website
Activity comments use the same bp_activity_add hook with type activity_comment.
add_action(‘bp_activity_add’, ‘reward_bp_activity_comment’, 10, 2);
function reward_bp_activity_comment($r, $comment_id) {
if (empty($r[‘type’]) || $r[‘type’] !== ‘activity_comment’) {
return;
}
$user_id = $r[‘user_id’];
// Don’t award for commenting on your own activity
$parent = new BP_Activity_Activity($r[‘item_id’]);
if ((int) $parent->user_id === (int) $user_id) {
return;
}
$already_awarded = get_user_meta($user_id, ‘bp_comment_rewarded_’ . $comment_id, true);
if ($already_awarded) {
return;
}
myCred_add(
‘bp_activity_comment’,
$user_id,
3,
‘Commented on an activity update’,
$comment_id,
”,
‘mycred_default’
);
update_user_meta($user_id, ‘bp_comment_rewarded_’ . $comment_id, true);
}
The self-comment check: This stops users from farming points by replying to their own posts. Adjust if your community treats self-replies as valid.
How to Award Points for Joining Groups on BuddyPress Community Website
BuddyPress triggers groups_join_group when a user joins a group.
add_action(‘groups_join_group’, ‘reward_bp_group_join’, 10, 2);
function reward_bp_group_join($group_id, $user_id) {
// Cap at 5 groups to prevent join-spam
$join_count = (int) get_user_meta($user_id, ‘bp_groups_joined_count’, true);
if ($join_count >= 5) {
return;
}
$group = groups_get_group($group_id);
myCred_add(
‘bp_group_join’,
$user_id,
10,
‘Joined a group: ‘ . $group->name,
$group_id,
”,
‘mycred_default’
);
update_user_meta($user_id, ‘bp_groups_joined_count’, $join_count + 1);
}
The cap on rewarding points: Without it, a user could join and leave groups indefinitely. We store a counter in user meta and gate the reward.
Why groups_get_group($group_id)->name instead of bp_get_group_name()? bp_get_group_name() is a template tag built for the BuddyPress Groups loop. Outside the loop, it may not render correctly. groups_get_group() returns the group object directly.
How to Deduct Points for Deleting Content on BuddyPress Community Website
If you award points for posting, claw them back when the user deletes the post. BuddyPress triggers bp_activity_before_delete before removal.
add_action(‘bp_activity_before_delete’, ‘deduct_bp_activity_delete’, 10, 2);
function deduct_bp_activity_delete($activities, $r) {
foreach ($activities as $activity) {
if (empty($activity->id)) {
continue;
}
$activity_id = (int) $activity->id;
$user_id = (int) $activity->user_id;
$was_awarded = get_user_meta($user_id, ‘bp_activity_rewarded_’ . $activity_id, true);
if (!$was_awarded) {
continue;
}
mycred_add(
‘bp_activity_deleted’,
$user_id,
-5,
‘Deleted an activity update’,
$activity_id,
”,
MYCRED_DEFAULT_TYPE_KEY
);
delete_user_meta($user_id, ‘bp_activity_rewarded_’ . $activity_id);
}
}
Why deduct points?
The activity existed long enough to generate engagement from others. If someone replies and the original poster deletes it, the reply author keeps their points. The original poster loses theirs for removing the context.
Note on the hook name: The correct hook is bp_activity_before_delete, not bp_before_activity_delete. The latter does not exist. The hook passes an array of IDs, not an args object.
How to Reward Profile Completion Bonus on BuddyPress Community Website
BuddyPress has no single “profile completed” event. Approximate it by checking required fields on xprofile_updated_profile.
add_action(‘xprofile_updated_profile’, ‘reward_bp_profile_completion’, 10, 3);
function reward_bp_profile_completion($user_id, $posted_field_ids, $errors) {
if (!empty($errors)) {
return;
}
// Find these IDs in wp-admin > Users > Profile Fields
$required_fields = array(1, 2, 3); // Name, Bio, Location
$completed = true;
foreach ($required_fields as $field_id) {
$value = xprofile_get_field_data($field_id, $user_id);
if (empty($value)) {
$completed = false;
break;
}
}
if (!$completed) {
return;
}
$already_awarded = get_user_meta($user_id, ‘bp_profile_bonus_awarded’, true);
if ($already_awarded) {
return;
}
myCred_add(
‘bp_profile_completed’,
$user_id,
25,
‘Completed profile information’,
0,
”,
‘myCred_default’
);
update_user_meta($user_id, ‘bp_profile_bonus_awarded’, true);
}
Note: The xprofile_updated_profile hook fires when a user updates their profile through the BuddyPress profile editor. Programmatic xProfile updates may not trigger this hook in every case.
How to Build a Custom myCred Hook Class
If you want toggle switches and point-value fields in the MyCred admin panel, wrap your rewards in a proper hook class.
class BP_Activity_Hook extends myCRED_Hook {
function __construct($hook_prefs, $type = ‘mycred_default’) {
parent::__construct(array(
‘id’ => ‘bp_custom_activity’,
‘defaults’ => array(
‘creds’ => 5,
‘log’ => ‘Activity post reward’,
‘enabled’ => 1
)
), $hook_prefs, $type);
}
function run() {
if ($this->prefs[‘enabled’]) {
add_action(‘bp_activity_add’, array($this, ‘award_points’), 10, 2);
}
}
function award_points($r, $activity_id) {
if (empty($r[‘type’]) || $r[‘type’] !== ‘activity_update’) {
return;
}
$user_id = $r[‘user_id’];
$this->core->add_creds(
‘bp_activity_post’,
$user_id,
$this->prefs[‘creds’],
$this->prefs[‘log’],
$activity_id,
”,
$this->myCred_type
);
}
function preferences() {
// Render admin UI fields here if needed
}
}
add_filter(‘myCred_setup_hooks’, ‘register_bp_custom_hook’, 10, 2);
function register_bp_custom_hook($installed, $point_type) {
$installed[‘bp_custom_activity’] = array(
‘title’ => ‘BuddyPress Activity Rewards’,
‘description’ => ‘Awards points for posting activity updates.’,
‘callback’ => array(‘BP_Activity_Hook’)
);
return $installed;
}
The base class name: It’s myCRED_Hook (uppercase CRED), not myCred_Hook. Get this wrong and PHP throws a fatal error.
This class approach lets non-developers adjust point values from wp-admin.
Debugging Tips on Reward Content Engagement on BuddyPress Community Website
Reward points not triggering? Check in order:
- Hook parameters. bp_activity_add passes an array, not an object. Use $r[‘type’], not $activity->type.
- Duplicate timeout. myCred silently rejects identical transactions within 1 second. Use unique reference IDs or meta flags.
- Point type slug. The default point type is mycred_default, or you can use the MYCRED_DEFAULT_TYPE_KEY constant (all lowercase, no spaces). A leading space or wrong case means points go to a non-existent type and the balance never updates.
- Log entry missing. MyCred requires a log entry string. Empty log = no transaction.
Test triggers with logging:
add_filter(‘myCred_add_routine’, ‘debug_myCred’, 10, 3);
function debug_myCred($result, $request, $myCred) {
error_log(‘MyCred transaction: ‘ . print_r($request, true));
return $result;
}
Check wp-content/debug.log.
Performance Notes on BuddyPress Community Website
- User meta checks (get_user_meta with $single = true) are fast but add a query. On high-volume sites, consider transients or a custom table for duplicate tracking.
- bp_activity_add triggers on every activity type. Gate your function with an early return on type mismatch.
- For high-frequency events like profile views, use JavaScript throttling and AJAX instead of server-side hooks.
Ending Note
BuddyPress exposes the actions. myCred exposes the accounting. The integration is just PHP.
Start with simple add_action patterns for one or two events. Move to a myCred hook class when you need admin controls or multiple point types. Guard against duplicate awards. Provide a way to deduct points when the rewarded action is reversed.
Set it up right and your members see their balance move the moment they post, comment, or join a group. That feedback loop is what turns a passive forum into an active BuddyPress community.
