xprofile_set_field_visibility_level( int $field_id, int $user_id, string $visibility_level = '' )

Set the visibility level for this field.

Description

Parameters

$field_id

(int) (Required) The ID of the xprofile field.

$user_id

(int) (Required) The ID of the user to whom the data belongs.

$visibility_level

(string) (Optional) What the visibity setting should be.

Default value: ''

Return

(bool) True on success

Source

File: bp-xprofile/bp-xprofile-functions.php

function xprofile_set_field_visibility_level( $field_id = 0, $user_id = 0, $visibility_level = '' ) {
	if ( empty( $field_id ) || empty( $user_id ) || empty( $visibility_level ) ) {
		return false;
	}

	// Check against a whitelist.
	$allowed_values = bp_xprofile_get_visibility_levels();
	if ( !array_key_exists( $visibility_level, $allowed_values ) ) {
		return false;
	}

	// Stored in an array in usermeta.
	$current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );

	if ( !$current_visibility_levels ) {
		$current_visibility_levels = array();
	}

	$current_visibility_levels[$field_id] = $visibility_level;

	return bp_update_user_meta( $user_id, 'bp_xprofile_visibility_levels', $current_visibility_levels );
}

Changelog

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.