bp_xprofile_map_meta_caps( array $caps, string $cap, int $user_id, mixed $args )
Maps XProfile caps to built in WordPress caps.
Description
Parameters
- $caps
-
(Required) Capabilities for meta capability.
- $cap
-
(Required) Capability name.
- $user_id
-
(Required) User id.
- $args
-
(Required) Arguments.
Return
(array) Actual capabilities for meta capability.
Source
File: bp-xprofile/bp-xprofile-caps.php
function bp_xprofile_map_meta_caps( $caps, $cap, $user_id, $args ) {
switch ( $cap ) {
case 'bp_xprofile_change_field_visibility' :
$caps = array( 'exist' );
// You may pass args manually: $field_id, $profile_user_id.
$field_id = 0;
$profile_user_id = isset( $args[1] ) ? (int) $args[1] : bp_displayed_user_id();
if ( ! empty( $args[0] ) ) {
$field_id = (int) $args[0];
} elseif ( isset( $GLOBALS['profile_template'] ) && $GLOBALS['profile_template']->in_the_loop ) {
$field_id = bp_get_the_profile_field_id();
}
// Visibility on the fullname field is not editable.
if ( 1 == $field_id ) {
$caps[] = 'do_not_allow';
break;
}
// Has the admin disabled visibility modification for this field?
if ( 'disabled' == bp_xprofile_get_meta( $field_id, 'field', 'allow_custom_visibility' ) ) {
$caps[] = 'do_not_allow';
break;
}
// Connections don't edit each other's visibility.
if ( $profile_user_id != bp_displayed_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
$caps[] = 'do_not_allow';
break;
}
break;
}
/**
* Filters the XProfile caps to built in WordPress caps.
*
* @since BuddyPress 1.6.0
*
* @param array $caps Capabilities for meta capability.
* @param string $cap Capability name.
* @param int $user_id User ID being mapped.
* @param mixed $args Capability arguments.
*/
return apply_filters( 'bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.6.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.