BP_REST_Forums_Endpoint::can_access_content( int $forum_id, bool $create = false )
Check current access permission.
Description
Parameters
- $forum_id
-
(Required) ID of the forum.
- $create
-
(Optional) force validate.
Default value: false
Return
(bool)
Source
File: bp-forums/classes/class-bp-rest-forums-endpoint.php
public function can_access_content( $forum_id, $create = false ) { if ( function_exists( 'bbp_is_forum_group_forum' ) && bbp_is_forum_group_forum( $forum_id ) ) { $group_ids = bbp_get_forum_group_ids( $forum_id ); $user_id = get_current_user_id(); $flag = false; if ( ! empty( $group_ids ) ) { foreach ( $group_ids as $group_id ) { if ( function_exists( 'bp_is_active' ) && bp_is_active( 'groups' ) ) { // if we checking access for showing forums, topic and replies then we need to check group is public or not. if ( ! $create ) { $group = groups_get_group( $group_id ); if ( 'public' === $group->status ) { $flag = true; } } if ( groups_is_user_member( $user_id, $group_id ) || groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) || bbp_is_user_keymaster( $user_id ) ) { $flag = true; } } } } return $flag; } elseif ( empty( $forum_id ) || ! bbp_user_can_view_forum( array( 'forum_id' => $forum_id, ) ) ) { return false; } else { return true; } }
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.