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

Return a validated user id


Description Description


Parameters Parameters

$user_id

(Optional) User id

$displayed_user_fallback

(Optional) Fallback on displayed user?

Default value: true

$current_user_fallback

(Optional) Fallback on current user?

Default value: false


Top ↑

Return Return

(int) Validated user id


Top ↑

Source Source

File: includes/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 inside a user loop
		} elseif ( ! empty( $bbp->user_query->in_the_loop ) && isset( $bbp->user_query->user->ID ) ) {
			$bbp_user_id = $bbp->user_query->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;
		}

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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