Skip to:
Content
Pages
Categories
Search
Top
Bottom

BP 1.5.1 – Users can’t view content of Private Groups Forums via the “Forums”- Page

  • @wiking

    Member

    When navigating to the “Discussion Forums” WordPress-Page (BP Groups Forum used) only WordPress Admins see the threads for Private Group Forums they are members in. Normal Users only see the threads from Public Groups, but not from Private Groups they are member in.

    Do I miss any settings to allow this or is this a bug in 1.5.1?

Viewing 13 replies - 1 through 13 (of 13 total)
  • @boonebgorges

    Keymaster

    This is expected behavior. The logic that would be required to show private forums to logged-in members of those groups is complex, and has not yet been implemented. There is a ticket in Trac to discuss this enhancement: https://buddypress.trac.wordpress.org/ticket/2576

    @wiking

    Member

    there is not to much activity on this ticket unfortunately.

    especially if private groups are heavily used it is hardly comprehensible for users that some threads appear, but others are not displayed. this was the feedback of my beta test users (i’am just in the process of launching a new community for gamers and some power users of my old page are testing my bp installation).

    If it is not possible to use the Group-Forums-Directory- is there any other Point where a user can view all new threads they are able to read?

    is it still that hard to implement the bugfix with the new 1.5 api?

    @wiking

    Member

    maybe interesting for other users with private groups heavily used:
    i modified the function “groups_add_forum_where_sql” starting at line 88 in /bp-groups/bp-groups-filters.php.
    I added the following block at line 110:
    elseif ( is_user_logged_in() )
    unset( $parts );
    therefore all logged in users get the same view as an admin and see updates in all private group forums (error message when clicking of threads they are not allowed to). next step would be to filter out group forums where the user has no permission.
    ==
    is there an function which could be used for that filtering in bp (replacing is_user_logged_in())?
    or is custom sql code needed here?

    @boonebgorges

    Keymaster

    Probably at least some custom SQL is needed. Something along the lines of:
    (1) doing an additional query to get a list of the user’s groups and the forum_ids for those groups
    (2) limiting the main forum topic query WHERE ( forum_id IN ( {$user_forums} ) OR group_status = ‘public’ ) (not sure if group_status is available here, I would have to look)

    > is it still that hard to implement the bugfix
    It’s not very difficult technically, but it will introduce at least one or two more queries on what can already be a database-intensive page load. If you can provide a workable patch, I’m sure it would be happily considered.

    @wiking

    Member

    i try to get it running and provide my version if it works.

    @wiking

    Member

    I still struggle to get this view running corectly.

    I managed to find out how to pull all group ID’s for a given userid:

    SELECT group_id FROM `xyz_bp_groups_members` where `user_id` = 1

    And how to get all forum_id’s for a given group:

    SELECT meta_value FROM `xyz_bp_groups_groupmeta` where group_id = 1 and meta_key = ‘forum_id’

    My idea was to do a join as i didn’t know how to follow your directions correctly @boonebgorges.
    Therefore i tried to modify the original $sql (line 83 in bp-group-filters.php):

    $sql .= ‘JOIN ‘ . $bp->groups->table_name . ‘ AS g LEFT JOIN ‘ . $bp->groups->table_name_groupmeta . ‘ AS gm ON g.id = gm.group_id ‘;

    with this extended version:

    $sql .= ‘JOIN ‘ . $bp->groups->table_name . ‘ AS g LEFT JOIN ‘ . $bp->groups->table_name_groupmeta . ‘ AS gm, oba_bp_groups_members AS gu ON g.id = gm.group_id AND gu.group_id = gm.group_id’;

    unfortunately i have not enough know-how how the buddypress-core is working correctly. Any hints on how to do this properly?

    Many Thanks!

    @sirup

    Member

    This problem is solved.
    In in “bp-groups-filters.php” in function “function groups_add_forum_where_sql( $sql = ” ) ” change the following (oba is the database prefix):

    Code:
    //Get current user
    $current_user = wp_get_current_user();

    //Fetch forums IDs to which user has access
    $i = 0;
    $result = mysql_query("SELECT meta_value FROM oba_bp_groups_members, oba_bp_groups_groupmeta WHERE user_id = ".$current_user->ID." and oba_bp_groups_members.group_id = oba_bp_groups_groupmeta.group_id and oba_bp_groups_groupmeta.meta_key=’forum_id’")
    or die ("MySQL-Error: " . mysql_error());
    while ( $row = mysql_fetch_array($result)) {
    $res[$i] = $row["meta_value"];
    $i++;
    }

    //Implode forum ids into a comma sperated list e.g: 3,5,7
    $comma_separated = implode(",", $res);

    // Set this for groups
    //Old //$parts[‘groups’] = "(gm.meta_key = ‘forum_id’ AND gm.meta_value = t.forum_id)";
    $parts[‘groups’] = "(gm.meta_key = ‘forum_id’ AND gm.meta_value = t.forum_id AND gm.meta_value IN (".$comma_separated."))";

    @wiking

    Member

    As there was a php error if the user who uses the forum directory is not logged in the following modification was done:

    Code:
    //Get current user
    $current_user = wp_get_current_user();

    //Fetch forums IDs to which user has access
    $i = 0;
    $result = mysql_query("SELECT meta_value FROM oba_bp_groups_members, oba_bp_groups_groupmeta WHERE user_id = ".$current_user->ID." and oba_bp_groups_members.group_id = oba_bp_groups_groupmeta.group_id and oba_bp_groups_groupmeta.meta_key=’forum_id’")
    or die ("MySQL-Error: " . mysql_error());
    while ( $row = mysql_fetch_array($result)) {
    $res[$i] = $row["meta_value"];
    $i++;
    }

    //Implode forum ids into a comma sperated list e.g: 3,5,7
    if ( !empty( $res ) )
    $comma_separated = implode(",", $res);

    // Set this for groups
    //Old //$parts[‘groups’] = "(gm.meta_key = ‘forum_id’ AND gm.meta_value = t.forum_id)";
    $parts[‘groups’] = "(gm.meta_key = ‘forum_id’ AND gm.meta_value = t.forum_id AND gm.meta_value IN (".$comma_separated."))";

    You also need to add the functionality that logged in users can potentially see all forums (the above code then filters out forums the user is not member of):

    after

    Code:
    // Are we a super admin?
    elseif ( is_super_admin() )
    unset( $parts[‘private’] );

    add

    Code:
    // Allow the forum directory to display private forums for users
    elseif ( is_user_logged_in() )
    unset( $parts[‘private’] );

    @djpaul

    Keymaster

    You should never, ever, edit core files.

    @wiking

    Member

    for sure – but the bug is open for 15 months ( https://buddypress.trac.wordpress.org/ticket/2576 ) and wasn’t fixed – and therefore i thought if you tidy the code up you could add it to core as a patch.

    @boonebgorges

    Keymaster

    I think that this is a decent candidate for a patch. Feel free to work it up as one and attach it to that ticket.

    @xsci

    Participant

    Greetings,

    Has a patch been created for this yet? I’m not the programmer and would love an easier way to update this.

    Cheers!

    Teresa

    @hnla

    Participant

    @xsci This is a year old thread and discusses an issue relating to BP 1.5.1;  BP is about to release version 1.7.

     

    Please open a new thread, describe the issues you are having and what versions of BP / WP  you are using and please test any issues you are having are not custom theme related by dropping back to the bp default theme

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘BP 1.5.1 – Users can’t view content of Private Groups Forums via the “Forums”- Page’ is closed to new replies.
Skip to toolbar