[buddypress-trac] [BuddyPress Trac] #6667: Please add filter to bp_field_has_data

buddypress-trac noreply at wordpress.org
Fri Oct 16 06:40:59 UTC 2015

#6667: Please add filter to bp_field_has_data
 Reporter:  nightbook             |      Owner:
     Type:  enhancement           |     Status:  new
 Priority:  normal                |  Milestone:  Awaiting Review
Component:  Component - XProfile  |    Version:  2.3.3
 Severity:  normal                |   Keywords:

 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 :

 It's currently only utilized in the profile-loop for conditionally
 including the fields if they have information.
 <?php if ( bp_field_has_data() ) : ?>
 Link to code -

 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-

 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,

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6667>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac

More information about the buddypress-trac mailing list