Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add BP Activity
- * Adds an activity entry when gaining or losing points.
- * @version 1.1
- */
- add_filter( 'mycred_add_finished', 'mycred_to_bp_activity', 999, 3 );
- function mycred_to_bp_activity( $reply, $request, $mycred ) {
- // Only applicable if the points have not been declined and if BP is installed
- if ( $reply === false || ! function_exists( 'bp_activity_add' ) ) return $reply;
- extract( $request );
- // Construct a log entry so we can use $mycred->parse_template_tags()
- $log_entry = new stdClass();
- $log_entry->ref = $ref;
- $log_entry->user_id = absint( $user_id );
- $log_entry->creds = $mycred->number( $amount );
- $log_entry->ref_id = $ref_id;
- $log_entry->entry = $entry;
- $log_entry->data = $data;
- $log_entry->ctype = $type;
- // The activity text
- // Ex: John just earned Points for commenting
- $entry = bp_core_get_username( $user_id ) . ' just earned ' . $mycred->parse_template_tags( $entry, $log_entry );
- // Add entry
- bp_activity_add( array(
- 'user_id' => absint( $user_id ),
- 'type' => 'mycred',
- 'component' => 'activity',
- 'primary_link' => bp_core_get_userlink( (int) $user_id, false, true ),
- 'content' => $entry,
- 'hide_sitewide' => true // Set to false if you want it included site-wide.
- ) );
- // As a filter we must always return something
- return $reply;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement