Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lordmatt/c7979e7b90a3d0209818568b098a8ea0 to your computer and use it in GitHub Desktop.
Save lordmatt/c7979e7b90a3d0209818568b098a8ea0 to your computer and use it in GitHub Desktop.
<?php
/*
* This is an example of adding activity to a BuddyPress group.
*
* I cribbed it pretty much wholesale from EGB
* @link https://github.com/lordmatt/external-group-blogs/
*
* You will almost certainly need to do some work and testing
* to get something useful from this code.
*
*/
// Get the group ID somehow - for example:
$group_id = bp_get_current_group_id();
$hide_sitewide = true;
// get the activity date somehow, for a very poor example:
$post_date = date("l jS \of F Y h:i:s A");
$link = 'http://example.com';
$aid = groups_record_activity( array(
'id' => null,
'user_id' => false,
'action' => 'My Activity Action',
'content' => 'My Activity Content',
'primary_link' => $link,
'type' => 'my_type',
'item_id' => $group_id,
'recorded_time' => gmdate( "Y-m-d H:i:s", $post_date ),
'hide_sitewide' => $hide_sitewide
) );
// add meta data to activity
bp_activity_update_meta( $aid, 'my_key', 'My Value' );
// update the last activity value for the group
groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment