bp_rest_register_field( string $component_id, string $attribute, array $args = array(), string $object_type = '' )
Registers a new field on an existing BuddyBoss object.
Description
See also
- `register_rest_field()`: for a full description. }
Parameters
- $component_id
-
(Required) The name of the *active* component (eg:
activity,groups,xprofile). Required. - $attribute
-
(Required) The attribute name. Required.
- $args
-
(Optional) An array of arguments used to handle the registered field
Default value: array()
- $object_type
-
(Optional) The xProfile object type to get. This parameter is only required for the Extended Profiles component. Not used for all other components. Possible values are
data,fieldorgroup.Default value: ''
Return
(bool) True if the field has been registered successfully. False otherwise.
Source
File: bp-core/bp-core-rest-api.php
function bp_rest_register_field( $component_id, $attribute, $args = array(), $object_type = '' ) {
$registered_fields = false;
if ( ! $component_id || ! bp_is_active( $component_id ) || ! $attribute ) {
return $registered_fields;
}
// Use the `bp_` prefix as we're using a WordPress global used for Post Types.
$field_name = 'bp_' . $component_id;
// Use the meta type as a suffix for the field name.
if ( 'xprofile' === $component_id ) {
if ( ! in_array( $object_type, array( 'data', 'field', 'group' ), true ) ) {
return $registered_fields;
}
$field_name .= '_' . $object_type;
}
$args = bp_parse_args(
$args,
array(
'get_callback' => null,
'update_callback' => null,
'schema' => null,
),
'rest_register_field'
);
// Register the field.
register_rest_field( $field_name, $attribute, $args );
if ( isset( $GLOBALS['wp_rest_additional_fields'][ $field_name ] ) ) {
$registered_fields = $GLOBALS['wp_rest_additional_fields'][ $field_name ];
}
// Check it has been registered.
return isset( $registered_fields[ $attribute ] );
}
Changelog
| Version | Description |
|---|---|
| BuddyBoss 1.3.5 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.