Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/16/2021 05:29:26 AM (3 years ago)
Author:
imath
Message:

Improve the Field/Group APIs to pick selected fields as signup ones

  • Introduce the bp_xprofile_get_signup_field_ids() function to get an ordered list of field IDs to use as signup fields.
  • Introduce the bp_xprofile_signup_args() function to get the signup arguments to use into the registration page xProfile loop. If no signup fields are available, it falls back to the primary fields group.
  • Introduce the $signup_fields_only xProfile loop argument to restrict fetched fields to signup ones if set to true.
  • Adapt the BP_XProfile_Data_Template class to build a unique xProfile field group out of any possible field groups containing one or more signup fields when the $signup_fields_only argument is set to true and registration is allowed on the site.
  • Adapt the BP_XProfile_Field class to get the possible field's signup position and add a new metabox to add a field to signup ones from the xProfile Field Administration screen.
  • Adapt the BP_XProfile_Group class to ignore non signup fields if the $signup_fields_only argument is set to true.

Props johnjamesjacoby, boonebgorges, DJPaul, Offereins

See #6347

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php

    r12868 r12885  
    106106     * @since 1.5.0
    107107     * @since 2.4.0 Introduced `$member_type` argument.
    108      * @since 8.0.0 Introduced `$hide_field_types` argument.
     108     * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
    109109     *
    110110     * @param array|string $args {
     
    121121     *     @type int|bool     $hide_empty_fields       Should empty fields be skipped.
    122122     *     @type int|bool     $fetch_visibility_level  Fetch visibility levels.
     123     *     @type string[]     $hide_field_types        List of field types to hide form loop. Default: empty array.
     124     *     @type bool         $signup_fields_only      Whether to only return signup fields. Default: false.
    123125     *     @type int|bool     $update_meta_cache       Should metadata cache be updated.
    124      *     @type string[]     $hide_field_types        List of field types to hide form loop. Default: empty array.
    125126     * }
    126127     */
     
    160161            'exclude_fields'         => false,
    161162            'hide_field_types'       => array(),
     163            'signup_fields_only'     => false,
    162164            'update_meta_cache'      => true
    163165        ) );
    164166
    165         $this->groups      = bp_xprofile_get_groups( $r );
     167        $groups = bp_xprofile_get_groups( $r );
     168
     169        if ( true === $r['signup_fields_only'] && bp_get_signup_allowed() ) {
     170            $signup_fields_order       = bp_xprofile_get_signup_field_ids();
     171            $signup_group              = new BP_XProfile_Group();
     172            $signup_group->id          = 0;
     173            $signup_group->name        = __( 'Signup Fields', 'buddypress' );
     174            $signup_group->description = '';
     175            $signup_group->can_delete  = 0;
     176            $signup_group->group_order = 0;
     177            $fields                    = array();
     178            $signup_group->fields      = array();
     179
     180            // Get all group fields.
     181            foreach ( $groups as $group ) {
     182                if ( ! $group->fields ) {
     183                    continue;
     184                }
     185
     186                // Populate fields using the field ID as key.
     187                foreach ( $group->fields as $signup_field ) {
     188                    $fields[ $signup_field->id ] = $signup_field;
     189                }
     190            }
     191
     192            if ( $fields ) {
     193                // Reorder signup fields.
     194                foreach ( $signup_fields_order as $ordered_signup_field_id ) {
     195                    if ( ! isset( $fields[ $ordered_signup_field_id ] ) ) {
     196                        continue;
     197                    }
     198
     199                    $signup_group->fields[] = $fields[ $ordered_signup_field_id ];
     200                }
     201            }
     202
     203            // Override groups with the signup one.
     204            $groups = array( $signup_group );
     205        }
     206
     207        $this->groups      = $groups;
    166208        $this->group_count = count( $this->groups );
    167209        $this->user_id     = $r['user_id'];
Note: See TracChangeset for help on using the changeset viewer.