Skip to:
Content

bbPress.org

Opened 11 years ago

Closed 11 years ago

#2512 closed defect (bug) (fixed)

bbp_admin_repair_forum_visibility repair tool breaks private and hidden forum visibility

Reported by: netweb's profile netweb Owned by: netweb's profile netweb
Milestone: 2.6 Priority: normal
Severity: major Version: 2.5
Component: Tools Keywords:
Cc:

Description

Running the bbp_admin_repair_forum_visibility repair tool breaks forum visibility.

Each private and hidden forum are assigned both _bbp_hidden_forums and _bbp_hidden_forums statuses.

Repro:

  • Create a hidden forum (post_id = 95887)
  • Create a private forum (post_id = 95889)
  • Run bbp_admin_repair_forum_visibility repair tool

Postmeta Actual Results:

_bbp_hidden_forums a:2:{i:0;s:5:"95889";i:1;s:5:"95887";} yes
_bbp_private_forums a:2:{i:0;s:5:"95889";i:1;s:5:"95887";} yes

Postmeta Expected Results:

_bbp_hidden_forums a:1:{i:1;s:5:"95887";} yes
_bbp_private_forums a:1:{i:0;s:5:"95889";} yes

The repair tool bbp_admin_repair_forum_visibility (/includes/forums/functions.php#L927) runs the follow two WP_Query queries:

        $private_forums = new WP_Query( array(
                'suppress_filters' => true,
                'nopaging'         => true,
                'post_type'        => bbp_get_forum_post_type(),
                'post_status'      => bbp_get_private_status_id(),
                'fields'           => 'ids',
                'cache_results'    => false
        ) );
        $hidden_forums = new WP_Query( array(
                'suppress_filters' => true,
                'nopaging'         => true,
                'post_type'        => bbp_get_forum_post_type(),
                'post_status'      => bbp_get_hidden_status_id(),
                'fields'           => 'ids'
        ) );

For which the query result for $private_forums is:

WP_Query Object
(
    [query] => Array
        (
            [suppress_filters] => 1
            [nopaging] => 1
            [post_type] => forum
            [post_status] => private
            [fields] => ids
            [cache_results] => 
        )

    [query_vars] => Array
        (
            [suppress_filters] => 1
            [nopaging] => 1
            [post_type] => forum
            [post_status] => Array
                (
                    [0] => private
                    [2] => hidden
                )

            [fields] => ids
SELECT wp_posts.ID 
FROM wp_posts  
WHERE 1=1  
AND wp_posts.post_type = 'forum' 
AND (wp_posts.post_status = 'hidden' OR wp_posts.post_status = 'private')  
ORDER BY wp_posts.post_date DESC 

For which the query result for $hidden_forums is:

WP_Query Object
(
    [query] => Array
        (
            [suppress_filters] => 1
            [nopaging] => 1
            [post_type] => forum
            [post_status] => hidden
            [fields] => ids
        )

    [query_vars] => Array
        (
            [suppress_filters] => 1
            [nopaging] => 1
            [post_type] => forum
            [post_status] => Array
                (
                    [0] => hidden
                    [1] => private
                )

            [fields] => ids
SELECT wp_posts.ID 
FROM wp_posts  
WHERE 1=1  
AND wp_posts.post_type = 'forum' 
AND (wp_posts.post_status = 'hidden' OR wp_posts.post_status = 'private')  
ORDER BY wp_posts.post_date DESC 

Thus when update_option is executed both private and hidden forums BOTH get assigned a _bbp_private_forums and _bbp_hidden_forums value in wp_postmeta

Workaround:

  • Don't run the bbp_admin_repair_forum_visibility repair tool

Via the backend forum edit admin:

  • Change the forum visibility from eg. private to public and save
  • Change the forum visibility back to the original private status and save

Attachments (1)

2512.01.diff (1.1 KB) - added by thebrandonallen 11 years ago.

Download all attachments as: .zip

Change History (8)

#1 @netweb
11 years ago

Oops, second line above should read:

Each private and hidden forum are assigned both _bbp_private_forums and _bbp_hidden_forums statuses.

#2 @johnjamesjacoby
11 years ago

Gut tells me there's a filter adding the additional post statuses in that needs to be unhooked. Though, wonder why it's not obeying suppress_filters.

Last edited 11 years ago by johnjamesjacoby (previous) (diff)

#3 follow-up: @thebrandonallen
11 years ago

This appears to be related to bbp_pre_get_posts_normalize_forum_visibility() added with pre_get_posts
https://bbpress.trac.wordpress.org/browser/trunk/includes/core/actions.php#L152

Since, pre_get_posts is an action, suppress_filters has no effect. Attached patch should fix the issue.

#4 @johnjamesjacoby
11 years ago

  • Component changed from Forums to Tools
  • Keywords commit added; needs-patch removed
  • Milestone changed from Awaiting Review to 2.6
  • Severity changed from normal to major

Perfect. Run it.

#5 in reply to: ↑ 3 @netweb
11 years ago

  • Component changed from Tools to Forums
  • Keywords has-patch added; commit removed
  • Milestone changed from 2.6 to Awaiting Review
  • Severity changed from major to normal

Replying to thebrandonallen:

This appears to be related to bbp_pre_get_posts_normalize_forum_visibility() added with pre_get_posts. Since, pre_get_posts is an action, suppress_filters has no effect. Attached patch should fix the issue.

Yep, that's it. Thanks for the patch, works perfectly.

#6 @netweb
11 years ago

  • Component changed from Forums to Tools
  • Keywords has-patch removed
  • Milestone changed from Awaiting Review to 2.6
  • Severity changed from normal to major

Trac used to notify you that someone else had updated the ticket before you submit your comment, weird''

#7 @netweb
11 years ago

  • Owner set to netweb
  • Resolution set to fixed
  • Status changed from new to closed

In 5257:

Remove pre_get_posts action bbp_pre_get_posts_normalize_forum_visibility from forum visibility repair tool to prevent hidden and private post status injected into WP_Query. Props thebrandonallen. Fixes #2512

Note: See TracTickets for help on using tickets.