package BuddyPress

 Methods

Constructor method.

__construct(integer|boolean $id = false
since 1.5.0

Parameters

$id

integerboolean

Optional. The ID of a specific activity item.

Append activity comments to their associated activity items.

append_comments(array $activities, string $spam = 'ham_only') : array
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$activities

array

Activities to fetch comments for.

$spam

string

Optional. 'ham_only' (default), 'spam_only' or 'all'.

Returns

arrayThe updated activities with nested comments.

Check whether an activity item exists with a given string content.

check_exists_by_content(string $content) : integer | false
Static
since 1.1.0
global wpdb $wpdb WordPress database object.

Parameters

$content

string

The content to filter by.

Returns

integerfalseThe ID of the first matching item if found, otherwise false.

Delete activity items from the database.

delete(array $args = array()) : array | boolean
Static

To delete a specific activity item, pass an 'id' parameter. Otherwise use the filters.

since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$args

array

{ @int $id Optional. The ID of a specific item to delete. @string $action Optional. The action to filter by. @string $content Optional. The content to filter by. @string $component Optional. The component name to filter by. @string $type Optional. The activity type to filter by. @string $primary_link Optional. The primary URL to filter by. @int $user_id Optional. The user ID to filter by. @int $item_id Optional. The associated item ID to filter by. @int $secondary_item_id Optional. The secondary associated item ID to filter by. @string $date_recorded Optional. The date to filter by. @int $hide_sitewide Optional. Default: false. }

Returns

arraybooleanAn array of deleted activity IDs on success, false on failure.

Delete the comments associated with a set of activity items.

delete_activity_item_comments(array $activity_ids = array(), boolean $delete_meta = true) : boolean
Static

This method is no longer used by BuddyPress, and it is recommended not to use it going forward, and use BP_Activity_Activity::delete() instead.

since 1.2.0
global wpdb $wpdb WordPress database object.
deprecated 2.3.0

Parameters

$activity_ids

array

Activity IDs whose comments should be deleted.

$delete_meta

boolean

Should we delete the activity meta items for these comments.

Returns

boolean

Delete the meta entries associated with a set of activity items.

delete_activity_meta_entries(array $activity_ids = array()) : boolean
Static
since 1.2.0

Parameters

$activity_ids

array

Activity IDs whose meta should be deleted.

Returns

boolean

Get activity items, as specified by parameters.

get(array $args = array()) : array
Static
since 1.2.0
since 2.4.0 Introduced the `$fields` parameter.
since 2.9.0 Introduced the `$order_by` parameter.
since 10.0.0 Introduced the `$count_total_only` parameter.
since 11.0.0 Introduced the `$user_id__in` and `$user_id__not_in` parameters.
see for a description of the 'filter' parameter.
see for a description of the 'meta_query' parameter format.
global wpdb $wpdb WordPress database object.

Parameters

$args

array

{ An array of arguments. All items are optional. @type int $page Which page of results to fetch. Using page=1 without per_page will result in no pagination. Default: 1. @type int|bool $per_page Number of results per page. Default: 25. @type int|bool $max Maximum number of results to return. Default: false (unlimited). @type string $fields Activity fields to return. Pass 'ids' to get only the activity IDs. 'all' returns full activity objects. @type string $sort ASC or DESC. Default: 'DESC'. @type string $order_by Column to order results by. @type array $exclude Array of activity IDs to exclude. Default: false. @type array $in Array of ids to limit query by (IN). Default: false. @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries. @type array $date_query Array of date_query conditions. See first parameter of WP_Date_Query::construct(). @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct(). @type string|array $scope Pre-determined set of activity arguments. @type array $filter See BP_Activity_Activity::get_filter_sql(). @type array $user_idin An array of user ids to include. Activity posted by users matching one of these user ids will be included in results. Default empty array. @type array $user_id__not_in An array of user ids to exclude. Activity posted by users matching one of these user ids will not be included in results. Default empty array. @type string $search_terms Limit results by a search term. Default: false. @type bool $display_comments Whether to include activity comments. Default: false. @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false. @type string $spam Spam status. Default: 'ham_only'. @type bool $cache_results Optional. Whether to cache activity information. Default true. @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true. @type string|bool $count_total If true, an additional DB query is run to count the total activity items for the query. Default: false. @type bool $count_total_only If true, only the DB query to count the total activity items is run. Default: false. }

Returns

arrayThe array returned has two keys: - 'total' is the count of located activities - 'activities' is an array of the located activities

Get activity comments that are associated with a specific activity ID.

get_activity_comments(integer $activity_id, integer $left, integer $right, string $spam = 'ham_only', integer $top_level_parent_id = 0) : array
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$activity_id

integer

Activity ID to fetch comments for.

$left

integer

Left-most node boundary.

$right

integer

Right-most node boundary.

$spam

string

Optional. 'ham_only' (default), 'spam_only' or 'all'.

$top_level_parent_id

integer

Optional. The id of the root-level parent activity item.

Returns

arrayThe updated activities with nested comments.

Get child comments of an activity or activity comment.

get_child_comments(integer $parent_id) : object
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$parent_id

integer

ID of an activity or activity comment.

Returns

objectNumerically indexed array of child comments.

Get the SQL for the 'date_query' param in BP_Activity_Activity::get().

get_date_query_sql(array $date_query = array()) : string
Static

We use BP_Date_Query, which extends WP_Date_Query, to do the heavy lifting of parsing the date_query array and creating the necessary SQL clauses.

since 2.1.0

Parameters

$date_query

array

An array of date_query parameters. See the documentation for the first parameter of WP_Date_Query.

Returns

string

Create filter SQL clauses.

get_filter_sql(array $filter_array) : string
Static
since 1.5.0

Parameters

$filter_array

array

{ Fields and values to filter by.

@type array|string|int $user_id      User ID(s).
@type array|string     $object       Corresponds to the 'component'
                                     column in the database.
@type array|string     $action       Corresponds to the 'type' column
                                     in the database.
@type array|string|int $primary_id   Corresponds to the 'item_id'
                                     column in the database.
@type array|string|int $secondary_id Corresponds to the
                                     'secondary_item_id' column in the database.
@type int              $offset       Return only those items with an ID greater
                                     than the offset value.
@type int              $offset_lower Return only those items with an ID lower
                                     than the offset value.
@type string           $since        Return only those items that have a
                                     date_recorded value greater than a
                                     given MySQL-formatted date.

}

Returns

stringThe filter clause, for use in a SQL query.

Get the first activity ID that matches a set of criteria.

get_id(array $args = array()) : integer | false
Static
since 1.2.0
since 10.0.0 Parameters were made optional.
global wpdb $wpdb WordPress database object.

Parameters

$args

array

{ An array of arguments. All items are optional. @type int $user_id User ID to filter by. @type string $component Component to filter by. @type string $type Activity type to filter by. @type int $item_id Associated item to filter by. @type int $secondary_item_id Secondary associated item to filter by. @type string $action Action to filter by. @type string $content Content to filter by. @type string $date_recorded Date to filter by. }

Returns

integerfalseActivity ID on success, false if none is found.

Create SQL IN clause for filter queries.

get_in_operator_sql(string $field, array|boolean $items) : string | false
Static
since 1.5.0
see
global wpdb $wpdb WordPress database object.

Parameters

$field

string

The database field.

$items

arrayboolean

The values for the IN clause, or false when none are found.

Returns

stringfalse

Get the date/time of last recorded activity.

get_last_updated() : string
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Returns

stringISO timestamp.

Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().

get_meta_query_sql(array $meta_query = array()) : array
Static

We use WP_Meta_Query to do the heavy lifting of parsing the meta_query array and creating the necessary SQL clauses. However, since BP_Activity_Activity::get() builds its SQL differently than WP_Query, we have to alter the return value (stripping the leading AND keyword from the 'where' clause).

since 1.8.0
global wpdb $wpdb WordPress database object.

Parameters

$meta_query

array

An array of meta_query filters. See the documentation for WP_Meta_Query for details.

Returns

array$sql_array 'join' and 'where' clauses.

Get a list of components that have recorded activity associated with them.

get_recorded_components(boolean $skip_last_activity = true) : array
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$skip_last_activity

boolean

If true, components will not be included if the only activity type associated with them is 'last_activity'. (Since 2.0.0, 'last_activity' is stored in the activity table, but these items are not full-fledged activity items.) Default: true.

Returns

arrayList of component names.

Get the SQL for the 'scope' param in BP_Activity_Activity::get().

get_scope_query_sql(mixed $scope = false, array $r = array()) : false | array
Static

A scope is a predetermined set of activity arguments. This method is used to grab these activity arguments and override any existing args if needed.

Can handle multiple scopes.

since 2.2.0

Parameters

$scope

mixed

The activity scope. Accepts string or array of scopes.

$r

array

Current activity arguments. Same as those of BP_Activity_Activity::get(), but merged with defaults.

Returns

falsearray'sql' WHERE SQL string and 'override' activity args.

Get sitewide activity items for use in an RSS feed.

get_sitewide_items_for_feed(integer $limit = 35) : array
Static
since 1.0.0

Parameters

$limit

integer

Optional. Number of items to fetch. Default: 35.

Returns

array$activity_feed List of activity items, with RSS data added.

In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).

