Opened 9 years ago
Closed 8 years ago
#6667 closed enhancement (fixed)
Please add filter to bp_field_has_data
Reported by: | nightbook | Owned by: | tw2113 |
---|---|---|---|
Milestone: | 2.8 | Priority: | normal |
Severity: | normal | Version: | 2.3.3 |
Component: | Extended Profile | Keywords: | |
Cc: |
Description
Hello,
I would like a filter applied to the bp_field_has_data function to allow overriding the boolean return, this would allow me to more easily tie in a plugin I'm working on to provide global fields across all profiles that is editable only by the admin.
Existing bp_field_has_data Function below simply returns the field_has_data property of the $profile_template global.
function bp_field_has_data() { global $profile_template; return $profile_template->field_has_data; }
*Found on Line 438 in bp-xprofile/bp-xprofile-template.php :
https://github.com/buddypress/BuddyPress/blob/0b97ae6bb5bf027d2e2573b9b6ab99058a0e6eca/src/bp-xprofile/bp-xprofile-template.php#L438
It's currently only utilized in the profile-loop for conditionally including the fields if they have information.
<?php if ( bp_field_has_data() ) : ?>
By introducing a filter I'll be able to display Fields which have no user inputted information and rather pull a global value from some custom xprofile_meta I've associated with the field.
Plugin URL - https://github.com/nightbook/buddypress-admin-global-profile-fields
Proposed Code Change for the bp_field_has_data function;
function bp_field_has_data() { global $profile_template; /** * Filters the profile field value. * * @since 1.0.0 * * @param boolean $field_has_data Toggle to indicate field should be displayed. * @param global $profile_template The profile template. * @param object $field The profile field. * @param int $field_id The id of the profile field. */ return apply_filters( 'bp_profile_field_has_data', $profile_template->field_has_data, $profile_template, $profile_template->field, $profile_template->field->id ); }
*May only need to pass $field_has_data and $profile_template as it gives access to others.
With this filter available along with the bp_get_the_profile_field_value filter that already exists I'd be able to easily complete implementation. Sample of how I would use the proposed filter.
add_filter( 'bp_profile_field_has_data', array($this, 'display_global_fields'), 10, 4); function display_global_fields( $field_has_data, $profile_template, $field, $field_id ) { if ( $field->visibility_level == 'global' ) { $global_field_value = bp_xprofile_get_meta( $field->id, 'field', 'global_value' ); if ( ! empty( $global_field_value ) || ( '0' === $global_field_value ) ) { return true; } } return $field_has_data; }
Other uses would be disabling fields with specific values such as a Not Applicable option/value in a dropdown type. Or showing empty fields and replacing with Information not Provided text.
Much appreciated,
Cheers
Attachments (1)
Change History (11)
This ticket was mentioned in Slack in #buddypress by mrmaz. View the logs.
9 years ago
#4
@
9 years ago
- Keywords needs-patch added; 2nd-opinion removed
- Milestone changed from Under Consideration to Future Release
#5
@
8 years ago
- Keywords has-patch added; needs-patch removed
This patch provides a good start and covers filters for bp_field_has_data
and bp_field_has_public_data
. If we want to include more, we can, but this covers the initial request.
#6
@
8 years ago
- Milestone changed from Future Release to 2.8
Please move tickets out of Future Release if you write patches for them, they get missed if the email notification comes in from a regular/known contributor.
#7
@
8 years ago
- Owner set to tw2113
- Resolution set to fixed
- Status changed from new to closed
In 11238:
#8
@
8 years ago
- Keywords has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
I noticed a) the filters are documented for 2.7, which should be 2.8, and b) the filters provide additional params that are already available in the template global data, which isn't common with other filters.
Sounds reasonable to me, though we'd probably also want to make sure similar template loop functions in the other components have a filter in the same place.