bbp_user_can_view_forum

Check if the user can access a specific forum.

Description

bbp_user_can_view_forum( (string) $args = '' ); 

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Usage

  1. if ( !function_exists( 'bbp_user_can_view_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // The args. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_user_can_view_forum($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/users/template.php  
  1. function bbp_user_can_view_forum( $args = '' ) { 
  2.  
  3. // Parse arguments against default values 
  4. $r = bbp_parse_args( $args, array( 
  5. 'user_id' => bbp_get_current_user_id(),  
  6. 'forum_id' => bbp_get_forum_id(),  
  7. 'check_ancestors' => false 
  8. ), 'user_can_view_forum' ); 
  9.  
  10. // Validate parsed values 
  11. $user_id = bbp_get_user_id( $r['user_id'], false, false ); 
  12. $forum_id = bbp_get_forum_id( $r['forum_id'] ); 
  13. $retval = false; 
  14.  
  15. // User is a keymaster 
  16. if ( !empty( $user_id ) && bbp_is_user_keymaster( $user_id ) ) { 
  17. $retval = true; 
  18.  
  19. // Forum is public, and user can read forums or is not logged in 
  20. } elseif ( bbp_is_forum_public( $forum_id, $r['check_ancestors'] ) ) { 
  21. $retval = true; 
  22.  
  23. // Forum is private, and user can see it 
  24. } elseif ( bbp_is_forum_private( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_private_forums' ) ) { 
  25. $retval = true; 
  26.  
  27. // Forum is hidden, and user can see it 
  28. } elseif ( bbp_is_forum_hidden ( $forum_id, $r['check_ancestors'] ) && user_can( $user_id, 'read_hidden_forums' ) ) { 
  29. $retval = true; 
  30.  
  31. return apply_filters( 'bbp_user_can_view_forum', $retval, $forum_id, $user_id );