Skip to:
Content

bbPress.org

Opened 7 years ago

Last modified 3 years ago

#2191 new enhancement

BuddyPress Group Subforums created in bbPress are incomplete

Reported by: moebis Owned by: johnjamesjacoby
Milestone: 2.7 Priority: high
Severity: normal Version: trunk
Component: Extend - BuddyPress Keywords: needs-patch needs-unit-tests
Cc: moebis@…, mercijavier@…, info@…

Description

Using latest trunk of both bbpresss/buddypress. Create a "group1" in buddypress, with corresponding forum. Then go into wp-admin and create subgroup of "group1" in bbpress admin, let's call it "subgroup1". Now go back to the front end and click on the group1 and look at the forums. Only content and listings from the subgroup1 appear, as if group1 disappeared completely. NOTE: Ticket originally posted on buddypress and requested to be moved here. orig. ticket: http://buddypress.trac.wordpress.org/ticket/4797

Attachments (7)

Screen Shot 2013-01-31 at 4.03.05 PM.png (190.0 KB) - added by moebis 7 years ago.
shows subgroup1 listings (notice 2 topics) but no parent group/forum listings
Screen Shot 2013-01-31 at 10.13.52 PM.png (121.2 KB) - added by moebis 7 years ago.
forum and sub forum looks in groups
Screen Shot 2013-01-31 at 10.14.03 PM.png (101.5 KB) - added by moebis 7 years ago.
drop down selection on topic posts in groups
current-trunk-no-edit.png (77.1 KB) - added by moebis 7 years ago.
current-trunk-removed-lines-607-608.png (87.5 KB) - added by moebis 7 years ago.
current-trunk-mock-up.png (90.1 KB) - added by moebis 7 years ago.
current-trunk-drop-down-example.png (80.9 KB) - added by moebis 7 years ago.

Download all attachments as: .zip

Change History (31)

@moebis
7 years ago

shows subgroup1 listings (notice 2 topics) but no parent group/forum listings

#1 @moebis
7 years ago

  • Cc moebis@… added

@moebis
7 years ago

forum and sub forum looks in groups

@moebis
7 years ago

drop down selection on topic posts in groups

#2 @moebis
7 years ago

Possible fix:

EDIT: /bbpress/includes/extend/buddypress/group.php

Delete lines 609-614 and add “?>” back to line 609.

(see new attachments for how patch looks after it's enabled)

#3 @moebis
7 years ago

  • Type changed from defect to enhancement

#4 @johnjamesjacoby
7 years ago

(In [4746]) Remove deprecated subforum prevention code. Though it's not directly supported, preventing it isn't necessary either. See #2191.

#5 @johnjamesjacoby
7 years ago

(In [4747]) Remove invalid @uses for subforum count. See #2191.

#6 @johnjamesjacoby
7 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from major to normal
  • Summary changed from subgroups created in bbpress cause display issue in buddypress to BuddyPress Group Subforums created in bbPress are incomplete

So, about this...

Group Subforums don't have a way to know they are literally "group forums" and as such, when clicked, will just look like regular old forums. I've "fixed" the original issue that you brought up, but I am positive there will be several others, as this arrangement technically just isn't supported.

To go much further than this will take significant time and effort, beyond the 2.3 scope. It's not a bug, but it's not finished either. It works well enough to be workable and shippable.

Renaming the ticket, and putting into Future Release.

#7 @moebis
7 years ago

@johnjamesjacoby - thank you so much. I think its great how responsive you and the team have been with this. I really think having this hook in there to build on in the future is going to be really big for the community. I know it's not "completely" tied into the groups, however, it now allows building the forum hierarchy and structure in bbpress which is already well suited for this sub forum functionality. Now we can build our buddypress groups, and at least show the sub forums underneath the forum tab in groups. Not feature complete... true, but it really goes a long way to providing a much needed nesting option in buddypress group forums (which really in now bbpress forums). Again, I appreciate all of the hard work the community has put into this, especially you, and I want to contribute wherever I can, especially with testing and financial contributions if needed from revenue generated within the sites I apply these plugins to.

#8 @moebis
7 years ago

It went back to showing the forums in groups the old way, which is to say it only shows the last forum/sub forum in the chain. So you only see the sub forums and not the main group forum. Also the forum selection on the post went back to the old way too. I removed line 607 and 608 in the latest trunk:

607 bbpress()->current_forum_id = $forum->ID;

608 bbp_set_query_name( 'bbp_single_forum' );

And now I can see all the topic posts in the parent forum and sub forums and now also other non related groups parent forums. The forum selection in topic post also came back when I removed those lines, but the drop down list shows all forums in the tree, instead of just the ones related to the group. I attached some new screenshots showing how it behaves/looks, along with a mockup of expected behavior.

#9 @freiwerk
6 years ago

Hi there,

I am using a buddypress with subforums too for one of my projects. I'have noticed that the subforums-functionality is incomplete, but most of the things works. In fact, my users do not want to miss this feature.

However, there is one things that does not work: Subforum posts are
a.) not shown in the group's activity stream, as the system does not see that they belong to a group
b.) are shown in the sitewide activity stream, as they are considered as public

