Skip to:
Content

bbPress.org

Opened 4 weeks ago

Last modified 4 weeks ago

#3608 assigned defect (bug)

Hidden forums search exclusion affects single group forum query for logged-out users

Reported by: r-a-y's profile r-a-y Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.6.12 Priority: normal
Severity: normal Version: 2.6.11
Component: Component - Forums Keywords: dev-feedback
Cc:

Description

In r7262, a change was made to prevent hidden forums from appearing in search results.

However, the change affects all single forum queries as well. If I am a logged-out user and viewing a single forum, the following DB query is made:

SELECT wp_posts.*
	FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
	WHERE 1=1 AND wp_posts.ID = FORUM_ID AND (
		( wp_postmeta.meta_key = '_bbp_forum_id' AND CAST(wp_postmeta.meta_value AS SIGNED) NOT IN (FORUM ID COMMA-DELIMITED LIST OF PRIVATE AND HIDDEN FORUMS) )
) AND wp_posts.post_type = 'forum' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'hidden' OR wp_posts.post_status = 'private'))
		GROUP BY wp_posts.ID
		ORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC

The NOT IN query is via bbp_exclude_forum_ids() and isn't necessary when you're on a single forum. If a user is on a single forum, we've already determined that this is the correct forum ID so we do not need this exclusion query.

Moreover, the NOT IN query only works for the reply and topic post types as the _bbp_forum_id postmeta for the forum post type is actually used to store the parent forum ID, not the forum ID. If we are doing a forum post type query and want to omit hidden forums from the query, the forum exclusion query must be done against the ID column.

This affects bbPress v2.6.11, but there currently isn't a 2.6.11 version on Trac, so I've set it to 2.6.9 for now.

I think there are two things that need to be addressed. First one is to only allow the forums clause if not on a single forum page. Second thing is if a forum post type exclusion query needs to be done, it needs to be done on the ID DB column and not as a _bbp_forum_id postmeta query. Unfortunately, WP_Query doesn't have a relation parameter outside of meta queries: https://wordpress.stackexchange.com/a/379405 , so a filter would need to run on the post_where hook to accomplish this or two separate queries would need to be made.

Change History (2)

#1 @r-a-y
4 weeks ago

Second thing is if a forum post type exclusion query needs to be done, it needs to be done on the ID DB column and not as a _bbp_forum_id postmeta query. Unfortunately, WP_Query doesn't have a relation parameter outside of meta queries: https://wordpress.stackexchange.com/a/379405 , so a filter would need to run on the post_where hook to accomplish this or two separate queries would need to be made.

For this, I specifically mean this part of bbp_pre_get_posts_normalize_forum_visibility(). I think this part only needs to be done for the reply and topic post types, not the forum post type. Ignore the WP_Query relation portion that I wrote as the forums clause above should cover this.

#2 @johnjamesjacoby
4 weeks ago

  • Milestone changed from Awaiting Review to 2.6.12
  • Owner set to johnjamesjacoby
  • Status changed from new to assigned
  • Version changed from 2.6.9 to 2.6.11
Note: See TracTickets for help on using tickets.