Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Correct. That’s the purpose of the code.

    Hello,

    You have two ways to use this code :

    1. You can create a plugin
    2. You can add it in the theme functions.php, but in that case I strongly recommend to create a child theme

    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.

    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)