As my users love this feature, I decided to fix it by myself. In fact, the problem is a routine in /bbpress/includes/extend/buddypress/activity.php

I have placed this workaround in

		// if recored activity is a subforum activity, we need to manipulate it to register as group acitvity
		
		// check if there is parent forum and which group it belongs to (subforum-check)
		$current_parent_forum_id = bbp_get_forum_parent_id($args['secondary_item_id']);
		$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
		
		// if no group_id is found lets try one forum level higher (sub-sub-forum check)
		if (empty($group_id)) {
			$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
		}
	 
		// if we found that the parent forum belongs to a group, register the activity as group activity
		if (!empty($group_id)) {
			$args['component'] = "groups";
			$args['item_id'] = $group_id;
			$args['secondary_item_id'] = $group_id;
			// if group is not public, hide the activity sitewide
			if (bp_get_group_public_status($group_id) == 'Private') {
				$args['hide_sitewide'] = true;
			}
			// update group last activity
			groups_update_last_activity( $group_id);
		}

right after

	private function record_activity( $args = array() ) {

There is only one litte remark I have: The result of the function bp_get_group_public_status($group_id) gives me a (translated) string. So this code does no work for other languages than English. I was not able to fetch this data in a different way...

I would love if you would include it into the bbpress code (or some prettier code), as with this tweak the subforums are quite useable although its beta status and a rework of the subforums issue is not planned right now.

What do you think? Any chance.

By the way thanks for your great work here, i really love bbpress.

Last edited 6 years ago by freiwerk (previous) (diff)

#10 follow-up: @freiwerk
6 years ago

small update of my code:

  • included registering of group last update time
  • fixed the group status (private/hidden/public) fetching for setting sitewide flag

@developers:
any updates from you guy for including a improved fix in the code?

		// if recored activity is a subforum activity, we need to manipulate it to register as group acitvity
		
		// check if there is parent forum and which group it belongs to (subforum-check)
		$current_parent_forum_id = bbp_get_forum_parent_id($args['secondary_item_id']);
		$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
		if ( !empty( $current_parent_forum_id ) ) {
			bbp_update_forum_last_active_time($current_parent_forum_id);
		}
		// if no group_id is found lets try one forum level higher (sub-sub-forum check)
		if (empty($group_id)) {
			$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}
		}
		
		// try if there is one more level higher (group-forums forum) and update it
		$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}		
	 
		// if we found that the parent forum belongs to a group, register the activity as group activity
		if (!empty($group_id)) {
			$args['component'] = "groups";
			$args['item_id'] = $group_id;
			$mygroup = groups_get_group( array( 'group_id' => $group_id ) );
			
			// if group is not public, hide the activity sitewide
			if ($mygroup->status == 'public') {
				$args['hide_sitewide'] = false;
			} else {
				$args['hide_sitewide'] = true;
			}
			// update group last activity
			groups_update_last_activity( $group_id);
		}

#11 in reply to: ↑ 10 @xplusboy
5 years ago

Replying to freiwerk:

small update of my code:

  • included registering of group last update time
  • fixed the group status (private/hidden/public) fetching for setting sitewide flag

@developers:
any updates from you guy for including a improved fix in the code?

		// if recored activity is a subforum activity, we need to manipulate it to register as group acitvity
		
		// check if there is parent forum and which group it belongs to (subforum-check)
		$current_parent_forum_id = bbp_get_forum_parent_id($args['secondary_item_id']);
		$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
		if ( !empty( $current_parent_forum_id ) ) {
			bbp_update_forum_last_active_time($current_parent_forum_id);
		}
		// if no group_id is found lets try one forum level higher (sub-sub-forum check)
		if (empty($group_id)) {
			$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ))[0];
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}
		}
		
		// try if there is one more level higher (group-forums forum) and update it
		$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}		
	 
		// if we found that the parent forum belongs to a group, register the activity as group activity
		if (!empty($group_id)) {
			$args['component'] = "groups";
			$args['item_id'] = $group_id;
			$mygroup = groups_get_group( array( 'group_id' => $group_id ) );
			
			// if group is not public, hide the activity sitewide
			if ($mygroup->status == 'public') {
				$args['hide_sitewide'] = false;
			} else {
				$args['hide_sitewide'] = true;
			}
			// update group last activity
			groups_update_last_activity( $group_id);
		}

