Don’t hide fields when user views his own profile
-
When a user is viewing their own profile, I would like to show them all fields, regardless of whether they have values or not. I don’t want to force them to enter values, but I do want to make it obvious which fields are empty.
So I understand that hiding fields is done in this file: bp-xprofile-template.php. Can someone tell me how to modify it so no fields are hidden when users are viewing their own profiles? I realize it’s poor practice to modify plugin files so am also open to other suggestions on how to accomplish this.
-
The easiest way is to create a template overload of this file:
buddypress\bp-templates\bp-legacy\buddypress\members\single\profile\profile-loop.php
Then, in the overload, remove this conditional:
if ( bp_field_has_data() )
More precisely – replace it with:
<?php if ( bp_is_my_profile() ) : ?> <tr<?php bp_field_css_class(); ?>> <td class="label"><?php bp_the_profile_field_name(); ?></td> <td class="data"><?php bp_the_profile_field_value(); ?></td> </tr> <?php elseif ( bp_field_has_data() ) : ?> <tr<?php bp_field_css_class(); ?>> <td class="label"><?php bp_the_profile_field_name(); ?></td> <td class="data"><?php bp_the_profile_field_value(); ?></td> </tr> <?php endif; ?>
Thanks for the quick response, but doesn’t seem to be working for me. I created the template overload of profile-loop.php and stored it in wp-content/themes/buddyboss-child/buddypress/bp-templates/bp-legacy/buddypress/members/single/profile. I’ve pasted the entire file below after modification.
I can’t find it now, but there was a thread somewhere that indicated that the following line needed to be changed in bp-xprofile-template.php so was wondering what you thought of that.
$hide_empty_fields_default = ( ! is_network_admin() && ! is_admin() && ! bp_is_user_profile_edit() && ! bp_is_register_page() );Anyway, here’s my profile-loop.php:
`Okay – discovered that the overload file needs to be in wp-content/themes/buddyboss-child/buddypress/members/single/profile and verified it by making a random change to the file, but I’m still not seeing fields without values.
PS For some reason, the system won’t allow me to paste the code.
You can change parameters by passing an array in your overload.
Example – you may need to change the passed values.
<?php $args = array( 'hide_empty_groups' => false, 'hide_empty_fields' => false ); if ( bp_has_profile( $args ) ) : ?>
- You must be logged in to reply to this topic.