PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

BuddyPress Profile Field Privacy

  1. Hi,

    I am currently using version 1.5.beta1.6 of the user registration addon. I am really impressed!

    I would however like to know if you'll be adding support for profile field privacy which is now a part of BuddyPress. I'd love to use Gravity forms to replace the normal edit profile forms, however in order to use it fully with BuddyPress it would be great I could somehow provide the privacy options on the form too.

    Steve

    Posted 11 years ago on Sunday December 30, 2012 | Permalink
  2. I'll bring this to the attention of the development team for their feedback.

    Posted 11 years ago on Sunday December 30, 2012 | Permalink
  3. Thanks :)

    Posted 11 years ago on Monday January 7, 2013 | Permalink
  4. We've added this to our list of requested features. Thus far, you are the only one who has asked. After talking it over with the team, this would be fairly involved to add, so we will wait to see what sort of interest there is in it before attempting to tackle it. Thank you for the suggestion.

    Posted 11 years ago on Monday January 14, 2013 | Permalink
  5. Hi There I am the second to request that. In fact for BuddyPress the new brilliant feature would be useless without that option.

    Cheers,
    T

    Posted 11 years ago on Wednesday January 23, 2013 | Permalink
  6. I do think it will become an issue if more people start using the plugin to update profiles. So a feature like this is something to think about in the near future, perhaps after the BETA release.

    I don't think it would be too difficult to implement, for example:

    When creating a feed you could have a checkbox 'enable privacy options', that could then check against the BuddyPress setting of the particular field and display the option(s) to the user on the frontend in the same way BuddyPress does. They simply have a line of text 'this field can be seen by anyone - change' and the 'change' link makes a dropdown box appear to alter the setting.

    Posted 11 years ago on Thursday January 24, 2013 | Permalink
  7. That would be perfect!

    Posted 11 years ago on Thursday January 24, 2013 | Permalink
  8. I opened a support ticket on this very topic last Friday. So, I guess this adds me to the list of people who desire this functionality for profile updates.

    Steve Holland has proposed a solution but it is unclear how I would do this inside my form. Is he suggesting a method to modify the userregistration addon itself? The latter seems more logical to me.

    This is the section of code found in userregistration.php that allows one to map buddypress xprofile fields to a gravity form:

    public static function get_buddypress_fields() {
        require_once(WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-classes.php');
        // get BP field groups
        $groups = BP_XProfile_Group::get(array('fetch_fields' => true ));
        $buddypress_fields = array();
        $i = 0;
        foreach($groups as $group) {
            if(!is_array($group->fields))
                continue;
            foreach($group->fields as $field) {
                $buddypress_fields[$i]['name'] = $field->name;
                $buddypress_fields[$i]['value'] = $field->id;
                $i++;
            }
        }
        return $buddypress_fields;
    }

    Within the bp-xprofile-classes.php script, I've found this code:

    //front end display condition
    if ( !empty( $fetch_visibility_level ) ) {
        $fields = self::fetch_visibility_level( $user_id, $fields );
    }

    The associatiated functions related to fetch_visibility_level:

    /**
    * Fetch the field visibility level for the fields returned by the query
    *
    * @since BuddyPress (1.6)
    *
    * @param int $user_id The profile owner's user_id
    * @param array $fields The database results returned by the get() query
    * @return array $fields The database results, with field_visibility added
    */
    function fetch_visibility_level( $user_id = 0, $fields = array() ) {
        // Get the user's visibility level preferences
        $visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
        // Get the admin-set preferences
        $admin_set_levels  = self::fetch_default_visibility_levels();
        foreach( (array) $fields as $key => $field ) {
            // Does the admin allow this field to be customized?
            $allow_custom = empty( $admin_set_levels[$field->id]['allow_custom'] ) || 'allowed' == $admin_set_levels[$field->id]['allow_custom'];
            // Look to see if the user has set the visibility for this field
            if ( $allow_custom && isset( $visibility_levels[$field->id] ) ) {
                $field_visibility = $visibility_levels[$field->id];
            // If no admin-set default is saved, fall back on a global default
            } else {
                $field_visibility = !empty( $admin_set_levels[$field->id]['default'] ) ? $admin_set_levels[$field->id]['default'] : apply_filters( 'bp_xprofile_default_visibility_level', 'public' );
            }
            $fields[$key]->visibility_level = $field_visibility;
        }
        return $fields;
    }
    
    /**
    * Fetch the admin-set preferences for all fields
    *
    * @since BuddyPress (1.6)
    *
    * @return array $default_visibility_levels An array, keyed by field_id, of default
    *   visibility level + allow_custom (whether the admin allows this field to be set by user)
    */
    function fetch_default_visibility_levels() {
        global $wpdb, $bp;
        $levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" );
    
        // Arrange so that the field id is the key and the visibility level the value
        $default_visibility_levels = array();
        foreach( $levels as $level ) {
            if ( 'default_visibility' == $level->meta_key ) {
                $default_visibility_levels[$level->object_id]['default'] = $level->meta_value;
            } else if ( 'allow_custom_visibility' == $level->meta_key ) {
                $default_visibility_levels[$level->object_id]['allow_custom'] = $level->meta_value;
            }
        }
        return $default_visibility_levels;
    }

    How to cobble all of this into a solution is the question...

    My project is due for launch on June 30, 2013. I want to know how/where to apply these functions to my profile update (Gravity) form or what would be the best method of customizing the userregistration.php to automate the inclusion of this functionality into the form on the front end, after the fiields have been mapped to their respective buddypress xprofile fields.

    Posted 10 years ago on Tuesday May 28, 2013 | Permalink
  9. I'll bring this to the attention of the development team for you. Thanks for your feedback.

    Posted 10 years ago on Tuesday May 28, 2013 | Permalink
  10. Can you please tell me what that means to me with regard to a time frame?

    Posted 10 years ago on Tuesday May 28, 2013 | Permalink
  11. David Peralty

    Everyone gets answered in turn, with one of our developers each week focused on helping with advanced level support requests. There is no time limit I can give you beyond that.

    Posted 10 years ago on Tuesday May 28, 2013 | Permalink
  12. Handling via priority support ticket.

    Posted 10 years ago on Friday May 31, 2013 | Permalink

This topic has been resolved and has been closed to new replies.