AppCommunity Hooks and Filters

AppCommunity uses a modified version of the BuddyPress REST API. You can use filters and action hooks to modify API responses.

Sample Code

This sample code uses the hooks and filters below to add custom content to the app.

Notify admin of bad words:  https://gist.github.com/scottopolis/bd55d1216296d530aa0bec086a9c3268

Include nested replies: https://gist.github.com/stillatmylinux/2bb2d5c715b16ddd6d8fe017a4eeddb5

Add custom profile fields: https://gist.github.com/scottopolis/be6670978bf8c2e94de2d35206b66bc9

Add custom member fields: https://gist.github.com/scottopolis/e5d9fc1f195dcdac8f0eacb7f6ddbd38

Filter activity feed: https://gist.github.com/scottopolis/4268054f1efb08958f645bc941a9ca92

Extend activity type: https://gist.github.com/scottopolis/4268054f1efb08958f645bc941a9ca92

Filters

Filters are mainly used to change the arguments before a response is created. For example, you can change what activity items are shown in the activity feed using a filter like this: https://gist.github.com/scottopolis/f40d4a97ad7cc1ee38595563c89fe718

Each component has a filter to get items with 2 arguments: $args and $request: appcommunity_{component}_get_items_args

See the gist above for an example.

Available filters:

  • appcommunity_activity_get_items_args
  • appcommunity_members_get_items_args
  • appcommunity_groups_get_items_args
  • appcommunity_messages_get_items_args

Action Hooks

Action hooks are mainly used to do something  after the API response has been created. For example, you could look at the response object and send an email to the admin if there is a curse word in it.

Most hooks have 3 arguments unless otherwise noted: $items, $retval, $request

Available hooks:

  • appcommunity_activity_get_items

  • appcommunity_activity_get_item

  • appcommunity_activity_create_item

  • appcommunity_activity_create_item_with_image

  • appcommunity_activity_update_item

  • appcommunity_friends_get_requests ( only 2 arguments )

  • appcommunity_groups_get_items

  • appcommunity_group_get_item

  • appcommunity_members_get_items

  • appcommunity_members_get_item

  • appcommunity_messages_get_items

  • appcommunity_messages_get_item ( 2 arguments )

  • appcommunity_notification_get_items

Template Hooks

AppCommunity has template hooks in the app files. These are used to display extra content in the app, for example add extra member profile fields to the profile page.

These are used a little bit differently than our other template hooks, but the concept is the same. Instead of adding data to a post type, you need to add data to a certain API response. View the example code here.

Profile custom content

Available template hooks:

  • appp.below_content
  • appp.above_content

Use these with the following filters:

  • appcommunity_prepare_user
  • appcommunity_prepare_group

Member custom content

Available template hooks:

  • before_item
  • after_item

Use these with the following filters:

  • bp_rest_members_prepare_value

API Endpoints

AppCommunityuses the following API Endpoints for retrieving data. You can test these endpoints using a tool like Postman to see exactly what data WordPress passes to the app.

Activity:wp-json/ap-bp/v1/activity

Activity from specific Group ID:wp-json/ap-bp/v1/activity/?primary_id=#

Messages:wp-json/ap-bp/v1/messages

Groups:wp-json/ap-bp/v1/groups

Members:

wp-json/ap-bp/v1/members