Skip to:

08/13/2014 12:30:12 AM (10 years ago)

Introduce bp_the_profile_field_ids(), and use as appropriate throughout BP

The POST routine run when editing one's xprofile-powered profile (or
registering for an account when the registration form includes xprofile fields)
works in part by sending a list of field IDs in the 'field_ids' <input> element.
These field IDs are then used to decide which POST keys to look for when saving
submitted profile values. Historically, the function powering this field_ids
element has been bp_the_profile_group_field_ids(), which pulls up only the
field IDs from a single field group. Normally this works fine, because the
typical Profile > Edit screen only allows for the editing of a single field
group at a time. However, the introduction in BP 2.0 of Settings > Profile
demonstrates that this technique breaks when attempting to save more than one
field group at a time.

The new bp_the_profile_field_ids() replaces this logic by pulling up all the
field_ids from all the groups in the $profile_template global object.

In order to provide for backward compatibility with themes that may have
overridden the modified templates (in particular, members/single/settings/profile.php),
we add logic to the Settings > Profile save routine that looks for any
submitted profile fields that are not present in the field_ids array.

Fixes #5666

Props boonebgorges, r-a-y

1 edited


  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r8785 r8819  
    314314        return substr( $field_ids, 0, -1 );
     315    }
     318 * Output a comma-separated list of field IDs that are to be submitted on profile edit.
     319 *
     320 * @since BuddyPress (2.1.0)
     321 */
     322function bp_the_profile_field_ids() {
     323    echo bp_get_the_profile_field_ids();
     325    /**
     326     * Generate a comma-separated list of field IDs that are to be submitted on profile edit.
     327     *
     328     * @since BuddyPress (2.1.0)
     329     *
     330     * @return string
     331     */
     332    function bp_get_the_profile_field_ids() {
     333        global $profile_template;
     335        $field_ids = array();
     336        foreach ( $profile_template->groups as $group ) {
     337            $field_ids = array_merge( $field_ids, wp_list_pluck( $group->fields, 'id' ) );
     338        }
     340        $field_ids = implode( ',', wp_parse_id_list( $field_ids ) );
     342        return apply_filters( 'bp_get_tthe_profile_field_ids', $field_ids );
    315343    }
Note: See TracChangeset for help on using the changeset viewer.