Hide a group of Profile Fields
-
Hi,
I have buddypress installed and I’m using for a company Intranet.
To create additional fields that I need, I have installed Buddypress Xprofile Custom Fields Type and it works rather well.
The problem is, I want to store additional info about each person that they can’t edit or see.
I have figured out how to hide a group of fields when viewing the user’s profile by adding in some code to exclude the group, in this instance the group ID 4:
<?php /** * BuddyPress - Members Profile Loop * * @package BuddyPress * @subpackage bp-legacy */ /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_before_profile_loop_content' ); ?> <?php if ( bp_has_profile() ) : ?> <?php while ( bp_profile_groups() ) : bp_the_profile_group(); if ( bp_get_the_profile_group_id() != '4' ) :?> <?php if ( bp_profile_group_has_fields() ) : ?> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_before_profile_field_content' ); ?> <div class="bp-widget <?php bp_the_profile_group_slug(); ?>"> <h2><?php bp_the_profile_group_name(); ?></h2> <table class="profile-fields"> <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> <?php if ( 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; ?> <?php /** * Fires after the display of a field table row for profile data. * * @since 1.1.0 */ do_action( 'bp_profile_field_item' ); ?> <?php endwhile; ?> </table> </div> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_after_profile_field_content' ); ?> <?php endif; ?> <?php endif; endwhile; ?> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_profile_field_buttons' ); ?> <?php endif; ?> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_after_profile_loop_content' ); ?>
What I can’t seem to figure out is how to hide the group of fields in Edit mode. So basically, at the minute when a user goes to edit the profile fields, group 4 will display.
I believe it’s the edit file I need to edit but I’m not a coder. I learnt vb, php etc a decade ago so i get the drift but I’m playing around here and can’t quite get it work with the lack of knowledge I have.
I have tried doing what I’ve done about but just get an error. Any ideas please?
<?php /** * BuddyPress - Members Single Profile Edit * * @package BuddyPress * @subpackage bp-legacy */ /** * Fires after the display of member profile edit content. * * @since 1.1.0 */ do_action( 'bp_before_profile_edit_content' ); if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?> <form action="<?php bp_the_profile_group_edit_form_action(); ?>" method="post" id="profile-edit-form" class="standard-form <?php bp_the_profile_group_slug(); ?>"> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_before_profile_field_content' ); ?> <h2><?php printf( __( "Editing '%s' Profile Group", 'buddypress' ), bp_get_the_profile_group_name() ); ?></h2> <?php if ( bp_profile_has_multiple_groups() ) : ?> <ul class="button-nav" aria-label="<?php esc_attr_e( 'Profile field groups', 'buddypress' ); ?>" role="navigation"> <?php bp_profile_group_tabs(); ?> </ul> <?php endif ;?> <div class="clear"></div> <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> <div<?php bp_field_css_class( 'editfield' ); ?>> <?php $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); $field_type->edit_field_html(); /** * Fires before the display of visibility options for the field. * * @since 1.7.0 */ do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); ?> <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> <?php printf( __( 'This field can be seen by: %s', 'buddypress' ), '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' ); ?> <a href="#" class="visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a> </p> <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> <fieldset> <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> <?php bp_profile_visibility_radio_buttons() ?> </fieldset> <a class="field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ) ?></a> </div> <?php else : ?> <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> <?php printf( __( 'This field can be seen by: %s', 'buddypress' ), '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' ); ?> </div> <?php endif ?> <?php /** * Fires after the visibility options for a field. * * @since 1.1.0 */ do_action( 'bp_custom_profile_edit_fields' ); ?> <p class="description"><?php bp_the_profile_field_description(); ?></p> </div> <?php endwhile; ?> <?php /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/profile/profile-wp.php */ do_action( 'bp_after_profile_field_content' ); ?> <div class="submit"> <input type="submit" name="profile-group-edit-submit" id="profile-group-edit-submit" value="<?php esc_attr_e( 'Save Changes', 'buddypress' ); ?> " /> </div> <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_field_ids(); ?>" /> <?php wp_nonce_field( 'bp_xprofile_edit' ); ?> </form> <?php endwhile; endif; ?> <?php /** * Fires after the display of member profile edit content. * * @since 1.1.0 */ do_action( 'bp_after_profile_edit_content' ); ?>
Thank you
- You must be logged in to reply to this topic.