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 11 years ago on Tuesday May 28, 2013 |
Permalink