Title: Kyle.php's Replies | WordPress.org

---

# Kyle.php

  [  ](https://wordpress.org/support/users/kylephp/)

 *   [Profile](https://wordpress.org/support/users/kylephp/)
 *   [Topics Started](https://wordpress.org/support/users/kylephp/topics/)
 *   [Replies Created](https://wordpress.org/support/users/kylephp/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/kylephp/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/kylephp/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/kylephp/engagements/)
 *   [Favorites](https://wordpress.org/support/users/kylephp/favorites/)

 Search replies:

## Forum Replies Created

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

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Groups] bbPress topic direct link](https://wordpress.org/support/topic/bbpress-topic-direct-link/)
 *  [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.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Groups] bbPress topic direct link](https://wordpress.org/support/topic/bbpress-topic-direct-link/)
 *  [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.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Groups] bbPress topic direct link](https://wordpress.org/support/topic/bbpress-topic-direct-link/)
 *  [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.

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