Add the following page to developer doc: - Introduction about the BP REST API - Reference: list of REST API Routes - Components routes - Members routes NB: this commit also improves Components and Members REST controllers item schemas. See https://buddypress.trac.wordpress.org/ticket/9145 Closes https://github.com/buddypress/buddypress/pull/382 git-svn-id: https://buddypress.svn.wordpress.org/trunk@14042 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
4.1 KiB
Components REST API routes
BuddyPress chose a modular approach using components to organize its features. Two components are loaded by default (eg: BuddyPress Core and Community Members) while the majority are optional. BuddyPress comes with 8 built-in optional components (Account Settings, Activity Streams, Extended Profiles, Friend connections, Notifications, Private messaging, User groups and Site Tracking).
Important
It’s important to note there can be more than one optional component from BuddyPress plugins installed on the website: these plugins can use the BuddyPress Component API to incorporate the lists of active or inactive components.
Schema
The schema defines all the fields that exist for BuddyPress components.
| Property | Description |
|---|---|
name |
Key name of the component. JSON data type: string. Context: view, edit. |
is_active |
Whether the component is active or not. JSON data type: boolean. Default: false. Context: view, edit. |
status |
Whether the component is active or inactive. JSON data type: string. Context: view, edit. One of: active, inactive. |
title |
Title of the component. JSON data type: string. Context: view, edit. |
description |
Description of the component. JSON data type: string. Context: view, edit. |
features |
Information about active features for the component. JSON data type: object | null. Default: null. Context: view, edit. |
List the BuddyPress components
Arguments
| Name | Description |
|---|---|
context |
Scope under which the request is made; determines fields present in response. JSON data type: string. Default: view. One of: view, edit. |
page |
Current page of the collection. JSON data type: integer. Default: 1. |
per_page |
Maximum number of components to be returned in result set. JSON data type: integer. Default: 10. |
search |
Limit results to those matching a string. JSON data type: string. |
status |
Limit result set to components with a specific status. JSON data type: string. Default: all. One of: all, active, inactive. |
type |
Information about active features for the component. JSON data type: string. Default: all. One of: all, optional, retired, required. |
Definition
GET /buddypress/v2/components
Example of use
Warning
The
requestHeadersobject needs to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/components?context=edit&status=active', {
method: 'GET',
headers: requestHeaders,
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.table( data );
} );
JSON Response
- An array of objects representing the matching components on success.
- An object containg the error code, data and message on failure.
Activate or Deactivate a BuddyPress component
Arguments
| Name | Description |
|---|---|
name |
Key name of the component. Required. JSON data type: string. |
action |
Whether to activate or deactivate the component. Required. JSON data type: string. One of: activate, deactivate. |
Definition
PUT /buddypress/v2/components
Example of use
Warning
The
requestHeadersneeds to be set according to the WordPress REST API nonce. Read more about the REST API authentification.
fetch( '/wp-json/buddypress/v2/components', {
method: 'PUT',
headers: requestHeaders,
body: JSON.stringify( { name: 'groups', action: 'activate' } ),
} ).then( ( response ) => {
return response.json();
} ).then( ( data ) => {
console.log( data );
} );
JSON Response
- An object representing the updated component on success.
- An object containg the error code, data and message on failure.