BP_REST_Topics_Endpoint::get_topic_action_states( int $topic_id )

Get topic actions state based on current user.

Description

Parameters

$topic_id

(Required) ID of the topic.

Return

(array|void)

Source

File: bp-forums/classes/class-bp-rest-topics-endpoint.php

	public function get_topic_action_states( $topic_id ) {
		if ( empty( $topic_id ) ) {
			return;
		}

		$topic_id = (int) $topic_id;
		$user_id  = bbp_get_user_id( 0, true, true );

		$state = array(
			'subscribed'   => '',
			'favorited'    => '',
			'open'         => bbp_is_topic_open( $topic_id ),
			'sticky'       => bbp_is_topic_sticky( $topic_id ),
			'super_sticky' => bbp_is_topic_super_sticky( $topic_id ),
			'spam'         => bbp_is_topic_spam( $topic_id ),
			'trash'        => bbp_is_topic_trash( $topic_id ),
		);

		if ( bbp_is_favorites_active() && current_user_can( 'edit_user', $user_id ) ) {
			$state['favorited'] = bbp_is_user_favorite( $user_id, $topic_id );
		}

		if ( bbp_is_subscriptions_active() && current_user_can( 'edit_user', $user_id ) ) {
			$state['subscribed'] = bbp_is_user_subscribed( $user_id, $topic_id );
		}

		return $state;
	}

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.