Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resoved] Posting custom type activity vía bp_activity_add() in groups


  • juanmaguerrero
    Participant

    @juanmaguerrero

    Hi everyone!

    I’m successfully posting activity in the main activity page and the user’s profile using this:

    
    bp_activity_add(
    array(
    'action' => $action,
    'content' => $content,
    'component' => 'activity',
    'type' => $type,
    'user_id' => $user_id
    )
    )
    

    $action, $content, $type, etc. are dynamically changed and it posts ok.

    But I cannot achieve this when trying to post within a GROUP. Only to the short function:

    
    groups_post_update(array('content' => $content, 'group_id' => $gid))
    

    But using that I can not customize the action or the type (or I’m making something wrong).

    I tried also:

    
    bp_activity_add(
    array(
    'action' => $action,
    'content' => $content,
    'component' => 'activity',
    'type' => $type,
    'group_id' => $gid,
    'user_id' => $user_id
    )
    )
    

    But with no effect (the activity keeps being posted ‘outside’ the group).

    Please if someone could help me, I’m using this on a plugin that will then share with the community :D

    Thanks to all in advance!

Viewing 4 replies - 1 through 4 (of 4 total)

  • Roger Coathup
    Participant

    @rogercoathup

    Off the top of my head –

    You’ll need to set the component as ‘group’ (groups?), as it’s activity related to groups not to the activity stream.

    I’m not sure how it will handle ‘action’ and ‘type’ if they’ve not been pre-registered by the groups component — unfortunately, you might have to trawl through the code to work that out.

    You might also want to use: groups_record_activity() rather than going directly to bp_activity_add()


    juanmaguerrero
    Participant

    @juanmaguerrero

    @rogercoathup thanks for your help, do you have any links for documentation on that function? I’ll try to find out in the meantime :) If someone else has an example for what I need it would be awesome


    Roger Coathup
    Participant

    @rogercoathup

    I doubt there’s any documentation — so, you’ll have to search your codebase for it, and then walk through the code (it’s clearly coded — so, not a problem to read what’s happening).

    You’ll find the function in bp-groups-activity.php


    juanmaguerrero
    Participant

    @juanmaguerrero

    @rogercoathup thanks to your help I just achieved what I wanted :)

    I’m doing this now and it’s working fine (still will polish it a bit more):

    
    if ( !isset( $bp->groups->current_group ) || !$bp->groups->current_group || $gid != $bp->groups->current_group->id ) {
    $group = groups_get_group( array( 'group_id' => $gid ) );
    } else {
    $group = $bp->groups->current_group;
    };
    
    groups_record_activity( array(
    'action'  => apply_filters( 'groups_activity_new_update_action', sprintf( __( '%1$s publicó una actualización en %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),
    'content'   => $content,
    'type'    => $type,
    'item_id' => $gid,
    'user_id' => $user_id
    )
    )
    

    Thanks a lot for your help!!! :D

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resoved] Posting custom type activity vía bp_activity_add() in groups’ is closed to new replies.
Skip to toolbar