get_specific(mixed $activity_ids, integer|boolean $max = false, integer $page = 1, integer $per_page = 25, string $sort = 'DESC', boolean $display_comments = false) : array
Static

As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.

since 1.2.0
deprecated 1.5
deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead.

Parameters

$activity_ids

mixed

Array or comma-separated string of activity IDs to retrieve.

$max

integerboolean

Maximum number of results to return. (Optional; default is no maximum).

$page

integer

The set of results that the user is viewing. Used in pagination. (Optional; default is 1).

$per_page

integer

Specifies how many results per page. Used in pagination. (Optional; default is 25).

$sort

string

MySQL column sort; ASC or DESC. (Optional; default is DESC).

$display_comments

boolean

Retrieve an activity item's associated comments or not. (Optional; default is false).

Returns

array

Hide all activity for a given user.

hide_all_for_user(integer $user_id) : mixed
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$user_id

integer

The ID of the user whose activity you want to mark hidden.

Returns

mixed

Populate the object with data about the specific activity item.

populate() 
since 1.0.0
global wpdb $wpdb WordPress database object.

Rebuild nested comment tree under an activity or activity comment.

rebuild_activity_comment_tree(integer $parent_id, integer $left = 1) : integer
Static
since 1.2.0
global wpdb $wpdb WordPress database object.

