Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search functionality with Private Groups plugin

  • @cracoucas

    Participant

    Hi!

    I’m just begining with Private Groups plugin (and even with wordpress!), that seems to be a great plugin to manage users permissions to access to bbpress forums.

    Just let me introduce my “configuration” in few words : I’m working with
    – 2 forums (A and B)
    – 2 groups (1 & 2)
    – Group 1 is authorised to work with both forum A and B.
    – Group 2 is only able to work with forum B.

    I have 2 questions about Private Groups behaviors :
    – SEARCH FUNCIONALITY : bpress search form or widget deal with all topics of all forums. I mean that the search functionnality does not take into account groups that are defined with Private Groups when displaying the results list. That’s true that a non authorised user can’t access to the detail of a topic (nor reply to it), but he can see all topics and even their content. Is there any solution to force the search functionnality to only deal with authorised combination forum/groups defined with Private Groups?

    – PARENT FORUM : maybe I’m wrong but the only way I’ve found to work with Private Groups is to define one parent forum (the father of all) and subforums. The point is I have no need of any parent forum. Is there anyway to keep all forums at the same level without define any parent forum?

    Thank you for any help or idea…

    mareva

Viewing 25 replies - 1 through 25 (of 33 total)
  • @robin-w

    Moderator

    can you let me know what your settings are

    Dashboard>settings>bbp private groups>

    forum visibility settings
    general settings

    @cracoucas

    Participant

    Hi
    Thank you for taking my rouble into account!

    My settings are :
    – Forum visibility : not activated (anything is checked in this tab). Please note that I tried to activate the forum visibility but it didn’t change anything.
    – General settings :
    >> Hide topic and reply counts : yes (checked)
    >> Show forum content (Descriptions) on main index : yes (checked)
    >> Remove Private prefix : : yes (checked)

    “My” 2 forums are defined as “private” forums.

    @robin-w

    Moderator

    ok, thanks, I’ll take a look.

    @robin-w

    Moderator

    Strange the things you don’t put in your testing – a top level forum was one I didn’t test! 🙂

    I’ve now worked a fix for this, but before I release it, I just want to check back on the search issue.

    Search should hide both ‘private group’ topics and replies from search results as though they don’t exist, and this works in my test site.

    Can you confirm that this is still an issue? and which version of the plugin you are using?

    @cracoucas

    Participant

    Hi!

    I use the 1.7 version.

    Listen… When I red your last message, I began to make a clean installation of my bbPress forum with Private Groups plugin on a server (I developp on localhost) in order to give you an access and to make it easier for you to check what should be wrong with the plugin.
    At the beginning, everything seemed to work correctly (without any bug)!

    Then I changed the slug of my 2 forums (slug? I don’t know if it is the right word in english. I mean, the name that is directly used in the permalink).
    … and issues appeared!
    – When no top level forum is defined, any logged user can see all forums in the index (even if visibility option is not activated in Private groups). He can’t access to the “private” one but he see it.
    – Search don’t hide ‘private group’ topics and replies from search results.

    I tried to definitly delete the forums and create them again but it didn’t change anything…
    So what? … I don’t know!

    I will send you an email in a few minutes (I’ve found your address on your site) with further informations (access code to my site)

    Regards,
    mareva

    @robin-w

    Moderator

    Then I changed the slug of my 2 forums (slug? I don’t know if it is the right word in english. I mean, the name that is directly used in the permalink).
    … and issues appeared!

    ok, that will help me find the error – can you tell me what you changed and how eg I went into dashboard>xx>yy and changed aa to bb

    @cracoucas

    Participant

    Hi,

    I went into dashboard > forums > “Forum title A” and changed the slug “forum-title-a” into “forum-new-slug”
    With :
    – “Forum title A” = “Forum A – copropriétaires”
    – “forum-title-a” (slug) = “forum-a-coproprietaires”
    – “forum-new-slug” = “forum-copros”

    Then I did the same with the second forum.

    regards,
    m.

    @robin-w

    Moderator

    Interesting, and offhand I’m not quite sure why it would do that, but I’ll have a dig and come back

    @robin-w

    Moderator

    ok, I’ve created a new version 1.8 that should fix the top level forum, and done some other tidy-ups that may or may not affect your search.

    Can you try it again?

    @cracoucas

    Participant

    Hi!
    Thank you for the release.
    The top level forum issue is now fixed.
    Unfortunetly, there is no change about the search functionnality.

    When testing the new release :
    1- I deleted definitly forums and recreated new ones, with new names and new slugs. I kept existing groups (that were already defined in the plugin settings) and existing users settings. And, of course, I created new topics using various logged in users.
    Then I made some tests.
    2- I changed forums slugs and made some tests again : it seems to be ok (except for the search).

    I’m really embarrassing with the issue related to the not filtered search results list because I will be forced to disable search functionality in bbPress settings.

    Do you think it should be fixed or it is linked to my own configuration with no hope to repare it?

    Regards
    m.

    @robin-w

    Moderator

    ok, so it is changing forum slugs that creates an issue for search – yes?

    Is it key that you change the slug? – what are you trying to achieve by doing this?

    @cracoucas

    Participant

    Not at all!
    Sorry, my explainations weren’t so clear…
    The search issue appeared in all cases, even before I changed slugs.

    @robin-w

    Moderator

    good, I couldn’t fathom out why chnagingh a lsug would affect anything !

    Ok, that’s strange, it works fine on my test site, and just uses the same core functionality as the main functions.

    Not sure what to suggest next….let me have a think overnight !

    @cracoucas

    Participant

    In fact, it is not the only trouble I have with bbPress search.

    I’ve just found another one this afternoon choosing which widgets I should display in forum pages (forum index, topics, reply…):
    – I’ve installed the plugin “Display Widget” (https://wordpress.org/plugins/display-widgets/).
    – For widgets I want (or want not) to display on forum pages, I checked all Display Widget options related to forums in widgets areas.
    –> It works perfectly everywhere, except on the bbpress result pages, I mean in pages where the result list is displayed after using the bbPress search functionality.

    Then I wonder that the issue I told you about has really something to do with Private Groups.
    Maybe you just can’t do anything for me…

    regards
    m.

    @robin-w

    Moderator

    ok, think we need to eliminate any other factors

    Plugins

    Deactivate all but bbpress and private groups and see if this fixes. if it does, re-enable one at a time to see which is causing the error.

    Themes

    If plugins don’t pinpoint the problem, switch to a default theme such as twentytwelve, and see if this fixes.

    Come back and let me know !

    @cracoucas

    Participant

    Ok, I’ve just did it… without any result!

    1- I desactivated all plugin except bbPress and Private Groups : Result list is still displaying results of all forums, even topics coming from private forum.

    2- I switched to TwentyTwelve : it neither work.

    gnnnn!

    @robin-w

    Moderator

    hmm….

    Ok, if I give you a new file, are you able to FTP it to a location within wordpress – ie do you know how to ftp !

    @cracoucas

    Participant

    No problem to do that.
    Please just let me know what the file is about and in which wp directory it has to be set.

    @robin-w

    Moderator

    Ok, what I want to do is check if the function is trying to filter and failing or not even trying to filter.

    I am therefore going to get the plugin to dump one of the lists, so that you can tell me what it is showing – it won’t look pretty, but should help.

    First of all you need to work out a search that produces only a few results, say less than 10, and that you can list all the results that you would expect to see for full access, and that you want to see for the private groups, and make a not of their numbers.

    so for instance

    search for zebra produces posts numbers

    2345,2367,2657,2894,2965

    But one of these is in a private forum so a non-logged in user should see

    2345,2367,2894,2965

    Once you have this list, then do the following :
    Use notepad to create a file called search.php

    then put this code into it

    <?php
    
    //this function filters to the bbp search function to allow only returns from allowed forums
    
    function pg_has_search_results( $args = '' ) {
    	global $wp_rewrite;
    //start with code as per bbp search !
    	/** Defaults **************************************************************/
    
    	$default_post_type = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    
    	// Default query args
    	$default = array(
    		'post_type'           => $default_post_type,         // Forums, topics, and replies
    		'posts_per_page'      => bbp_get_replies_per_page(), // This many
    		'paged'               => bbp_get_paged(),            // On this page
    		'orderby'             => 'date',                     // Sorted by date
    		'order'               => 'DESC',                     // Most recent first
    		'ignore_sticky_posts' => true,                       // Stickies not supported
    		's'                   => bbp_get_search_terms(),     // This is a search
    	);
    
    	// What are the default allowed statuses (based on user caps)
    	if ( bbp_get_view_all() ) {
    
    		// Default view=all statuses
    		$post_statuses = array(
    			bbp_get_public_status_id(),
    			bbp_get_closed_status_id(),
    			bbp_get_spam_status_id(),
    			bbp_get_trash_status_id()
    		);
    
    		// Add support for private status
    		if ( current_user_can( 'read_private_topics' ) ) {
    			$post_statuses[] = bbp_get_private_status_id();
    		}
    
    		// Join post statuses together
    		$default['post_status'] = implode( ',', $post_statuses );
    
    	// Lean on the 'perm' query var value of 'readable' to provide statuses
    	} else {
    		$default['perm'] = 'readable';
    	}
    	
    	//PG then loop to find allowable forums
    	//Get an array of IDs which the current user has permissions to view
    	$allowed_posts = private_groups_get_permitted_post_ids(new WP_Query($default));
    	Echo 'Allowed posts list' ;
    	var_dump ($allowed_posts) ;
    	// The default forum query with allowed forum ids array added
        $default['post__in'] = $allowed_posts;
    
        
    	//then return to bbp search code
    	/** Setup *****************************************************************/
    
    	// Parse arguments against default values
    	$r = bbp_parse_args( $args, $default, 'has_search_results' );
    
    	// Get bbPress
    	$bbp = bbpress();
    
    	// Call the query
    	if ( ! empty( $r['s'] ) ) {
    		$bbp->search_query = new WP_Query( $r );
    	}
    
    	// Add pagination values to query object
    	$bbp->search_query->posts_per_page = $r['posts_per_page'];
    	$bbp->search_query->paged          = $r['paged'];
    
    	// Never home, regardless of what parse_query says
    	$bbp->search_query->is_home        = false;
    
    	// Only add pagination is query returned results
    	if ( ! empty( $bbp->search_query->found_posts ) && ! empty( $bbp->search_query->posts_per_page ) ) {
    
    		// Array of arguments to add after pagination links
    		$add_args = array();
    
    		// If pretty permalinks are enabled, make our pagination pretty
    		if ( $wp_rewrite->using_permalinks() ) {
    
    			// Shortcode territory
    			if ( is_page() || is_single() ) {
    				$base = trailingslashit( get_permalink() );
    
    			// Default search location
    			} else {
    				$base = trailingslashit( bbp_get_search_results_url() );
    			}
    
    			// Add pagination base
    			$base = $base . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
    
    		// Unpretty permalinks
    		} else {
    			$base = add_query_arg( 'paged', '%#%' );
    		}
    
    		// Add args
    		if ( bbp_get_view_all() ) {
    			$add_args['view'] = 'all';
    		}
    
    		// Add pagination to query object
    		$bbp->search_query->pagination_links = paginate_links(
    			apply_filters( 'bbp_search_results_pagination', array(
    				'base'      => $base,
    				'format'    => '',
    				'total'     => ceil( (int) $bbp->search_query->found_posts / (int) $r['posts_per_page'] ),
    				'current'   => (int) $bbp->search_query->paged,
    				'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
    				'next_text' => is_rtl() ? '&larr;' : '&rarr;',
    				'mid_size'  => 1,
    				'add_args'  => $add_args, 
    			) )
    		);
    
    		// Remove first page from pagination
    		if ( $wp_rewrite->using_permalinks() ) {
    			$bbp->search_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links );
    		} else {
    			$bbp->search_query->pagination_links = str_replace( '&paged=1', '', $bbp->search_query->pagination_links );
    		}
    	}
    	//finally filter to return
    	// Return object
    	return apply_filters( 'pg_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query );
    }
    
    add_filter ('bbp_has_search_results', 'pg_has_search_results') ; 

    Then go into FTP

    Then look in

    wp-content/plugins/bbp-private-groups/includes

    and you’ll see a file called

    wp-content/plugins/bbp-private-groups/includes/search.php

    Rename this file to searchold.php (as we’ll need it back later!)

    Then copy the search.php that you made above to this folder (wp-content/plugins/bbp-private-groups/includes).

    Then run your search.

    You should see a horrible list at the start, but this will be what should be the filtered list

    run this with full access and with restricted access (ie not logged in) and tell me what lists you get and of they are different.

    @cracoucas

    Participant

    Ok I’ll do that now.
    Please could you tell me before :
    – Should I desactive all plugins before (except bbPress and Private Groups before)?
    – Should I switch to Twenty Twelve theme again?
    – May I create topics I will test using any logged in user (as the admin user)?

    You wrote : “But one of these is in a private forum so a non-logged in user should see”
    Please note that my both forums are private ones, then no non-logged-in users are supposed to have an acces to any forum.
    – Forum A is to be used by Group 1 only.
    – Forum B is to used by Group 1 and Group 2.

    @cracoucas

    Participant

    It’s me again!

    Preparing some topics for the the test you ask me to do, I’ve found something strange :

    – When the search keyword is used in a topic that belongs to the most private forum (Forum A in my example : restricted to Group 1) but in any topic of the other forum (Forum B : restricted to Group 1 and 2), the search does not filter : the topic is displayed in results (search work out by a logged in user that belongs to the Group 2.
    That was the case of all my previous tests!

    – But when the search keyword is used in both topics that belongs to Forum A or Forum B, then the search function seems to filter correctly : the topic that belongs to Forum A does not appear in the result list.

    So… what shall I do?
    Shall I go on creating a new search.php file as you explained to me?

    Sorry to have been so long to find this “special behaviour”!

    @cracoucas

    Participant

    Sorry to have been so long to find this “special behaviour”!

    @robin-w

    Moderator

    No hold on and let me have a think and a look !

    @robin-w

    Moderator

    ok, I have just set up a test as follows :

    user1 access to group 1
    user2 access to group 2

    forum 1 assigned to group 1 visibility private parent:no parent
    forum 2 assigned to group 1 and group 2 visibility private parent:no parent

    dashboard>settings>private groups>

    visibility
    set to off (unchecked)
    all other options blank

    general settings
    all blank

    The I log on as user2 and search for a term I know is in both forums, and it only shows the results for forum 2.

    Then I log in as user1 and search for a term I know is in both forums, and it shows the results for forum 1 and forum 2.

    Then I log out, and serach again, and it show no results from either forum.

    Which bits of the above are different for you?

    @cracoucas

    Participant

    On my configuration, following settings are different than yours (others are similar):

    – dashboard>settings>private groups> General settings : all checked (please note that ” Hide topic and reply counts” option doesn’t change anything. But I don’t care).

    – search as non-logged in : I can’t test it because a non-logged in user is not able to see forums pages : the user has to log in before.

    ———————-
    Just to let you know:
    – search as user1 : ok (I get similar result)
    – search as user2 : ok (I get similar result).
    – Here is the point : if I log on as user2 and search for a term I know is only in forum 1, it shows the result but it should not.

Viewing 25 replies - 1 through 25 (of 33 total)
  • You must be logged in to reply to this topic.
Skip to toolbar