bbp_get_user_id( int $user_id, bool $displayed_user_fallback = true, bool $current_user_fallback = false )

Return a validated user id

Description

Parameters

$user_id

(int) (Optional) User id

$displayed_user_fallback

(bool) (Optional) Fallback on displayed user?

Default value: true

$current_user_fallback

(bool) (Optional) Fallback on current user?

Default value: false

Return

(int) Validated user id

Source

File: bp-forums/users/template.php

	function bbp_get_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
		$bbp = bbpress();

		// Easy empty checking
		if ( !empty( $user_id ) && is_numeric( $user_id ) ) {
			$bbp_user_id = $user_id;

		// Currently viewing or editing a user
		} elseif ( ( true === $displayed_user_fallback ) && !empty( $bbp->displayed_user->ID ) ) {
			$bbp_user_id = $bbp->displayed_user->ID;

		// Maybe fallback on the current_user ID
		} elseif ( ( true === $current_user_fallback ) && !empty( $bbp->current_user->ID ) ) {
			$bbp_user_id = $bbp->current_user->ID;

		// Failsafe
		} else {
			$bbp_user_id = 0;
		}

		return (int) apply_filters( 'bbp_get_user_id', (int) $bbp_user_id, $displayed_user_fallback, $current_user_fallback );
	}

Changelog

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