bbp_forum_enforce_hidden

Check if it's a hidden forum or a topic or reply of a hidden forum and if the user can't view it, then sets a 404.

Description

bbp_forum_enforce_hidden(); 

Usage

  1. if ( !function_exists( 'bbp_forum_enforce_hidden' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_forum_enforce_hidden(); 
  7.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_forum_enforce_hidden() { 
  2.  
  3. // Bail if not viewing a single item or if user has caps 
  4. if ( !is_singular() || bbp_is_user_keymaster() || current_user_can( 'read_hidden_forums' ) ) 
  5. return; 
  6.  
  7. global $wp_query; 
  8.  
  9. // Define local variable 
  10. $forum_id = 0; 
  11.  
  12. // Check post type 
  13. switch ( $wp_query->get( 'post_type' ) ) { 
  14.  
  15. // Forum 
  16. $forum_id = bbp_get_forum_id( $wp_query->post->ID ); 
  17. break; 
  18.  
  19. // Topic 
  20. $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID ); 
  21. break; 
  22.  
  23. // Reply 
  24. $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID ); 
  25. break; 
  26.  
  27.  
  28. // If forum is explicitly hidden and user not capable, set 404 
  29. if ( !empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )