2

I know there is a method in BuddyPress which can help to hide some profile fields:

function bp_has_profile( $args = '' ) {
    global $profile_template;

    // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page,
    // or this is a registration page
    $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() );

    // We only need to fetch visibility levels when viewing your own profile
    if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) {
        $fetch_visibility_level_default = true;
    } else {
        $fetch_visibility_level_default = false;
    }

    $defaults = array(
        'user_id'             => bp_displayed_user_id(),
        'profile_group_id'    => false,
        'hide_empty_groups'   => true,
        'hide_empty_fields'   => $hide_empty_fields_default,
        'fetch_fields'        => true,
        'fetch_field_data'    => true,
        'fetch_visibility_level' => $fetch_visibility_level_default,
        'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
        'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level );
    return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
}

I am not sure how to call this method and pass 'exclude_fields' => $IDs_to_hide

4 Answers 4

0

Yes, It is possible to hide some fields from the profile page.

First go to the edit.php in your theme folder.Here if you want to hide the text box and name is "Full Name".

<?php if ( 'textbox' == bp_get_the_profile_field_type() ) : ?>
    <?php if ( 'Full Name' != bp_the_profile_field_name() ) : ?>
         <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
         <input type="text" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" value="<?php bp_the_profile_field_edit_value(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
      <?php endif; ?>
<?php endif; ?>

The above code is same as in profile.php file but I will put only the new if condition same as put the condition in other Radiobutton and Selectbox etc.

Your Full Name profile field are not displayed in your profile.

0

Not sure if there is a way to do this with your theme functions, but you can easily hide it in the edit loop. Copy /buddypress/members/single/profile/edit.php to your theme and add this line:

<?php if ( 'Field Name' == bp_get_the_profile_field_name() ) continue; ?>

Just below this line:

<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

This is similar to Chirag's approach, but will skip all things related to the field including the wrapper div, so you don't have extraneous HTML.

1
  • Hi, I used this and it works great, but when I hit the save button it empties all the hidden fields, so they don't have a value anymore. Did you run into this issue as well? Mar 9, 2019 at 16:07
0

You can use CSS to hide specific fields with id selector.

#field_1 {
display:none;
}
#signup_username {
display:none;
}
0

You can do it via bp_before_has_profile_parse_args filter:

function skip_xprofile_fields( $args ){
    global $bp, $wpdb;
    $field_name = 'First Name';
    $field_id = $wpdb->get_var( "SELECT id FROM {$bp->profile->table_name_fields} WHERE `name` = '".esc_sql($field_name)."'");
    $args['exclude_fields'] = ','.$field_id;
    return $args;
}
add_filter('bp_before_has_profile_parse_args', 'skip_xprofile_fields' );

Just replace $field_name var with your field name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.