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-group.php

    r12868 r12885  
    239239     * @since 1.2.0
    240240     * @since 2.4.0 Introduced `$member_type` argument.
    241      * @since 8.0.0 Introduced `$hide_field_types` argument.
     241     * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments.
    242242     *
    243243     * @global object $wpdb WordPress DB access object.
     
    245245     * @param array $args {
    246246     *  Array of optional arguments:
    247      *      @type int          $profile_group_id  Limit results to a single profile group.
    248      *      @type int          $user_id           Required if you want to load a specific user's data.
    249      *                                            Default: displayed user's ID.
    250      *      @type array|string $member_type       Limit fields by those restricted to a given member type, or array of
    251      *                                            member types. If `$user_id` is provided, the value of `$member_type`
    252      *                                            will be overridden by the member types of the provided user. The
    253      *                                            special value of 'any' will return only those fields that are
    254      *                                            unrestricted by member type - i.e., those applicable to any type.
    255      *      @type bool         $hide_empty_groups True to hide groups that don't have any fields. Default: false.
    256      *      @type bool         $hide_empty_fields True to hide fields where the user has not provided data.
    257      *                                            Default: false.
    258      *      @type bool         $fetch_fields      Whether to fetch each group's fields. Default: false.
    259      *      @type bool         $fetch_field_data  Whether to fetch data for each field. Requires a $user_id.
    260      *                                            Default: false.
    261      *      @type int[]|bool   $exclude_groups    Comma-separated list or array of group IDs to exclude.
    262      *      @type int[]|bool   $exclude_fields    Comma-separated list or array of field IDs to exclude.
    263      *      @type string[]     $hide_field_types  List of field types to hide form loop. Default: empty array.
    264      *      @type bool         $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
    265      *                                            and data. Default: true.
     247     *      @type int          $profile_group_id   Limit results to a single profile group.
     248     *      @type int          $user_id            Required if you want to load a specific user's data.
     249     *                                             Default: displayed user's ID.
     250     *      @type array|string $member_type        Limit fields by those restricted to a given member type, or array of
     251     *                                             member types. If `$user_id` is provided, the value of `$member_type`
     252     *                                             will be overridden by the member types of the provided user. The
     253     *                                             special value of 'any' will return only those fields that are
     254     *                                             unrestricted by member type - i.e., those applicable to any type.
     255     *      @type bool         $hide_empty_groups  True to hide groups that don't have any fields. Default: false.
     256     *      @type bool         $hide_empty_fields  True to hide fields where the user has not provided data.
     257     *                                             Default: false.
     258     *      @type bool         $fetch_fields       Whether to fetch each group's fields. Default: false.
     259     *      @type bool         $fetch_field_data   Whether to fetch data for each field. Requires a $user_id.
     260     *                                             Default: false.
     261     *      @type int[]|bool   $exclude_groups     Comma-separated list or array of group IDs to exclude.
     262     *      @type int[]|bool   $exclude_fields     Comma-separated list or array of field IDs to exclude.
     263     *      @type string[]     $hide_field_types   List of field types to hide form loop. Default: empty array.
     264     *      @type bool         $signup_fields_only Whether to only return signup fields. Default: false.
     265     *      @type bool         $update_meta_cache  Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
     266     *                                             and data. Default: true.
    266267     * }
    267268     * @return array $groups
     
    284285            'hide_field_types'       => array(),
    285286            'update_meta_cache'      => true,
     287            'signup_fields_only'     => false,
    286288        ) );
    287289
     
    343345        $fields = array();
    344346        foreach ( $field_ids as $field_id ) {
     347            if ( true === $r['signup_fields_only'] && ! in_array( $field_id, bp_xprofile_get_signup_field_ids(), true ) ) {
     348                continue;
     349            }
     350
    345351            $_field = xprofile_get_field( $field_id, null, false );
    346352
Note: See TracChangeset for help on using the changeset viewer.