Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using bp_activity_add() to update an activity


  • Matthew Holt
    Participant

    @webdevmatt

    When using bp_activity_add() to update an activity, I am having a bit of a challenge. I have tried two approaches:
    1. create an array of the elements needed to update, with a known activity id and pass them to bp_activity_add()
    eg.
    `$activity=array(‘id’=>533,’hide_sitewide’ => true,’content’=>’test 1′, ‘action’=>’test test’);
    do_action(‘bp_activity_add’,$activity);`
    2. Create an activity object and add assign the ID property and pass it to bp_activity_add()
    eg.
    `$activity = new BP_Activity_Activity ();
    $activity->ID=533;
    $activity->hide_sitewide=true;
    $activity->content=”test 1″;
    $activity->action=”test test”;
    do_action(‘bp_activity_add’,$activity);`

    What am I missing? Is there a different way to do this?

    Please advise.

Viewing 8 replies - 1 through 8 (of 8 total)
  • something like:

    `
    $activity_id = bp_activity_add( array( ‘id’ => 555, ‘action’ => ‘something new and blue’ );
    `

    no reason to use the do_action – that is just a trigger point for hooking into buddypress.

    make sure you capture all the previous activity data and pass that back in – performs a full sql update on all cols (see the code in https://wordpress.org/extend/plugins/buddypress-edit-activity-stream/ )


    Matthew Holt
    Participant

    @webdevmatt

    Odd, no luck. Data is not changed, and nothing is returned in $activity_id. Any thoughts?

    @nuprn1 are you saying that I need to capture all the activity data and pass it back to the bp_activity_add() in order for the update to be executed?


    r-a-y
    Keymaster

    @r-a-y

    Change “action” to “content” in Rich’s code.


    Matthew Holt
    Participant

    @webdevmatt

    I actually did that as well and had the same result :(.
    `$activity_id = bp_activity_add( array( ‘id’ => 468, ‘content’ => ‘something new and blue’ ));`

    You would think one of these would work.


    Matthew Holt
    Participant

    @webdevmatt

    I have tried attempting this from a couple different pages. Originally from post-form.php and also from the main activity loop with no luck. It doesn’t appear that I’m doing anything special?


    nicholmikey
    Participant

    @nicholmikey

    Did anyone get a solution to this? I have tried several methods of adding activities to the stream with no luck.


    nicholmikey
    Participant

    @nicholmikey

    So far I have tracked the problem to bp-activity-classes, in the save() function, for some reason {$bp->activity->table_name} is returning nothing so the SQL structure ends up missing a table name. Makes no sense as other plugins like bbpress uses this save() feature and works fine.

    The table_name variable is populated during init, so looks like you’re calling bp_activity_add before bp is initialized. Try doing that during init with a lower priority, like 99. Worked for me 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Using bp_activity_add() to update an activity’ is closed to new replies.
Skip to toolbar