its worked good for me with small changhes in your codes :

// check if there is parent forum and which group it belongs to (subforum-check)
		$current_parent_forum_id = bbp_get_forum_parent_id($args['secondary_item_id']);
		$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ));
		$group_id = $group_id[0];
		if ( !empty( $current_parent_forum_id ) ) {
			bbp_update_forum_last_active_time($current_parent_forum_id);
		}
		// if no group_id is found lets try one forum level higher (sub-sub-forum check)
		if (empty($group_id)) {
			$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			$group_id = array_values(bbp_get_forum_group_ids( $current_parent_forum_id ));
			$group_id = $group_id[0];
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}
		}
		
		// try if there is one more level higher (group-forums forum) and update it
		$current_parent_forum_id = bbp_get_forum_parent_id( $current_parent_forum_id );
			if ( !empty( $current_parent_forum_id ) ) {
				bbp_update_forum_last_active_time($current_parent_forum_id);
			}		
	 
		// if we found that the parent forum belongs to a group, register the activity as group activity
		if (!empty($group_id)) {
			$args['component'] = "groups";
			$args['item_id'] = $group_id;
			$mygroup = groups_get_group( array( 'group_id' => $group_id ) );
			
			// if group is not public, hide the activity sitewide
			if ($mygroup->status == 'public') {
				$args['hide_sitewide'] = false;
			} else {
				$args['hide_sitewide'] = true;
			}
			// update group last activity
			groups_update_last_activity( $group_id);
		}

#12 @mercime
5 years ago

  • Cc mercijavier@… added

This ticket was mentioned in Slack in #bbpress by netweb. View the logs.


5 years ago

#14 @wph4
4 years ago

Hi,

I got here when searching for the possibilities of having multiple forums for one group OR subgroups (each one with its own forum).

I have read the article but do not get how can I get it done with my installation. I guess I am not tech enough to understand it all. Although it is still marker as incomplete some people are alreadyusing it... looks like to me...

Can someone give me some light here?

Thanks a lot!

This ticket was mentioned in Slack in #buddypress by netweb. View the logs.


4 years ago

#16 @mlwilkerson
3 years ago

Hi @wph4 , I'm in the same situation. I just posted a lengthy write-up of the scenarios I slogged through and the results of what is (mostly) working for me at this point. See here:
https://buddypress.org/support/topic/group-with-multiple-forums/#post-257734

#17 @mlwilkerson
3 years ago

And here's the code I wrote to make sure that when any activity happens in a sub-forum of a group's forum, the following occur:

  1. the last activity time is updated for that sub-forum, and for every parent forum, all the way up the hierarchy, regardless of how deep that hierarchy may be.
  1. the last activity time is updated for the associated BuddyPress Group
  1. the bp_activity is generated, appropriately tied to the group, so that users can see the activity in their BuddyPress activity streams (this results ends up being a happy side effect of getting the rest of it right).

The code above seems to require hacking the bbPress plugin code, but it turns out that there's a filter that can be added, such as in your theme's functions.php, that simply returns the associated group object. If bbPress knows the right group object (as a result of implementing this filter), it can do the right thing, accomplishing all of the above.

The filter code:

function mw_filter_bp_get_current_group($given_group){
	$group_object = $given_group;
	$post = get_post();

	switch($post->post_type){
		case 'topic':
			$current_forum_id = $post->post_parent;
			break;
		case 'forum':
			$current_forum_id = $post->ID;
			break;
		case 'reply':
			$current_topic_id = $post->post_parent;
			$current_forum_post = get_post($current_topic_id);
			$current_forum_id = $current_forum_post->ID;
			break;
		default:
			$current_forum_id = 0;
	}
	if( $current_forum_id) {
		// initialize a few things
		$group_id = 0;
		$found_group_forum = false;
		$reached_the_top = false;

		// This loop works our way up to the top of the topic->sub-forum->parent-forum hierarchy.
		// We will stop climbing when we find a forum_id that is also the id of a group's forum.
		//     When we find that, we've found the group, and we can stop looking.
		// Or if we get to the top of the hierarchy, we'll bail out of the loop, never having found a forum
		// that is associated with a group.
		while(!$found_group_forum && !$reached_the_top){
			$forum_group_ids = bbp_get_forum_group_ids( $current_forum_id );
			if(!empty($forum_group_ids)){
				// We've found the forum_id that corresponds to the group's forum
				$found_group_forum = true;
				$group_id = $forum_group_ids[0];
			}
			else{
				$current_post = get_post($current_forum_id);
				if($current_post->post_parent) {
					// $post->post_parent will be the ID of the parent, not an object
					$current_forum_id = $current_post->post_parent;
				}
				else{
					// We've reached the top of the hierarchy
					$reached_the_top = true;
				}
			}
		}

		if($group_id){
			$group_object = new BP_Groups_Group($group_id);
		}
	}
	return $group_object;
}
add_filter('groups_get_current_group','mw_filter_bp_get_current_group',10,1);