Parameters

$parent_id

integer

ID of an activity or activity comment.

$left

integer

Node boundary start for activity or activity comment.

Returns

integerRight Node boundary of activity or activity comment.

Save the activity item to the database.

save() : \WP_Error | boolean
since 1.0.0
global wpdb $wpdb WordPress database object.

Returns

\WP_ErrorbooleanTrue on success.

Get favorite count for a given user.

total_favorite_count(integer $user_id) : integer
Static
since 1.2.0

Parameters

$user_id

integer

The ID of the user whose favorites you're counting.

Returns

integer$value A count of the user's favorites.

Append xProfile fullnames to an activity array.

append_user_fullnames(array $activities) : array
Static
since 2.0.0

Parameters

$activities

array

Activities array.

Returns

array

Generate action strings for the activities located in BP_Activity_Activity::get().

generate_action_strings(array $activities) : array
Static

If no string can be dynamically generated for a given item (typically because the activity type has not been properly registered), the static 'action' value pulled from the database will be left in place.

since 2.0.0

Parameters

$activities

array

Array of activities.

Returns

array

Convert activity IDs to activity objects, as expected in template loop.

get_activity_data(array $activity_ids = array(), boolean $cache_results = true) : array
Static
since 2.0.0
since 15.0.0 Added the `$cache_results` parameter.
global wpdb $wpdb WordPress database object.

Parameters

$activity_ids

array

Array of activity IDs.

$cache_results

boolean

Optional. Whether to cache activity information. Default true.

Returns

array

Pre-fetch data for objects associated with activity items.

prefetch_object_data(array $activities) : array
Static

Activity items are associated with users, and often with other BuddyPress data objects. Here, we pre-fetch data about these associated objects, so that inline lookups - done primarily when building action strings - do not result in excess database queries.

The only object data required for activity component activity types (activity_update and activity_comment) is related to users, and that info is fetched separately in BP_Activity_Activity::get_activity_data(). So this method contains nothing but a filter that allows other components, such as bp-friends and bp-groups, to hook in and prime their own caches at the beginning of an activity loop.

since 2.0.0

Parameters

$activities

array

Array of activities.

Returns

array$activities Array of activities.

 Properties

 

Description of the activity, eg 'Alex updated his profile.'.

$action : string

Default

''
since 1.2.0
 

BuddyPress component the activity item relates to.

$component : string

Default

''
since 1.2.0
 

The content of the activity item.

$content : string

Default

''
since 1.2.0
 

The date the activity item was recorded, in 'Y-m-d h:i:s' format.

$date_recorded : string

Default

''
since 1.0.0
 

Error type to return. Either 'bool' or 'wp_error'.

$error_type : string

Default

'bool'
since 2.6.0
 

Error holder.

$errors : \WP_Error

Default

since 2.6.0
 

Whether the item should be hidden in sitewide streams.

$hide_sitewide : integer

Default

0
since 1.1.0
 

ID of the activity item.

$id : integer

Default

since 1.0.0
 

Whether this item is marked as spam.

$is_spam : integer

Default

since 1.6.0
 

ID of the associated item.

$item_id : integer

Default

since 1.0.0
 

Node boundary start for activity or activity comment.

$mptt_left : integer

Default

since 1.5.0
 

Node boundary end for activity or activity comment.

$mptt_right : integer

Default

since 1.5.0
   

ID of the associated secondary item.

$secondary_item_id : integer

Default

since 1.0.0
 

Activity type, eg 'new_blog_post'.

$type : string

Default

''
since 1.2.0
 

ID of user associated with the activity item.

$user_id : integer

Default

since 1.0.0