Skip to:
Content
Pages
Categories
Search
Top
Bottom

Conflict between bbpress and wp-members


  • stuartataltitude
    Participant

    @stuartataltitude

    I am using wp-members and bbpress together (I guess there are many sites that do this). The normal bbpress behaviour is for non-logged-in site visitors to be able to view forum topics but not reply to them. If I deactivate the wp-Members plugin then this is what happens. However, with wp-members activated, site visitors cannot see topic content (though they can see replies to a topic).

    Maybe there is a setting somewhere that I am missing but I’d like the default bbpress behaviour to continue to work with wp-Members activated. I’m hoping that there are other sites that have experienced the same issue – maybe someone has found a solution?

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

  • stuartataltitude
    Participant

    @stuartataltitude

    I have tracked through to bbp_replies(). bbpress()->reply_query->have_posts() seems to give different results when logged in and logged out (iff WP-Members is active).
    When logged in, if a topic has 1 original post and 1 reply, this returns 1 first time, then 1 second time (for the reply) then “” (for no more). When logged out it only returns 1 (for the reply to the original post) then “”. So at first sight it seems to be something to do with querying the database (as opposed to posts being filtered out later for example).

    I know it is perhaps more something for the WP-Members plugin to look at (as they have broken your plugin and not vice versa) but if you have any ideas what might be going on – so I can point them in a direction for what to look for, that would be great. Must be lots of sites that are using both WP-Members and bbpress together – but maybe most don’t want visitors seeing forums and so haven’t hit this issue.


    stuartataltitude
    Participant

    @stuartataltitude

    I tracked the problem down to the WP Members plugin function do_hide_posts. This calls
    $query->set( ‘post__not_in’, **array of hidden post ids** ). The intention (I think) is just to filter out hidden posts but for some reason this call (which only contains a list of hidden page Ids – not any bbpress topic or reply ids) causes all topic and reply ids to be stripped from the query’s Results.

    For the record (in case others have the same problem), I have now added the following to my functions.php in my child theme…

    add_action( ‘wpmem_after_init’ , ‘kmc_wpmem_after_init’);
    function kmc_wpmem_after_init() {
    global $
    remove_action( ‘pre_get_posts’, array( $wpmem, ‘do_hide_posts’ ) );
    add_action( ‘pre_get_posts’, ‘kmc_hide_posts’ );
    }
    function kmc_hide_posts( $query ) {
    global $wpmem;
    $index = 0;
    $hidden = array();
    $hidden_posts = $wpmem->get_hidden_posts();
    // Remove hidden pages from the list of posts to be ignored
    foreach($hidden_posts as $post_id){
    $post = get_post($post_id);
    $postType = get_post_type_object(get_post_type($post));
    if ($postType->labels->singular_name != “Page”) {
    $hidden[$index] = $post_id;
    $index++;
    }
    }
    if ( ! empty( $hidden ) ) {
    $query->set( ‘post__not_in’, $hidden );
    }
    return $query;
    }

    I still don’t understand why $query->set( ‘post__not_in’, **an array of 15 hidden page ids**) causes all topics and replies to be stripped from the output, but the above change solves my problem for now.


    Robin W
    Moderator

    @robin-w

    I suspect that this function is ‘overwriting’ a ‘post__in’ function. WP_query can have a post__in OR a post__not_in, not both, so setting post__not_in may take out a post__in set within bbpress.

    Just a guess, but would make sense. You fix looks sensible, and thanks for posting

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