Advertisement
designbymerovingi

bp point activity with custom message

Feb 17th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /**
  2. * Add BP Activity
  3. * Adds an activity entry when gaining or losing points.
  4. * @version 1.1
  5. */
  6. add_filter( 'mycred_add_finished', 'mycred_to_bp_activity', 999, 3 );
  7. function mycred_to_bp_activity( $reply, $request, $mycred ) {
  8.  
  9. // Only applicable if the points have not been declined and if BP is installed
  10. if ( $reply === false || ! function_exists( 'bp_activity_add' ) ) return $reply;
  11.  
  12. extract( $request );
  13.  
  14. // Construct a log entry so we can use $mycred->parse_template_tags()
  15. $log_entry = new stdClass();
  16. $log_entry->ref = $ref;
  17. $log_entry->user_id = absint( $user_id );
  18. $log_entry->creds = $mycred->number( $amount );
  19. $log_entry->ref_id = $ref_id;
  20. $log_entry->entry = $entry;
  21. $log_entry->data = $data;
  22. $log_entry->ctype = $type;
  23.  
  24. // The activity text
  25. // Ex: John just earned Points for commenting
  26. $entry = bp_core_get_username( $user_id ) . ' just earned ' . $mycred->parse_template_tags( $entry, $log_entry );
  27.  
  28. // Add entry
  29. bp_activity_add( array(
  30. 'user_id' => absint( $user_id ),
  31. 'type' => 'mycred',
  32. 'component' => 'activity',
  33. 'primary_link' => bp_core_get_userlink( (int) $user_id, false, true ),
  34. 'content' => $entry,
  35. 'hide_sitewide' => true // Set to false if you want it included site-wide.
  36. ) );
  37.  
  38. // As a filter we must always return something
  39. return $reply;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement