bp_xprofile_map_meta_caps( array $caps, string $cap, int $user_id, mixed $args )

Maps XProfile caps to built in WordPress caps.


Parameters Parameters

$caps

(array) (Required) Capabilities for meta capability.

$cap

(string) (Required) Capability name.

$user_id

(int) (Required) User id.

$args

(mixed) (Required) Arguments.


Top ↑

Return Return

(array) Actual capabilities for meta capability.


Source 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;
			}

			// Friends don't let friends 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 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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.