#18 @mlwilkerson
3 years ago

I've decided that even with my additional code above, Subforums are still incomplete. The code above ensures that: IF you can get the subforums to work and be accessible by non-admin users, THEN the activities in that subforum will properly appear in the group's activity stream, will update the last update times, and so forth.

The problem is that the assumptions built in to the current implementation will eventually break the accessibility of the subforum. See my post here where I initial discovered this:
https://bbpress.org/forums/topic/empty-topics-started-and-replies-created-hides-private-forums-data/#post-177193

Private and hidden forums are eventually cached in the WP options _bbp_hidden_forums and _bbp_private_forums. This happens, for example, when you run Tools->bbPress->Recalculate private and hidden forums.

There are a few places in the core code that forcibly assert the expectation that there is only one forum per group. And while subforums are technically not additional forums at the top-level, the same code that limits us to one forum per group is also affecting the subforum case as well.

For example, in bbpress/includes/extend/buddypress/groups.php you have:

		// Forum data
		$forum_action = bp_action_variable( $offset );
		$forum_ids    = bbp_get_group_forum_ids( bp_get_current_group_id() );
		$forum_id     = array_shift( $forum_ids );

Even though the data model supports multiple group_forum_ids, the array_shift results in taking the first one.

When this code executes in the case of view a topic in a subforum, the effect is that $forum_id ends up being set to the parent forum's ID, which is then assigned to the current_forum_id a couple of lines below:

		// Set the global forum ID
		$bbp->current_forum_id = $forum_id;

This is the value that ends up in the SQL WHERE clause in get_posts() when querying for the topic, constraining the parent_post attribute.

For example, suppose you have the following forums defined for GroupX:

GroupX (id: 25)
Subforum1 (id: 26)
Topic1-Subforum1 (id: 27)

If you then try to load Topic1-Subforum1, bbp_get_group_forum_ids( bp_get_current_group_id() ) will retrieve the group_forum_id of 25 (GroupX), and will pass that through the query_vars as post_parent=25, which will end up in the SQL query that attempts to retrieve the topic.

But of course, the actual parent_post of the topic is 26 (Subforum1), not 25 (GroupX). So when you query for a topic with the name 'Topic1-Subforum1' where parent_post = 25, you get zero results.

I'm currently out of ideas for how to hack this. So I think I'm now finally going to abandon making subforums work until support for it is completed.

#19 @thebrandonallen
3 years ago

  • Keywords needs-unit-tests added

@mlwilkerson

Thank you very much for the in depth analysis!

In order to get this fixed, we need unit tests. Since you've already done a lot of research on this, if you know how to write unit tests, and are willing to write some (even though they will fail) this would be a huge help.

If unit tests aren't in your wheelhouse or time constraints, the information you've posted here will give us a great starting point.

#21 @mlwilkerson
3 years ago

@thebrandonallen in a former life, in other development frameworks, I've written tons of unit tests. So I'm glad to do that here. I haven't yet created unit tests in this framework, though I need to start doing that soon for my own plugin development, so this is a good nudge. Could you link me to a starting point for creating what you need?

I've noticed the PHP Unit stuff for WordPress core testing here, and I see an example of a test on a BuddyPress specific plugin here. Is there a similar bbpress unit test class that I should be extending similar to the BuddyPress example?

#22 @thebrandonallen
3 years ago

Ugh! I was forgetting the fact that this touches BP as well. Unfortunately, there may be some issues with our BuddyPress testing bootstrap. You'll need this fixed before you can write the tests. I'll try to get in touch with @netweb a little later, and see if we can get the bootstrap ironed out (#2782).

We do have our own test class. Just like WP has WP_UnitTestCase and BP has BP_UnitTestCase we have BBP_UnitTestCase.

There is also https://codex.buddypress.org/developer/automated-testing/writing-automated-tests-for-buddypress-dependent-plugins/, from the BP codex, that we're trying to follow.

Thanks for volunteering for this, though! We're working hard to increase our test coverage, and forum/subforum tests, along with BP tests are definitely an area where we are lacking.

#23 @wdfee
3 years ago

  • Cc info@… added

#24 @johnjamesjacoby
3 years ago

  • Milestone changed from Future Release to 2.7
  • Owner set to johnjamesjacoby

Marked #2969 as a duplicate, since the same code will solve both problems.

This will need to be addressed sooner than later, so I'm moving this to 2.7.

Note: See TracTickets for help on using tickets.