Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/21/2021 02:17:21 PM (3 years ago)
Author:
imath
Message:

Field Types can now declare supported features & field visibility

  • Edit the JavaScript file used by the xProfile Create field Administration screen to handle Field types requirements by showing/hiding screen metaboxes according to feature supports and to get ride of some jQuery deprecated methods.
  • Improve the xProfile Field API to take in account xProfile Field Types declared feature supports by adding two new methods to get (BP_XProfile_Field->get_field_type_supports()) & check (BP_XProfile_Field->field_type_supports( $feature_name )) the field type supported features.
  • The xProfile Create field Administration Screen Metaboxes displayed to set the field properties can now be disabled by the Field Type using the static variable $supported_features. See tests/phpunit/assets/bptest-xprofile-field-type.php for an example of use.
  • Improve the xProfile Field API to take in account the xProfile Field Types visibility property to use as default field visibility. NB: setting this Field Type visibility and its allow_custom_visibility feature support to false, a Field Type can now enforce the visibility to use for a field.
  • Introduce a new xProfile Fields loop argument $hide_field_types to avoid displaying fields according to an array of Field types. To customize this new argument you can use the bp_before_has_profile_parse_args filter for existing xProfile loop. For instance you can avoid to list xProfile fields according to their type from the WP-Admin/Extended profile screen checking the corresponding Administration Screen ID.
  • Add PHP unit tests to verify these improvements are working the right way.

Props DJPaul, Offereins, needle, netweb, vapvarun

See #7162

File:
1 edited

Legend:

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

    r12725 r12868  
    238238     *
    239239     * @since 1.2.0
     240     * @since 2.4.0 Introduced `$member_type` argument.
     241     * @since 8.0.0 Introduced `$hide_field_types` argument.
    240242     *
    241243     * @global object $wpdb WordPress DB access object.
     
    257259     *      @type bool         $fetch_field_data  Whether to fetch data for each field. Requires a $user_id.
    258260     *                                            Default: false.
    259      *      @type array        $exclude_groups    Comma-separated list or array of group IDs to exclude.
    260      *      @type array        $exclude_fields    Comma-separated list or array of field IDs to exclude.
     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.
    261264     *      @type bool         $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields,
    262265     *                                            and data. Default: true.
     
    279282            'exclude_groups'         => false,
    280283            'exclude_fields'         => false,
     284            'hide_field_types'       => array(),
    281285            'update_meta_cache'      => true,
    282286        ) );
     
    339343        $fields = array();
    340344        foreach ( $field_ids as $field_id ) {
    341             $fields[] = xprofile_get_field( $field_id, null, false );
     345            $_field = xprofile_get_field( $field_id, null, false );
     346
     347            if ( in_array( $_field->type, $r['hide_field_types'], true ) ) {
     348                continue;
     349            }
     350
     351            $fields[] = $_field;
    342352        }
    343353
     
    347357        // Maybe fetch field data.
    348358        if ( ! empty( $r['fetch_field_data'] ) ) {
     359            $field_type_objects = wp_list_pluck( $fields, 'type_obj', 'id' );
    349360
    350361            // Get field data for user ID.
    351362            if ( ! empty( $field_ids ) && ! empty( $r['user_id'] ) ) {
    352                 $field_data = BP_XProfile_ProfileData::get_data_for_user( $r['user_id'], $field_ids );
     363                $field_data = BP_XProfile_ProfileData::get_data_for_user( $r['user_id'], $field_ids, $field_type_objects );
    353364            }
    354365
Note: See TracChangeset for help on using the changeset viewer.