BP_REST_XProfile_Field_Groups_Endpoint::prepare_item_for_response( BP_XProfile_Group $group, WP_REST_Request $request )
Prepares single XProfile field group data for return as an object.
Description
Parameters
- $group
-
(Required) XProfile field group data.
- $request
-
(Required) Full data about the request.
Return
(WP_REST_Response)
Source
File: bp-xprofile/classes/class-bp-rest-xprofile-field-groups-endpoint.php
public function prepare_item_for_response( $group, $request ) { $data = array( 'id' => (int) $group->id, 'name' => $group->name, 'description' => array( 'raw' => $group->description, 'rendered' => apply_filters( 'bp_get_the_profile_field_description', $group->description ), ), 'group_order' => (int) $group->group_order, 'can_delete' => (bool) $group->can_delete, 'repeater_enabled' => false, ); // Check for repeater set is enable of not. $repeater_enabled = bp_xprofile_get_meta( $group->id, 'group', 'is_repeater_enabled', true ); if ( ! empty( $repeater_enabled ) && 'on' === $repeater_enabled ) { $data['repeater_enabled'] = true; } // If the fields have been requested, we populate them. if ( $request['fetch_fields'] ) { $data['fields'] = array(); foreach ( $group->fields as $field ) { /** * Added support for display name format support from platform. */ // Get the current display settings from BuddyBoss > Settings > Profiles > Display Name Format. $current_value = bp_get_option( 'bp-display-name-format' ); // If First Name selected then do not add last name field. if ( 'first_name' === $current_value && function_exists( 'bp_xprofile_lastname_field_id' ) && bp_xprofile_lastname_field_id() === $field->id ) { if ( function_exists( 'bp_hide_last_name' ) && false === bp_hide_last_name() ) { continue; } // If Nick Name selected then do not add first & last name field. } elseif ( 'nickname' === $current_value && function_exists( 'bp_xprofile_lastname_field_id' ) && bp_xprofile_lastname_field_id() === $field->id ) { if ( function_exists( 'bp_hide_nickname_last_name' ) && false === bp_hide_nickname_last_name() ) { continue; } } elseif ( 'nickname' === $current_value && function_exists( 'bp_xprofile_firstname_field_id' ) && bp_xprofile_firstname_field_id() === $field->id ) { if ( function_exists( 'bp_hide_nickname_first_name' ) && false === bp_hide_nickname_first_name() ) { continue; } } if ( function_exists( 'bp_member_type_enable_disable' ) && false === bp_member_type_enable_disable() ) { if ( function_exists( 'bp_get_xprofile_member_type_field_id' ) && bp_get_xprofile_member_type_field_id() === $field->id ) { continue; } } /** * --Added support for display name format support from platform. */ $data['fields'][] = $this->fields_endpoint->assemble_response_data( $field, $request ); } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $response->add_links( $this->prepare_links( $group ) ); /** * Filter the XProfile field group returned from the API. * * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request Request used to generate the response. * @param BP_XProfile_Group $group XProfile field group. * * @since 0.1.0 */ return apply_filters( 'bp_rest_xprofile_field_groups_prepare_value', $response, $request, $group ); }
Changelog
Version | Description |
---|---|
0.1.0 | 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.