سؤال

Does anybody know the basic steps on how to add a custom event item to the Buddypress activity stream? I've got a custom post type of "activity" that my members can click on in the post and it records in a database table that that user has "completed" that activity. More or less like a "to do" list. I'm trying to figure out how I can integrate this with the buddypress activity stream so when a user clicks the button, it inserts something like, "John Doe has completed Permalinked Post Title Here." I've looked through the Buddypress codex & have Googled quite a bit, but I can't seem to find any good tutorials on this. If anybody can point me in the right direction or give me a simple plain English step by step I would appreciate it. Please know that I'm not looking for any code written, just a general idea of the steps involved in making this happen.

For anyone who is searching, this is what I wrote in my php file that was called in the ajax request for the button that "completes" the activity...

// Begin Code for Custom Activity Stream
global $wp, $wp_query;
$this_activity_object = get_post( $activity_post_id_complete ); 
$title = $this_activity_object->post_title; 
$activity_content = $title;
$this_user_profile_url = bp_core_get_user_domain($wp_user_id);  
$action_String = "<a href=\"". $this_user_profile_url ."\">@" . bp_core_get_username($wp_user_id)."</a> just completed a custom activity!";

global $bp;
bp_activity_add( array(     
    'user_id' => $wp_user_id,
    'item_id' => $activity_db_id_complete,
    'action' => $action_String,
    'content' => $activity_content,
    'component' => 'activity',
    'primary_link' => '<a href="'.get_post_permalink($this_activity_id).'">' . $title . '</a>',
    'type' => 'custom_activity_update',
    'hide_sitewide' => false
));
هل كانت مفيدة؟

المحلول

You can use bp_activity_add(). For example, you'd do it like this:

// record an activity item to the activity table

bp_activity_add( array(
    'id' => $id
    'user_id' => $user_id,
    'item_id' => $item_id,
    'action' => $action,
    'content' => $content,
    'component' => $component,
    'primary_link' => $link,
    'type' => $type,
    'secondary_item_id' => $secondary_item_id,
    'recorded_time' => $time,
    'hide_sitewide' => false,
    'is_spam' => $spam
));

Ref explaining what the parameters mean:

http://codex.buddypress.org/developer/function-examples/bp_activity_add/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top