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

Set the visibility level for this field.


Description Description


Parameters Parameters

$field_id

(Required) The ID of the xprofile field.

$user_id

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

$visibility_level

(Optional) What the visibility setting should be.

Default value: ''


Top ↑

Return Return

(bool) True on success


Top ↑

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

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.