Toby (@tobyhawkins)

Forum Replies Created

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

  • Toby
    Participant

    @tobyhawkins

    Still not completely sure why this is happening, but I think it’s because of the way the forum is being displayed using the BuddyPress group tabs/screen hooks. Digging into the is_bbpress() function, none of the WP_Query information is being set so it doesn’t pass any of the is_ functions.

    You can filter is_bbpress in bbpress > includes > extend > buddypress > groups in the setup_filters() function and get it working, but I can’t see a way of doing this without modifying the plugin code.


    Toby
    Participant

    @tobyhawkins

    Not quite sure if I understand exactly what you want, but one of these should help..

    If you want to display a search form at the top of single topics add the following to your functions.php file:

        function my_bbp_topic_search_form(){
            ?>
            <div class="bbp-search-form">
         
                <?php bbp_get_template_part( 'form', 'search' ); ?>
         
            </div>
            <?php
        }
        add_action( 'bbp_template_before_single_topic', 'my_bbp_topic_search_form' );

    If you want a search form at the top of single forums (or sub forums) use the following in your functions.php file:

        function my_bbp_forum_search_form(){
            ?>
            <div class="bbp-search-form">
         
                <?php bbp_get_template_part( 'form', 'search' ); ?>
         
            </div>
            <?php
        }
        add_action( 'bbp_template_before_single_forum', 'my_bbp_forum_search_form' );

    If you want to limit results to the topic or forum in question that will be a little more tricky but the following post will point you in the right direction (it shows you how to limit searching to a single forum – you’ll need to customise further to apply it to a single topic): http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress.

    Hope that helps.


    Toby
    Participant

    @tobyhawkins

    Yes. That’s not ideal. I think the problem is the bbp_pre_get_posts_normalize_forum_visibility function in bbpress > includes > forums > functions.php.

    I’m not going to vouch for the security of this (although I think the logic is ok and cursory testing seems to bear this out) but you can get round this by changing your my_bbp_filter_search_results function to the following:

    function my_bbp_filter_search_results( $r ){
    
        //Get the submitted forum ID (added in gethub > bbpress > form-search.php)
        $forum_id = sanitize_title_for_query( $_GET['bbp_search_forum_id'] );
     
        //If the forum ID exits, filter the query
        if( $forum_id && is_numeric( $forum_id ) ){
     
            $r['meta_query'] = array(
                array(
                    'key' => '_bbp_forum_id',
                    'value' => $forum_id,
                    'compare' => '=',
                )
            );
    	    
            $group_id = bbp_get_forum_group_ids( $forum_id );
            if( groups_is_user_member( bp_loggedin_user_id(), $group_id[0] ) )
            {
                function my_allow_all_forums () { return true; }
                add_filter( 'bbp_include_all_forums', 'my_allow_all_forums' );
            }
        }
     
        return $r;
    }
    add_filter( 'bbp_after_has_search_results_parse_args' , 'my_bbp_filter_search_results' );

    To negate the danger of plugins forgetting to manage permissions for posts properly the normalize function visibility automatically steps in on any WP_Query activity and shuts it down, but apparently doesn’t account for the possibility of forums being private, but viewable by low level users within the group context. By adding the filter only when searching on a single forum and then only if the logged-in user is a member of the correct group I think I have accounted for the security issues, but I’m not enough of a php expert to be 100% confident that I haven’t missed something.


    Toby
    Participant

    @tobyhawkins

    I should mention that it still doesn’t work when I delete the child theme bbpress overrides.


    Toby
    Participant

    @tobyhawkins

    I haven’t tried this out, but it looks like it might be what you’re looking for.

    http://sevenspark.com/tutorials/how-to-search-a-single-forum-with-bbpress


    Toby
    Participant

    @tobyhawkins

    I’m using the following in my theme’s functions.php, although for some reason is_bbpress() isn’t working on Buddypress Group Forums for me.

        if( ! function_exists( 'my_dequeue_bbp_scripts' ) )
        {
            function my_dequeue_bbp_scripts()
            {
                if( function_exists( 'is_bbpress' ) )
                {
                    if( ! is_bbpress() )
                    {
                        wp_dequeue_style('bbp-default');
                        wp_dequeue_style('bbp-default-rtl');
                    }
                }
            }
        }
        if( ! is_admin() ) add_action( 'wp_enqueue_scripts', 'my_dequeue_bbp_scripts' );
Viewing 6 replies - 1 through 6 (of 6 total)