Advertisement
designbymerovingi

myCRED Activity to BP Activity

Dec 2nd, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. add_filter( 'mycred_add', 'mycred_to_bp_activity', 999, 3 );
  2. function mycred_to_bp_activity( $reply, $request, $mycred ) {
  3.  
  4.     // Only applicable if the points have not been declined and if BP is installed
  5.     if ( $reply === false || ! function_exists( 'bp_activity_add' ) ) return $reply;
  6.  
  7.     extract( $request );
  8.  
  9.     // Construct a log entry so we can use $mycred->parse_template_tags()
  10.     $log_entry = new stdClass();
  11.     $log_entry->ref = $ref;
  12.     $log_entry->user_id = (int) $user_id;
  13.     $log_entry->creds = $mycred->number( $amount );
  14.     $log_entry->ref_id = $ref_id;
  15.     $log_entry->entry = $entry;
  16.     $log_entry->data = $data;
  17.     $log_entry->ctype = $type;
  18.  
  19.     // Add entry
  20.     bp_activity_add( array(
  21.         'user_id'       => (int) $user_id,
  22.         'type'          => 'mycred',
  23.         'component'     => 'activity',
  24.         'primary_link' => bp_core_get_userlink( (int) $user_id, false, true ),
  25.         'content'       => $mycred->parse_template_tags( $entry, $log_entry ),
  26.         'hide_sitewide' => false
  27.     ) );
  28.  
  29.     // As a filter we must always return something
  30.     return $reply;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement