how to hide specific BuddyPress profile fields

I found this tutorial from 2009: "Hide Selected Profile Feeds" in the article https://premium.wpmudev.org/blog/5-useful-hacks-and-code-snippets-for-buddypress-and-wpmu/

The code is outdated.

Could you tell me of a plugin (preferred / GUI) to select one or more fields to be hidden from displaying to anyone other than Admin? Or, alternatively, a db/theme hack to do so, as was suggested in the linked article.

For example: http://ScrnSht.com/ntjwqq
I don't want the blacked-out field displayed AT ALL in anyone's profile except their own or by an Admin.
But I NEED it when people register to the site.

Thank you.

  • Patrick
    • Support Monkey

    @Steve

    Nice request on uservoice; I added my vote. You mentioned in your comment there that a profile search feature would be handy. There's already a plugin for that: http://wordpress.org/extend/plugins/bp-profile-search/ It would be great to see that forked for BP profile groups.
    EDIT - scratch that! I just saw on another thread that someone else had tried this plugin and it's buggy: https://premium.wpmudev.org/forums/topic/buddypress-profile-search-1

    @Clifford

    I found this nifty plugin that might be worth a shot for what you're trying to achieve: http://wordpress.org/extend/plugins/buddypress-profiles-manager/ It hasn't been updated since June of last year, but you could take a look inside to see how the conditional statements are made to hide specific profile groups. Then create a profile group for the field(s) you want hidden following your own conditionals.

  • Patrick
    • Support Monkey

    Hi Arun,

    No, that example is to display xprofile fields in the member-header (or anywhere else with mods). I believe what Clifford & Steve are looking for is a way to hide selected xprofile fields from view except if the member profile is being viewed by super_admin or current_user

  • SteveDB
    • Design Lord, Child of Thor

    @pcwriter

    Thats correct and a whole lot more as in the link to the example using joomla and jomsocial.

    I have used this and it was very good with a lot of features and flexibilty as regards membership acl.

    The search function has the ability to set up a search box with full controll via the admin as to who see's what fields.

    So could be setup for dating sites too?

    And thanks for the votes :slight_smile:

    Spread the word more needed.

    Steve.

  • Clifford P
    • The Bug Hunter

    @pcwriter ( https://premium.wpmudev.org/forums/topic/how-to-hide-specific-buddypress-profile-fields#post-192419 )

    I tried creating profile groups in addition to "Base (Primary)" but the non-Base group(s) didn't show up on the Registration screen (at least not using EduClean Homepage).
    Probably because of this message right within wp-admin: "NOTE: Any fields in the "Base" group will appear on the signup page."
    How do you make a non-Base profile group that's displayed on Registration page?

  • Patrick
    • Support Monkey

    Hi Clifford,

    Ah, if you want that profile field to appear on the registration page, then it must be in the Base group. So the Buddypress Profiles Manager plugin won't necessarily help you, not in the way it was designed to anyway. However, you should be able to get a good idea of how the conditionals in the plugin are hiding profile groups, and then apply that to a specific field you want to hide in a non-Base group.

    If you need help with that, let me know and I'll download the plugin to see if I can't figure something out for ya! :slight_smile:

  • Patrick
    • Support Monkey

    Hi Clifford,

    I haven't been able to figure out how to prevent the field label and data from being delivered to the browser, but the label and data can be hidden from view on screen. Although savvy users will still be able to see the hidden info by viewing the source code, sorry.

    Add the following snippet to your active theme/child-theme's functions.php file or bp-custom.php. Change tr.field_field-name to the name of the table row you want to hide. If you want to hide more than one, simply separate them with commas like in any css style. Be sure to add the code after the opening php tag, or before the closing one.

    You can find the name of the table row you need by viewing the page source, or using Firebug or similar tool in another browser. For example, the table row for the Name field in the Base group would be tr.field_name.

    function my_hide_profile_fields() {
    if(!is_super_admin() && !bp_is_home()) { ?>
    <?php print "<style type='text/css' media='screen'>"; ?>
    tr.field_field-name
    { display: none; }
    <?php print "</style>"; ?>
    <?php }
    }
    add_action( 'wp_head', 'my_hide_profile_fields');

    If anyone else would care to take a stab at this to find a way to prevent the data from being delivered to the browser, go for it!

    Hope this helps! :slight_smile:

  • Clifford P
    • The Bug Hunter

    seems like it's definitely a BuddyPress core issue.
    CSS display:none; is better than nothing but isn't the real solution, as you pointed out.
    sounds like an excellent plugin for WPMU DEV to take on. I doubt it'd be considered "core" functionality even if BuddyPress peeps agreed 100%.
    Thanks for this addition. 10 rep your way.

  • gogger
    • Design Lord, Child of Thor

    Im trying to do something slightly different, but i think its in the same vein. We need to find a way to filter out x field, apply instructions to just that field, and the print the rest as normal. So far i think iv worked out it needs to involve bp_get_the_profile_field_name() - so something along the lines of this perhaps? (i havnt tested this, i dont have access to a BP test site atm, will set one up tonight to work this out - SO DO NOT USE THIS ON A PRODUCTION SITE, testing only.)

    This replaces the whole table in profile-loop.php [line 13 - 33]

    <table class="profile-fields">
      <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
        <?php if ( bp_field_has_data() ) : ?>
          <?php if ( (bp_get_the_profile_field_name() == "field_in_question") && !is_super_admin() && !bp_is_home()) { ?> ) : ?>
            <?php echo "";?>
          <?php else : ?>
            <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 endif; ?>
        <?php do_action( 'bp_profile_field_item' ); ?>
      <?php endwhile; ?>
    </table>

    p.s. relatively im a novice to many others here, just trying to contribute to the answer with the knowledge i have available :slight_smile:

  • gogger
    • Design Lord, Child of Thor

    Ok the above code did not work - but this does. Remember to change the field name to the field you wish to hide - its CASE SENSITIVE so be aware [where it says $data_field == "field-name"].

    Replace the whole <table class="profile-fields"></table> section in buddypress/bp-themes/*theme-name/members/single/profile/profile-loop.php

    <table class="profile-fields">
      <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
        <?php if ( bp_field_has_data() ) : ?>
          <?php $data_field = bp_get_the_profile_field_name(); if ( ($data_field == "field-name") && !is_super_admin() && !bp_is_home()) : ?>
            <?php echo "";?>
          <?php else : ?>
            <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 endif; ?>
    <?php do_action( 'bp_profile_field_item' ); ?>
      <?php endwhile; ?>
    </table>
  • Clifford P
    • The Bug Hunter

    I wish I could say that it worked, but it didn't.

    I took off @pcwriter's display:none; code and the field was displayed.

    I added @gogger's code and the fields remained displayed.
    I tried it in edu-clean theme and edu-clean-child with the same folder hierarcy.

    I hope this can get working (PHP no-show instead of CSS no-show) soon (thanks for your efforts!) but I have to say that a GUI is definitely worthy of request I think (i.e. a plugin).

    Looking forward to your feedback...

  • gogger
    • Design Lord, Child of Thor

    Ok i downloaded edu-clean and tried the code, it works. I didnt make a child theme - just modified the theme files, but if it works on the theme files it will work as a child theme. Are you sure you got the directory structure correct? Did you try and hide multiple fields? If so, howd you modify the code to do it? - the code i posted only hides 1 field, youd need to change it slightly to do more than one. Also remember the field names are case sensitiv and that the field will show up to a logged in user or an admin - youll need to log out to test if it gets hidden.

  • gogger
    • Design Lord, Child of Thor

    Ok, new install of buddypress with a fresh version of edublogs theme. The second lot of code i posted placed in the profile-loop.php replacing the existing <table> code works. Iv just tried it. So im not really sure why its not working for you... I can only suggest double checking the field name is correct and the files are in the right place.

    A GUI for this would be awesome i agree...

  • gogger
    • Design Lord, Child of Thor

    I guess you could try renaming the $data_field variable to something more unique like $hidden_profile_data_field just in case something in a plugin on the same page is using the same name... but id check the field names and that the code is in the right place first.

  • Clifford P
    • The Bug Hunter

    @gogger
    I really appreciate your effort. Maybe I'm doing something wrong, but I can't imagine what if I got the display:none; CSS to work - should be the same field names...

    So, for your code, if this is the table row I want to hide:

    <tr class="field_2 field_home-address">
            <td class="label">Home Address</td>
            <td class="data"><p><a href="http://example.com/members/?s=12345 East Ave" rel="nofollow">12345 East Ave</a></p>
    </td>
            </tr>

    What should I put here (from your code)?
    <?php $data_field_hidden = bp_get_the_profile_field_name(); if ( ($data_field_hidden == "field_home-address") && !is_super_admin() && !bp_is_home()) : ?>

    I tried field_home-address, home-address, field_2, 2, and I don't know why it won't work...

  • gogger
    • Design Lord, Child of Thor

    Ah this is probably where its going wrong. The css class names and the actual field names are different - css class names refer to styles/scripts to be applied to the data. You need to use the field name as you entered it when you set up the profile field in the buddypress back end - sorry if i confused you. So from what i see it should be the following:

    <?php $data_field_hidden = bp_get_the_profile_field_name(); if ( ($data_field_hidden == "Home Address") && !is_super_admin() && !bp_is_home()) : ?>

    The field name is the name of the field in the actual database. @pcwriter's method is applying the display: none; property to anything with css selector specified [in this case field_home-address], but for the php method we need to select it from the database to stop it being displayed at the user end so we need to use the reference the database uses to select the entry.

  • Clifford P
    • The Bug Hunter

    Great! Got that to work. Sorry I didn't catch the db field name thing. I just saw the format of "field-name" and thought it was the same; "field name" might have made me think of it....

    I will get you some rep points. Hopefully some others will contribute rep as well.

    Here's the "multiple fields" hide...

    wrong code removed, see below
  • Clifford P
    • The Bug Hunter

    An oldie but a goodie... So I came back to it... And changed my previous "multi field" code (cuz it was wrong) and also changed to use field IDs instead of field Names....

    and got this:

    <?php
    // from https://premium.wpmudev.org/forums/topic/how-to-hide-specific-buddypress-profile-fields ?>
    <table class="profile-fields">
      <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
        <?php if ( bp_field_has_data() ) : ?>
    <?php
          $data_field = bp_get_the_profile_field_id();
          $hide_these_field_ids = array(2, 7, 10); // from wp_bp_xprofile_fields table
          if ( (in_array($data_field, $hide_these_field_ids) && !is_super_admin() && !bp_is_home()) ) : ?>
            <?php echo "";?>
          <?php else : ?>
            <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 endif; ?>
    <?php do_action( 'bp_profile_field_item' ); ?>
      <?php endwhile; ?>
    </table>

    Enjoy! It really helped me out. Thanks again people.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.