Skip to:
Content

BuddyPress.org

Opened 11 months ago

Closed 2 months ago

Last modified 2 months ago

#8976 closed enhancement (fixed)

Registration through REST API with additional profile fields

Reported by: niftythree's profile niftythree Owned by: espellcaste's profile espellcaste
Milestone: 14.0.0 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch has-unit-tests
Cc:

Description

Hi,

At the moment, when using the BuddyPress REST API to signup a member, only basic information is required. Would it be possible for it to mirror the BuddyPress Register page process (i.e. fill in all required fields and then the member can continue to the activate process)?

Being able to use the "Use this field in the site registration form." option in profile fields is great. Currently, if we were to implement registration via an app which uses the API and enforce compulsory fields, it would first have to do the account sign up, wait for the account to be activated, and then have a separate process where the user can enter the required fields. While this process could work theoretically, it contains a lot of steps, and leaves it open to scenarios where a person can create an account, activate the account, and not complete the rest of the process, leaving empty profiles. Website users would see incomplete profiles and this would not be fair on those that chose to use the website, and were forced to fill in the required signup fields during registration.

Is there a way this is already possible? Please let us know, if so.

Thank you.

Change History (18)

#1 @imath
11 months ago

  • Milestone changed from Awaiting Review to Up Next

Thanks for your feedback @niftythree I agree, we'll work on it from there: https://github.com/buddypress/BP-REST/issues/489

#2 @niftythree
11 months ago

Thanks @imath 🙂

#3 @imath
7 months ago

  • Milestone changed from Up Next to 14.0.0

#4 @espellcaste
6 months ago

  • Owner set to espellcaste
  • Status changed from new to assigned

I plan to work on this feature.

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.


3 months ago

#6 @espellcaste
3 months ago

  • Keywords has-patch has-unit-tests added

I have a pr with this implementation together with tests: https://github.com/buddypress/BP-REST/pull/502

  • We are making sure Signup fields can be returned when listing XProfile Groups or Fields.
  • And making sure the signup endpoint can send XProfile field data.

@niftythree If you could test the implementation, it'd be great.

#7 @espellcaste
3 months ago

In 13797:

While pulling XProfile group fields objects from cache with the BP_XProfile_Group::get method,
avoid unnecessary queries for the cached bp_xprofile_get_signup_field_ids() function.

See #8976

#8 @niftythree
3 months ago

Hi @espellcaste,

We've had a look, and think it's working really well. 🙂

#9 @niftythree
3 months ago

Hi @espellcaste,

We've since noticed two things, and we thought this might be the best place to add them.

  • The order of individual profile fields is not preserved when an account is pending, when submitted through the REST API; i.e. the order of profile fields is different for an active account when compared to a pending account (when submitted through the website, they match).
  • The output display order of "Custom" ordered field options (e.g. the different checkboxes within one profile field) when submitted through the REST API isn't preserved. Options are displayed in the order they are sent.

Thanks. 🙂

#10 @espellcaste
3 months ago

@niftythree I would need more information here since I can't replicate this issue via the API.

The order of individual profile fields is not preserved when an account is pending, when submitted through the REST API; i.e. the order of profile fields is different for an active account when compared to a pending account

This part is not clear to me. A pending account is still a signup. And the data of the signup is returned like so. So there is no profile fields for pending accounts.

[
  {
    "count_sent": 0,
    "date_sent": "2024-04-20T04:20:25",
    "date_sent_gmt": "2024-04-20T04:20:25",
    "id": 12,
    "meta": {
      "count_sent": 0,
      "field_1": "User Test 07",
      "field_19": [
        "Option 01",
        "Option 03"
      ],
      "field_19_visibility": "public",
      "profile_field_ids": "19",
      "sent_date": "0000-00-00 00:00:00"
    },
    "registered": "2024-04-20T04:20:25",
    "registered_gmt": "2024-04-20T04:20:25",
    "user_email": "user_07@gmail.com",
    "user_login": "user07",
    "user_name": "User Test 07"
  }
]

The output display order of "Custom" ordered field options (e.g. the different checkboxes within one profile field) when submitted through the REST API isn't preserved. Options are displayed in the order they are sent.

This is another report I can't replicate. Here is the output I see for getting profile fields for a particular user. The order is set to "Custom". And the field is a checkboxes field.

When I compare this with the web version, they match.

https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/

