Skip to:
Content

BuddyPress.org

Changeset 8819


Ignore:
Timestamp:
08/13/2014 12:30:12 AM (12 years ago)
Author:
boonebgorges
Message:

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

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress/members/register.php

    r8686 r8819  
    105105                                        <?php endwhile; ?>
    106106
    107                                         <input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="<?php bp_the_profile_group_field_ids(); ?>" />
     107                                        <input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="<?php bp_the_profile_field_ids(); ?>" />
    108108
    109109                                        <?php endwhile; endif; endif; ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php

    r8688 r8819  
    6464        </div>
    6565
    66         <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_group_field_ids(); ?>" />
     66        <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_field_ids(); ?>" />
    6767
    6868        <?php wp_nonce_field( 'bp_xprofile_edit' ); ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/settings/profile.php

    r8214 r8819  
    4747        <?php wp_nonce_field( 'bp_xprofile_settings' ); ?>
    4848
    49         <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_group_field_ids(); ?>" />
     49        <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_field_ids(); ?>" />
    5050
    5151</form>
  • trunk/src/bp-xprofile/bp-xprofile-actions.php

    r8678 r8819  
    8686                $posted_field_ids = explode( ',', $_POST['field_ids'] );
    8787
     88                // Backward compatibility: a bug in BP 2.0 caused only a single
     89                // group's field IDs to be submitted. Look for values submitted
     90                // in the POST request that may not appear in 'field_ids', and
     91                // add them to the list of IDs to save.
     92                foreach ( $_POST as $posted_key => $posted_value ) {
     93                        preg_match( '/^field_([0-9]+)_visibility$/', $posted_key, $matches );
     94                        if ( ! empty( $matches[1] ) && ! in_array( $matches[1], $posted_field_ids ) ) {
     95                                $posted_field_ids[] = $matches[1];
     96                        }
     97                }
     98
    8899                // Save the visibility settings
    89100                foreach ( $posted_field_ids as $field_id ) {
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r8785 r8819  
    313313
    314314                return substr( $field_ids, 0, -1 );
     315        }
     316
     317/**
     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();
     324}
     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;
     334
     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                }
     339
     340                $field_ids = implode( ',', wp_parse_id_list( $field_ids ) );
     341
     342                return apply_filters( 'bp_get_tthe_profile_field_ids', $field_ids );
    315343        }
    316344
Note: See TracChangeset for help on using the changeset viewer.