rcp_bbp_can_access_topic

The Restrict Content Pro - bbPress rcp bbp can access topic function.

Description

rcp_bbp_can_access_topic( (int) $topic_id = 0 ); 

Parameters (1)

0. $topic_id — Optional. (int)
The topic id.

Usage

  1. if ( !function_exists( 'rcp_bbp_can_access_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'restrict-content-pro-bbpress/includes/topic-functions.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = rcp_bbp_can_access_topic($topic_id); 
  9.  

Defined (1)

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

/includes/topic-functions.php  
  1. function rcp_bbp_can_access_topic( $topic_id = 0 ) { 
  2.  
  3. if( ! function_exists( 'rcp_is_active' ) ) { 
  4. return true; 
  5.  
  6. $ret = true; 
  7. $user_id = get_current_user_id(); 
  8. $paid_only = rcp_topic_is_premium( $topic_id ); 
  9. $access_level = get_post_meta( $topic_id, 'rcp_access_level', true ); 
  10. $subscriptions = get_post_meta( $topic_id, 'rcp_subscription_level', true ); 
  11.  
  12. if( $paid_only && ! rcp_is_active( $user_id ) ) { 
  13.  
  14. $ret = false; // User does not have a paid subscription 
  15.  
  16.  
  17. if ( $access_level > 0 && ! rcp_user_has_access( $user_id, $access_level ) ) { 
  18.  
  19. $ret = false; // User does not have the necessary access level 
  20.  
  21.  
  22. if( ! empty( $subscriptions ) && ! in_array( rcp_get_subscription_id( $user_id ), $subscriptions ) ) { 
  23.  
  24. $ret = false; // User does not have the appropriate subscription level 
  25.  
  26.  
  27. if( ! rcp_bbp_can_access_forum( bbp_get_forum_id() ) ) { 
  28.  
  29. $ret = false; // If the user can't view the topic, they can't view the forum 
  30.  
  31. if( current_user_can( 'moderate' ) ) { 
  32.  
  33. $ret = true; // Moderators can always access forums 
  34.  
  35.  
  36. return apply_filters( 'rcp_bbp_can_access_topic', $ret, $topic_id, $user_id );