[
  {
    "_links": {
      "collection": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/"
        }
      ],
      "group": [
        {
          "embeddable": true,
          "href": "https://bar.wp.test/wp-json/buddypress/v1//xprofile/groups/1"
        }
      ],
      "self": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/1"
        }
      ]
    },
    "can_delete": false,
    "data": {
      "id": 9,
      "value": {
        "raw": "User 14",
        "rendered": "<p>User 14</p>\n",
        "unserialized": [
          "User 14"
        ]
      }
    },
    "description": {
      "rendered": ""
    },
    "field_order": 0,
    "group_id": 1,
    "id": 1,
    "is_default_option": false,
    "is_required": true,
    "name": "Name",
    "option_order": 0,
    "options": [],
    "order_by": "",
    "parent_id": 0,
    "type": "textbox"
  },
  {
    "_links": {
      "collection": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/"
        }
      ],
      "group": [
        {
          "embeddable": true,
          "href": "https://bar.wp.test/wp-json/buddypress/v1//xprofile/groups/1"
        }
      ],
      "self": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/2"
        }
      ]
    },
    "can_delete": true,
    "data": {
      "id": 0,
      "value": {
        "raw": "",
        "rendered": "",
        "unserialized": []
      }
    },
    "description": {
      "rendered": ""
    },
    "field_order": 1,
    "group_id": 1,
    "id": 2,
    "is_default_option": false,
    "is_required": false,
    "name": "Text Box Test Field - #9127",
    "option_order": 0,
    "options": [],
    "order_by": "",
    "parent_id": 0,
    "type": "textbox"
  },
  {
    "_links": {
      "collection": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/"
        }
      ],
      "group": [
        {
          "embeddable": true,
          "href": "https://bar.wp.test/wp-json/buddypress/v1//xprofile/groups/1"
        }
      ],
      "self": [
        {
          "href": "https://bar.wp.test/wp-json/buddypress/v1/xprofile/fields/19"
        }
      ]
    },
    "can_delete": true,
    "data": {
      "id": 10,
      "value": {
        "raw": "a:2:{i:0;s:9:\"Option 01\";i:1;s:9:\"Option 03\";}",
        "rendered": "<p>Option 01, Option 03</p>\n",
        "unserialized": [
          "Option 01",
          "Option 03"
        ]
      }
    },
    "description": {
      "rendered": "testing description"
    },
    "field_order": 2,
    "group_id": 1,
    "id": 19,
    "is_default_option": false,
    "is_required": true,
    "name": "Checkbox",
    "option_order": 0,
    "options": [
      {
        "can_delete": true,
        "description": {
          "rendered": ""
        },
        "field_order": 0,
        "group_id": 1,
        "id": 26,
        "is_default_option": false,
        "is_required": false,
        "name": "Option 01",
        "option_order": 1,
        "order_by": "",
        "parent_id": 19,
        "type": "option"
      },
      {
        "can_delete": true,
        "description": {
          "rendered": ""
        },
        "field_order": 0,
        "group_id": 1,
        "id": 27,
        "is_default_option": false,
        "is_required": false,
        "name": "Option 02",
        "option_order": 2,
        "order_by": "",
        "parent_id": 19,
        "type": "option"
      },
      {
        "can_delete": true,
        "description": {
          "rendered": ""
        },
        "field_order": 0,
        "group_id": 1,
        "id": 28,
        "is_default_option": false,
        "is_required": false,
        "name": "Option 03",
        "option_order": 3,
        "order_by": "",
        "parent_id": 19,
        "type": "option"
      }
    ],
    "order_by": "CUSTOM",
    "parent_id": 0,
    "type": "checkbox"
  }
]
Last edited 3 months ago by espellcaste (previous) (diff)

#11 @niftythree
3 months ago

Hi @espellcaste,

Thanks for your reply. Can you try the following:

  1. Create additional fields through WordPress Dashboard > Users > Profile Fields > Add New Field > Add "Travelling" as the Name and set Type to "Checkboxes".
    1. Set your checkbox options to > Check "Use this field in the site registration form." > Save:
      • I never travel
      • Always
      • Sometimes
    2. Create another profile field > Add "Info about me" as the Name and set Type to Text Box > Check "Use this field in the site registration form." > Save
    3. Create another profile field > Add "Language" as the Name and set Type to Multi Select Box > Check "Use this field in the site registration form."
      1. Set your Multi Select Box options and Save:
      • Arabic
      • English
      • Dutch
    4. Rearrange the fields in the WordPress Dashboard > Users > Profile Fields area. Position "Language" at the top, "Travelling" second and "Info about me" at the bottom.
      1. Rearrange the fields in the "Signup Fields" group the same way. "Language" at the top, "Travelling" second and "Info about me" at the bottom.
  1. Register an account through the REST API with profile fields as ordered below (i.e. different to the ordering within the Signup Fields group):
    1. Send back "Travelling" profile field options in the order of:
      • "Sometimes, I never travel"
    2. "Info about me" profile field sent back as:
      • "This is some text for my profile."
    3. Send back "Language" profile field options in the order of:
      • "Arabic, English"
  1. Check WordPress Dashboard > Users > Manage Signups > Click on newly registered pending account
    1. The order of the profile fields are different
    2. Checkbox and multi select box selections are arranged in the order they were sent, and not in the sort order set for the profile field. NB: we now know that this happens regardless of the sort order type that's chosen, and not just for Custom.
      1. Once the account is activated, the profile field order displays correctly on the website, but the field options do not display in the sort order. The REST API also responds in the same way (for example, in /members and /members/me).


Further information:

  • The above occurs when using a Checkbox or Multi Select Box.
  • The more profile fields and options within them you have, the easier it is to notice.
  • Existing activated users: Updating profile field options for a checkbox/multi select box through the REST API will also save/display in the order they were sent, and not in the sort order set for the profile field.
  • When the website is used, it conforms to all sort orders, including "Custom", when registering and editing a profile.

Thanks.

#12 @espellcaste
3 months ago

That's great! Let me try to replicate this. :D

#13 @espellcaste
3 months ago

@niftythree I updated the branch with your latest suggestions.

There is a pending question if we should sort the field values. See here. But the field options are sorted properly now.

https://github.com/buddypress/BP-REST/pull/502

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.


2 months ago

#16 @espellcaste
2 months ago

We agreed in the last dev chat that the field option *values* should respect the sort options for multiselect fields.

#17 @espellcaste
2 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

@niftythree This was resolved: https://github.com/buddypress/BP-REST/issues/489

I'll work on the sorting of the values at #9147, since it is more complex and involves changes inside BP core too.

Note: See TracTickets for help on using tickets.