bp_activity_add()
bp_activity_add()
is used to insert new activity items into the database.
Usage
$activity_id = bp_activity_add( $args );
Parameters
$args
- An array that describes the activity item that you’re creating. Possible values:
'id'
(optional) Pass a numerical id to update an existing activity item'action'
An HTML string summarizing the activity item, which is used by the template when displaying the activity item. Usually contains links to related users, groups, etc. E.g.,'<a href="http://example.com/members/bill">Bill</a> created the group <a href="http://example.com/groups/tmnt">TMNT</a>'
'content'
(optional) The string content of the activity item. In the case of a blog post, for example, you might use an excerpt from the post content. In some cases, it’s appropriate for activity items not to have any content for this field – e.g., when a user creates a new group.'component'
A string denoting the unique “component” that this activity item is associated with. BuddyPress components are ‘groups’, ‘members’, etc. If you are writing a BuddyPress plugin, you might consider having a single component name for all activity in your plugin.'type'
A string denoting the specific kind of activity being created. This should be more specific than'component'
. For example, when creating a group, BuddyPress posts an activity item with the component ‘groups’ and the type ‘created_group’.'type'
is used for filtering, as in the “New Groups”, “New Blog Posts”, etc dropdown on Activity directories.'primary_link'
(optional) The primary URL associated with the activity item. BuddyPress uses this value when creating activity RSS feeds, to tell the feed reader where to find the original item. If you omit this value, the fallback value is the permalink page for the single activity item.'user_id'
(optional) The unique numeric id of the user associated with the activity item. In BuddyPress, the primary use of this value is to filter which items appear on the Activity tab of an individual member’s profile. If the value is omitted, it will default to the id of the currently logged-in user. Note that you can pass0
for items that may be associated with no user at all.'item_id'
(optional) The numeric ID of the primary item associated with this activity item. For example, when recording the creation of a group, BuddyPress sets the'item_id'
to the numeric id of the newly created group. This value can be used for filtering.'secondary_item_id'
(optional) A second numeric ID for further filtering. For example, when recording a new blog comment, BuddyPress sets the'item_id'
to the ID of the blog, and the'secondary_item_id'
to the ID of the comment.'recorded_time'
(optional) The time the activity is recorded. Should be in GMT, MySQL format. (In PHP,date( 'Y-m-d H:i:s', $time )
.) Defaults to the current time.'hide_sitewide'
(optional)'hide_sitewide'
is used in a few different ways:- To prevent duplicate entries when viewing the sitewide activity stream. For instance, when a new friendship is established, two activity items are created: one with
'user_id'
set to the user who sent the request and'item_id'
set to recipient, and the other one vice versa. We need both items so that both users see the item on their own profiles, but it’s not desirable to see both of them on the sitewide stream, so the second one is marked'hide_sitewide' => true
. - To prevent activity items from hidden or private groups from appearing in sitewide activity streams. That is, when an activity item is posted to a non-public group,
'hide_sitewide'
is set tofalse
. Then, when viewing the group’s activity stream (which is accessible only to members), BP includes'hide_sitewide'
items; in contrast, the sitewide stream excludes these items.
Thus,
'hide_sitewide'
is used simultaneously for preventing duplicates and for privacy. Please be sure you understand the way that'hide_sitewide'
works before attempting to use it for the purposes of privacy in your own plugins.- To prevent duplicate entries when viewing the sitewide activity stream. For instance, when a new friendship is established, two activity items are created: one with
'is_spam'
(optional) Set totrue
to mark an item as spam.
Return value
New database row activity ID
Source File
bp_activity_add()
is located in bp-activity/bp-activity-functions.php