Skip to:

Visibility Fields should not depend on usermeta

  • webheadcoder


    I have a request to not depend on the ‘bp_xprofile_visibility_levels’ user meta setting in order to hide fields. Or simply add a hidden input explained in the workaround. Here is why:

    I developed a private membership site so naturally I wanted to disallow the ‘public’ visibility setting. I added something like:

    function myfunction($levels) {
        return $levels;
    add_filter( 'bp_xprofile_get_visibility_levels', 'myfunction');

    This caused a chain reaction to show all fields with an enforced visibility.

    I have a Mobile Phone field along with several others to be forced to be ‘adminsonly’. So there is no form input (radio buttons) to switch the visibility. BuddyPress checks _POST[‘field_123_visibility’] and if there is no post field, the default visibility is ‘public’. Then BuddyPress checks for the allowed visibilities. Since i took out ‘public’, ‘public’ is not an allowed visibility and does not save the users’ visibility preference (in bp_xprofile_visibility_levels) . Because the user does not have a visibility preference saved for this field it is not checked to be hidden (bp_xprofile_get_fields_by_visibility_levels()). Since it’s not even considered to be hidden, it shows. This is where I’d like a change to the code. I don’t think it’s right to skip a field if it is not in the user meta.

    I’m not expert at BuddyPress so maybe unsetting the ‘public’ visibility setting is a big no-no. It just seems very strange that unsetting the ‘public’ visibility can cause ‘adminsonly’ fields to show publicly.

    My workaround for this is to just add a hidden field so that the usermeta is saved. in members/single/profile/edit.php I added the following:
    <input type="hidden" name="field_<?php bp_the_profile_field_id();?>_visibility" value="adminsonly">

  • The topic ‘Visibility Fields should not depend on usermeta’ is closed to new replies.
Skip to toolbar