BP_REST_XProfile_Fields_Endpoint::get_items( WP_REST_Request $request )
Retrieve XProfile fields.
Description
Parameters
- $request
-
(Required) Full data about the request.
Return
(WP_REST_Response)
Source
File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php
public function get_items( $request ) { $args = array( 'profile_group_id' => $request['profile_group_id'], 'user_id' => $request['user_id'], 'member_type' => $request['member_type'], 'hide_empty_groups' => $request['hide_empty_groups'], 'hide_empty_fields' => $request['hide_empty_fields'], 'fetch_field_data' => $request['fetch_field_data'], 'fetch_visibility_level' => $request['fetch_visibility_level'], 'exclude_groups' => $request['exclude_groups'], 'exclude_fields' => $request['exclude_fields'], 'update_meta_cache' => $request['update_meta_cache'], 'fetch_fields' => true, ); if ( empty( $request['member_type'] ) ) { $args['member_type'] = false; } /** * Filter the query arguments for the request. * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ $args = apply_filters( 'bp_rest_xprofile_fields_get_items_query_args', $args, $request ); // Actually, query it. $field_groups = bp_xprofile_get_groups( $args ); $retval = array(); foreach ( $field_groups as $group ) { 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. */ $retval[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $field, $request ) ); } } $response = rest_ensure_response( $retval ); /** * Fires after a list of field are fetched via the REST API. * * @param array $field_groups Fetched field groups. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_xprofile_fields_get_items', $field_groups, $response, $request ); return $response; }
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.