mlwilkerson (@mlwilkerson)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • @mlwilkerson

    Participant

    After doing some more work on this, I think that while the visibility of my topic in the subforum is indeed broken after the Subforum’s ID is placed in the _bbp_hidden_forums option, that is only a symptom and not a cause.

    I think that the fundamental assumptions of this version of bbPress/BuddyPress preclude the use of Subforums. And evidence of this is that visibility sensitive areas of the code like this just come up with the wrong answer when subforums are involved.

    So for me, I think I’m going to stop trying to make subforums work until the core code changes to better support them.

    @mlwilkerson

    Participant

    I’m seeing the same thing as originally reported by @mfiguerasma.

    I first noticed it when my non-admin user (TestUser) *suddenly* could no longer see a topic that he had formerly been able to see. In my case, I am using sub-forums. (See: https://bbpress.trac.wordpress.org/ticket/2191#comment:17 )

    I have a BP Group called GroupH.
    The group forum root is a type=category group called “Group Forums”
    Subforum1-GroupH is under the forum “GroupH”.

    GroupH is the group forum, i.e the one you see in a the drop-down in the settings where you select which forum is associated with the BP Group.

    So, it’s:

    Group Forums
    GroupH
    Subforum1-GroupH
    Topic1-Subforum1-GroupH

    All of the forums and subforums have a Visibility setting of Private (in the admin settings screens).

    So Topic1-Subforum1-GroupH was accessible by my TestUser one minute and then wasn’t the next minute. I knew that I hadn’t changed the visibility settings on my forums or anything else, but I realized that what I had done (thinking it was merely “for good measure”) was to run:
    Tools->bbPress->Recalculate private and hidden forums

    I recreated my original scenario, verified that TestUser could access Topic1-Subforum1-GroupH, and then used Updraft to take snapshots of my database before running “Recalculate private and hidden forums” calculate again. Sure enough, after that “repair”, it was broken again.

    So I debugged it. This repair tool kicks off bbp_repair_forum_visibility() which updates two options in the options table:
    _bbp_private_forums
    _bbp_hidden_forums

    These are pre-calculated, cached, lists of forums.

    If the forum_id for GroupH appears in _bbp_hidden_forums, then TestUser won’t be able to access Topic1-Subforum1-GroupH. Before running this “repair”, the forum_id for GroupH does not appear in that list. After the repair it does.

    So, how is the forum_id for GroupH getting into this list of hidden forums when the post_status on the forum is most definitely private? (Verified by looking at its row in the posts table)

    It’s getting there precisely by the means @mfiguerasma showed.

    When the query is being run to get a list of all “hidden” forums, in order to create _bbp_hidden_forums, it invokes the pre_get_posts filter. bbPress uses that filter bbp_pre_get_posts_normalize_forum_visibility() to change the query_vars.

    Notice what’s happening here:

    (1) The WP_Query is saying “I am trying to find a list of *hidden* forums” (I have my own reasons for why I want a list of hidden forums.)

    (2) But bbp_pre_get_posts_normalize_forum_visibility() seems to be second-guessing. I receives query_vars with post_type=hidden, but then the way its logic works is to say: “What are various post statuses that this user has permission to see. Ah, this user can see both hidden and private ones, so I’ll update the query_vars to include post_types of both hidden and private.”

    I think the logic of bbp_pre_get_posts_normalize_forum_visibility() is exactly backwards. It’s trying to include all of the post_types that the user can access. But that’s not why it has been invoked. It’s been invoked in the process of simply creating a list of hidden forums for _bbp_hidden_forums and its messing that up by including the private post_status.

    (3) So what the WP_Query gets back is a list of forum_ids for all hidden *and private* groups. And that’s the list that ultimately gets stored in _bbp_hidden_forums.

    So this “repair” actually breaks my forums.

    If you simply remove this bbPress filter before doing the repair, it seems to produce the correct result. My TestUser can access Topic1-Subforum1-GroupH both before and after the repair when we remove the filter:
    remove_action(‘pre_get_posts’,’bbp_pre_get_posts_normalize_forum_visibility’,4);

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