BP_REST_XProfile_Fields_Endpoint::get_repeater_fields_data( BP_XProfile_Field $field, WP_REST_Request $request )
Get Repeater field data.
Description
Parameters
- $field
-
(Required) Field Object.
- $request
-
(Required) Full data about the request.
Return
(array|void)
Source
File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php
public function get_repeater_fields_data( $field, $request ) { global $bp, $wpdb; if ( empty( $field ) || ! bp_loggedin_user_id() ) { return; } $field_id = $field->id; // phpcs:ignore $sql = "select m1.object_id FROM {$bp->profile->table_name_meta} as m1 WHERE m1.meta_key = '_cloned_from' AND m1.meta_value = %d"; // phpcs:ignore $sql = $wpdb->prepare( $sql, $field_id ); // phpcs:ignore $results = $wpdb->get_col( $sql ); $user_id = ( ! empty( $request['user_id'] ) ? $request['user_id'] : bp_loggedin_user_id() ); $data = array(); $user_fields = bp_get_profile_field_set_count( $field->group_id, $user_id ); if ( ! empty( $results ) && ! is_wp_error( $results ) ) { $count = 1; foreach ( $results as $k => $sub_field_id ) { if ( $count > $user_fields ) { break; } $data[ $k ]['id'] = $sub_field_id; if ( ! empty( $request['fetch_field_data'] ) ) { $data[ $k ]['value'] = array( 'raw' => xprofile_get_field_data( $sub_field_id, $user_id ), 'unserialized' => $this->get_profile_field_unserialized_value( xprofile_get_field_data( $sub_field_id, $user_id ) ), 'rendered' => $this->get_profile_field_rendered_value( xprofile_get_field_data( $sub_field_id, $user_id ), $field_id ), ); } if ( ! empty( $request['fetch_visibility_level'] ) ) { $data[ $k ]['visibility_level'] = xprofile_get_field_visibility_level( $sub_field_id, $user_id ); $data[ $k ]['allow_custom_visibility'] = bp_xprofile_get_meta( $sub_field_id, 'field', 'allow_custom_visibility' ); } $count ++; } } return $data; }
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.