Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xprofile_data function doesn't preserve the order of fields/groups when converted to json #375

Closed
modemlooper opened this issue Jan 13, 2021 · 0 comments · Fixed by #380
Closed

Comments

@modemlooper
Copy link
Contributor

modemlooper commented Jan 13, 2021

When fetching the member endpoint the profile data is not In the same order as the admin UI because the keys are all integers and JSON orders integer keys sequentially. xprofile_data function is using the field id as the key but it should be the field_order / group_order as the key to keep the data in order.

    protected function xprofile_data( $user_id ) {
		$data = array();

		// Get XProfile groups, only if the component is active.
		if ( bp_is_active( 'xprofile' ) ) {
			$fields_endpoint = new BP_REST_XProfile_Fields_Endpoint();

			$groups = bp_xprofile_get_groups(
				array(
					'user_id'          => $user_id,
					'fetch_fields'     => true,
					'fetch_field_data' => true,
				)
			);

			foreach ( $groups as $group ) {
				$data['groups'][ $group->id ] = array(
					'id'   => $group->id,
					'name' => $group->name,
				);

				foreach ( $group->fields as $item ) {
					$data['groups'][ $item->group_id ]['fields'][ $item->field_order ] = array(
						'id'    => $item->id,
						'name'  => $item->name,
						'value' => array(
							'raw'          => $item->data->value,
							'unserialized' => $fields_endpoint->get_profile_field_unserialized_value( $item->data->value ),
							'rendered'     => $fields_endpoint->get_profile_field_rendered_value( $item->data->value, $item ),
						),
					);
				}
			}
		} else {
			$data = array( __( 'No extended profile data available as the component is inactive', 'buddypress' ) );
		}

		return $data;
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants