bbp_get_displayed_user_field( string $field = '', string $filter = 'display' )

Return a sanitized user field value

Description

This function relies on the $filter parameter to decide how to sanitize the field value that it finds. Since it uses the WP_User object’s magic __get() method, it can also be used to get user_meta values.

See also

Parameters

$field

(string) (Optional) Field to get

Default value: ''

$filter

(string) (Optional) How to filter the field value (null|raw|db|display|edit)

Default value: 'display'

Return

(string|bool) Value of the field if it exists, else false

Source

File: bp-forums/users/template.php

	function bbp_get_displayed_user_field( $field = '', $filter = 'display' ) {

		// Get the displayed user
		$user         = bbpress()->displayed_user;

		// Juggle the user filter property because we don't want to muck up how
		// other code might interact with this object.
		$old_filter   = $user->filter;
		$user->filter = $filter;

		// Get the field value from the WP_User object. We don't need to perform
		// an isset() because the WP_User::__get() does it for us.
		$value        = $user->$field;

		// Put back the user filter property that was previously juggled above.
		$user->filter = $old_filter;

		// Return empty
		return apply_filters( 'bbp_get_displayed_user_field', $value, $field, $filter );
	}

Changelog

Changelog
Version Description
bbPress (r2688) 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.