[buddypress-trac] [BuddyPress Trac] #7304: xProfile Group field
buddypress-trac
noreply at wordpress.org
Tue Oct 25 19:43:22 UTC 2016
#7304: xProfile Group field
-------------------------------+------------------
Reporter: danbp | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone:
Component: Extended Profile | Version: 2.7
Severity: normal | Resolution:
Keywords: reporter-feedback |
-------------------------------+------------------
Comment (by dcavins):
Oh, we're using a `for()` loop with an incrementor rather than some other
loop (like a foreach), so the array's key values matters. This should
avoid the problem:
{{{
function bpfr_hide_profile_field_group( $groups ) {
// Hide the profile group tabs on the edit interface for all non-
admins.
if ( bp_is_user_profile_edit() && ! current_user_can( 'bp_moderate' )
) {
$remove_groups = array( 2 ); // Put the IDs of the groups to
remove here, separated by commas.
foreach ( $groups as $key => $group_obj ) {
if ( in_array( $group_obj->id, $remove_groups ) ) {
unset( $groups[$key] );
}
}
$groups = array_values( $groups );
}
return $groups;
}
add_filter( 'bp_profile_get_field_groups', 'bpfr_hide_profile_field_group'
);
}}}
or, to save a foreach, this is probably better:
{{{
function bpfr_hide_profile_field_group( $groups ) {
// Hide the profile group tabs on the edit interface for all non-
admins.
if ( bp_is_user_profile_edit() && ! current_user_can( 'bp_moderate' )
) {
$remove_groups = array( 2 ); // Put the IDs of the groups to
remove here, separated by commas.
$new_set = array();
foreach ( $groups as $key => $group_obj ) {
if ( ! in_array( $group_obj->id, $remove_groups ) ) {
$new_set[] = $group_obj;
}
}
return $new_set;
}
return $groups;
}
}}}
Sorry for the earlier mistake!
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7304#comment:7>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list