Title: bbPress topic direct link
Last modified: August 21, 2016

---

# bbPress topic direct link

 *  [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * (@thetechnoman)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/)
 * Hello,
 * thank for this amazing and free plugin.
 * Everythink works fine with one exception.
 * Users are still able to access a topic with the direct link to that topic.
 * Could you fix this?
 * Thank you very much
 * [http://wordpress.org/plugins/groups/](http://wordpress.org/plugins/groups/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * (@thetechnoman)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477520)
 * I would appreciate it if i could get a answer.
 * Thanks
 *  [Kyle.php](https://wordpress.org/support/users/kylephp/)
 * (@kylephp)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477526)
 * Hello,
    I noticed a similar issue recently: The topics & replies under private
   forums, were publicly visible in widgets (recents topics, recents replies, etc…).
 * That’s because posts (and custom post types like topics & replies) does not inherit
   the parents restrictions.
 * Here is my fix. Seems to work but no guarantee. Plugin author or skilled people
   opinion could be useful on this one 🙂
 *     ```
       function force_access_restriction_inheritance( $post_id, $post ) {
   
           $post_caps = Groups_Post_Access::get_read_post_capabilities( $post_id );
   
           // Force topic, reply & attachments inheritance.
           if ( !in_array( $post->post_type, array( 'topic', 'reply', 'attachment' ) ) || 'publish' != $post->post_status || wp_is_post_revision($post_id) )
               return;
   
           $caps = Groups_Post_Access::get_read_post_capabilities( $post->post_parent );
           $diff = array_diff( $caps, Groups_Post_Access::get_read_post_capabilities( $post_id ) );
   
           if ( empty( $diff ) ) // Capabality already exists.
               return;
   
           $return = array();
   
           foreach ( $caps as $cap )
               $return[] = Groups_Post_Access::create( array( 'post_id' => $post_id, 'capability' => $cap ));
   
           // do not save post if capability add failed.
           if ( in_array( false, $return ) )
               wp_die( 'Something went wrong.' );
       }
       add_action( 'save_post', 'force_access_restriction_inheritance', 99, 2 );
       ```
   
 * ps: please excuse my poor english.
 *  Thread Starter [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * (@thetechnoman)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477537)
 * Hey Kyle,
 * thank you very much.
 * Could you tell me where i have to put this code?
 * I placed it in my themes functions.php but i can still access the threads without
   the permission.
 * // EDIT: add_action( ‘save_post’, ‘force_access_restriction_inheritance’, 99,
   2 );
 * I need to check if a visitor has the needed role for a forums in order to reads
   the containing threads 🙁
 * Thanks!
 *  [Kyle.php](https://wordpress.org/support/users/kylephp/)
 * (@kylephp)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477538)
 * Hello,
 * You have two ways to use this code :
    1. You can [create a plugin](http://codex.wordpress.org/Writing_a_Plugin)
    2. You can add it in the theme functions.php, but in that case I strongly recommend
       to [create a child theme](http://codex.wordpress.org/Child_Themes)
 * In both cases, remember that the code is hooked on the “save_post” action, meaning
   you’ll have to update existing posts to trigger the action:
    In admin, set a 
   capability to a forum, then use the batch edit to update every topics once then
   do the same for every replies.
 * Hope that help.
 *  Thread Starter [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * (@thetechnoman)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477539)
 * Ah okay thanks.
 * So if a new post is created in inhertis the required capabilieties which i have
   set for the forums? Correct?
 *  [Kyle.php](https://wordpress.org/support/users/kylephp/)
 * (@kylephp)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477540)
 * Correct. That’s the purpose of the code.
 *  Thread Starter [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * (@thetechnoman)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477541)
 * Thank you very much. I will try to create the plugin. Not sure if i am able to
   do that lol.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘bbPress topic direct link’ is closed to new replies.

 * ![](https://ps.w.org/groups/assets/icon-256x256.png?rev=983146)
 * [Groups](https://wordpress.org/plugins/groups/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/groups/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/groups/)
 * [Active Topics](https://wordpress.org/support/plugin/groups/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/groups/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/groups/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [TheTechnoMan](https://wordpress.org/support/users/thetechnoman/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/bbpress-topic-direct-link/#post-4477541)
 * Status: not resolved