Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sub forums in bbpress 2.3 and buddypress 1.7


  • moebis
    Participant

    @moebis

    I just installed the latest trunk of both to continue my testing. I like a lot of the improvements, but I’ve been discovering some bugs here and there. Not sure if this is the place to post it, but here it goes.

    First off, the 2 work well together now, except when you try to mix the site-wide forums with group forums. If you click on a group and look at the forum tab, it shows posts from the next group-forum or site-wide forums. What I’m attempting to do is create groups, with a top-level forum for each group, and then sub-sitewide forums underneath, which I nest using the backend bbpress admin. These sub-forums don’t have a group all their own they just belong underneath and listed in forums top of the master group they are part of. It looks like this functionality is somewhat coded into the newest branch of buddypress 1.7 and bbpress 2.3, and if fixed it would be perfect. I know there is a plugin called buddypress group hierarchy or something, but it’s not really what I’m looking for, because it assumes I want full group buddypress functionality surrounding the sub-forums. I just want more granular control over the topics on each group.


    @johnjamesjacoby
    – hear our plea. Allow us to create sub-forums in bbpress for the top-level forum in buddypress groups. When you click on the group, the sub-forums that belong to it will show underneath. When posting to the group forum, maybe even an option to move the topic to the top level group forum or sub-forums for the user? Just a thought. Thanks for all the great work on this, it’s getting much better now.

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

  • moebis
    Participant

    @moebis

    Created ticket within buddypress trac: https://buddypress.trac.wordpress.org/ticket/4797


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Multiple forums per BuddyPress Group is started in bbPress, but likely won’t be finished for several months. There are a few technical challenges regarding performance that don’t make it entirely feasible. If it’s something you need, you’ll want to build it, and if you’re able, contribute back to the bbPress project.

    On the whole, I agree that it would be nice to have in core.


    Erlend
    Participant

    @sadr

    What about assigning tag(s) to a group instead, like you do it on WPORG? Wouldn’t that be a good way to at least make it a bit more flexible while working towards the ‘multiple forums per group’ ?


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    I’ve considered this, but without term meta there’s no way to do sticky topics in groups.


    moebis
    Participant

    @moebis

    @johnjamesjacoby – This actually almost completely works within the current trunks of bbpress and buddypress, even the activity feed of subforums looks and works correctly within the group. The only bug is somewhere in the display of the forum tab in the group, I assume because it’s not expecting a subforum, which is why it doesn’t display the parent forum, which is also the group forum. I confirmed this by creating another subgroup (so 1 parent, and 2 child), and it will only display the latest forum/subforum created within the group and ignore the older 2 (the parent and first created subfourm). I will play around with the source code to see where it’s generating the group forum display and make a code suggestion if you would like. It’s probably just querying the bbpress tables for a forum associated with the group and whichever shows last in the table is what the display generates. It’s smart enough to already calculate all of the topics in all forums and sub-forums, so it’s about 90% of the way there. I think because bbpress and buddypress are partitioned so well, this might not be an issue, it’s almost feature complete in this regard, and I know the community has been clambering for this functionality for a very long time. Most end up turning to the hierarchy plugin, which really isn’t the long term solution. Is it possible to get this into 1.7, which is so close to release? If so, I’ll work out a quick solution, that is future proof and can be expanded on in future versions.


    moebis
    Participant

    @moebis

    Good News All!!! Ok…. I have sub forums working in buddypress with a small hack to group.php (in latest trunk of bbpress 2.3). @johnjamesjacoby was right, it looks like they started building this functionality into bbpress and so-far it works. The only thing left to do, is maybe make it display a little more intuitively (I’ll continue to work on that), and on the buddypress side allow sub forum posts to be added to the activity feed of the group it belongs to. I was wrong before, sub forum topic posts do not show up on group activity feed, but I think I’ve already isolated the code to fix that.

    Here is how to play with my hack in the latest trunk:

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

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

    This is how the forums in groups looks now (you can see all topics from the group forum and the bbpress sub forum of that group forum). Also, the post box has a drop-down select to chose the forum or sub-forum to post to:


    stickFinger
    Participant

    @stickfinger

    Hi moebi

    I came here from a google search regarding subforuns in bbpress.

    Even before I install wp+bp+bbpress i´d love to know if you have news on this. For the kind of community i´m planning subforuns is a must 🙂

    Also looking at your code, i´ve found in my group.php

    ` */
    public function remove_forum( $forum_args = array() ) {

    // Bail if no forum_id was passed
    if ( empty( $forum_args[‘forum_id’] ) )
    return;
    ` where public function is line 610 and so i´m a bit lost.

    Any help would be appreciate.
    Thanks


    stickFinger
    Participant

    @stickfinger

    Sorry, but that is really VERY important for my new project, so:

    Any insight on this?


    Fraternity
    Participant

    @fraternity

    Throwing a post on here to get notified as replies, as this is exactly what I am trying to achieve.

    This bit looks promising: “Good News All!!! Ok…. I have sub forums working in buddypress with a small hack to group.php (in latest trunk of bbpress 2.3)”


    Fraternity
    Participant

    @fraternity

    Also, sorry to derail a bit, but any comment on scalability of this?

    I currently run three forums, one each for a different capital city in my country, each with around 15 subforums.

    My plan is to combine these into a single site, so each group forum would have 15 subforums – which would be about 45 forums just to replicate what I have now.

    I’d then like to create another 10 or so site forums, so that our members from different cities can discuss general topics. And then I’d like to add more groups – initially I’d be adding 3 more groups, for 3 more cities in my country, which would be another 45 forums.

    That right away takes me up to 106 forums (10 sitewide, 6 group forums and 90 subforums), before I even start expanding the geographic reach of our groups beyond our country’s borders.

    Let’s say I expand into 50 different cities, I’m looking at about 810 subforums (10 sitewide, 50 group forums, 750 subforums).

    John mentions “There are a few technical challenges regarding performance that don’t make it entirely feasible” and I wonder if this was what he was getting at?

    Perhaps I’m posting this in the wrong section.. but figured you’re probably going to run into a similar issue, moebis


    stickFinger
    Participant

    @stickfinger

    At least one response Fraternity 🙂
    It seem that matter are kind of…forgotten

    For my kind of site/ project this would be perfect.
    Also i´d like to mention a hidden (at least for me) fact: on a new install of bp 1.7 + bbpress we have no choice to stay with the now “retired” bp forum compnent.

    I´m telling you that because with the old forum component + we can achieve buddypress subgroups and subforums aswell.

    moebis…where the hell are you ? 🙂 we need your hack. please elaborate a bit more …


    Fraternity
    Participant

    @fraternity

    moebis – just took a look at this, I may have a more recent version than you use in your fix above.

    Here is how to play with my hack in the latest trunk:

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

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

    The code I have at these lines is this:

    <?php bbp_get_template_part( ‘form’, ‘topic’ ); ?>

    <?php else : ?>

    <?php bbp_get_template_part( ‘feedback’, ‘no-topics’ ); ?>

    Probably not what I want to comment out. What I did find though is this (lines 567-581):

    // Suppress subforums for now
    add_filter( ‘bbp_get_forum_subforum_count’, ‘__return_false’ );

    // Set up forum data
    bbpress()->current_forum_id = $forum->ID;
    bbp_set_query_name( ‘bbp_single_forum’ ); ?>

    <?php

    // Remove the subforum suppression filter
    remove_filter( 'bbp_get_forum_subforum_count', '__return_false' );

    Group Subforums

    I highlighted a few things:
    1) Topics are only being displayed from group subforum 2 (believe you mentioned this above). This should be easy enough to fix
    2) I thought I was posting in the Group Forum when I used the default form below, but clearly (as per highlight 3) this is now set to group subforum 2
    3) Default Create New Topic is set to Group Subforum 2. I assume this was the “last retrieved forum” and is probably easy enough to fix. In my case, I’ll probably be changing my group forums to a category anyway, so I don’t actually want people starting new topics from this page.


    Fraternity
    Participant

    @fraternity

    That second codeblock (lines 567-581) should read:

    `
    // Suppress subforums for now
    //add_filter( ‘bbp_get_forum_subforum_count’, ‘__return_false’ );

    // Set up forum data
    bbpress()->current_forum_id = $forum->ID;
    bbp_set_query_name( ‘bbp_single_forum’ ); ?>

    <?php

    // Remove the subforum suppression filter
    //remove_filter( 'bbp_get_forum_subforum_count', '__return_false' );
    `

    The fact that bbPress doesn't automatically encode text between the code tags I used is a bit of a concern 😀


    Fraternity
    Participant

    @fraternity

    @stickfinger: moebis provided his hack above. If you weren’t able to follow his instructions, then it’s probably not a good idea that you try to do this modification, and wait for the official release when the bbPress team get it sorted.

    As both moebis and I have pointed out, there are a few ‘issues’ at trying to force it to do this and that’s probably why the bbPress team have held off on the official release.


    stickFinger
    Participant

    @stickfinger

    I guess i have the same problem as you my file is different from moebis´ and so i could not find the correct lines.

    I´m not a coder but i can assure you that i know how to copy and paste 🙂

    But you´re right, maybe i´ll start with BP 1.6.5 and use this Nice PLug to get the project as I wish for now. I have a similar project as Yours but very smaller

    A district site ( with maybe 4 to 10 ) and with subforums like Health, Education, Secutity, Traffic, etc.

    So for instance:

    Brooklyn:
    –Health
    –Education
    –Traffic

    Queens:
    –Health
    –Education
    –Traffic

    But i still have some concerns about future updates, you know. i´m a bit stucked 🙂


    Fraternity
    Participant

    @fraternity

    Just came back to this after a number of months and see there are a few new versions out

    Have group subforums been implemented yet? I couldn’t tell from the release notes.


    Riobeaches
    Participant

    @riobeaches

    any new on updates on group subforums yet?


    derricksmith01
    Participant

    @derricksmith01

    Hello,

    I really needed this feature so I dug into the code and came up with a solution that doesn’t modify core files. The solution hooks the query pre_get_posts and uses the buddypress ‘plugins’ template file to catch and display the group sub forums.

    This probably isn’t the most efficient solution but it seems to work in my environment. I’ll post back if I notice any issues as more subforums are created.

    Here are the functions – place in your theme’s functions.php. I also included my plugins.php file also.

    // functions.php

    
    //Filters bbpress forum permalink if on a group forum page.  Keeps users from being redirected to sitewide forums
    function buddyboss_forum_permalink($link){
    	global $wpdb, $bp;
    	if (strpos($link, "/forums/forum/")){
    
    			$forum = substr($link, strpos($link, "/forum/") + 7);   
    			$forums = explode("/",$forum);
    			$args=array(
    				'post_type' => 'forum',
    				'name' => $forums[0],
    			);
    			$root_forum = get_posts( $args );
    			$group_id = $wpdb->get_var(
    				" SELECT group_id
    				  FROM wp_bp_groups_groupmeta
    				  WHERE meta_key = 'forum_id' AND meta_value = '". serialize(array($root_forum[0]->ID)) ."'"
    			);
    			if (isset($group_id)){
    				$group = groups_get_group( array( 'group_id' => $group_id ) );
    				unset($forums[0]);
    				$forums = implode("/",$forums);
    				$permalink = bp_get_group_forum_permalink($group)."/".$forums;
    			} else {
    				$permalink = $link;
    			}
    			
    	}
    	return $permalink;
    }
    add_filter('bbp_get_forum_permalink','buddyboss_forum_permalink',10,1);
    
    //Filters bbpress topic permalink if on a group forum page.  Keeps users from being redirected to sitewide forums
    function buddyboss_topic_permalink($link){
    	global $wpdb, $bp;
    		if (strpos($link, "/forums/topic/")){
    			$start_topic = substr($link, strpos($link, "/topic/") + 7);   
    			
    			$args=array(
    				'post_type' => 'topic',
    				'name' => $start_topic,
    			);
    			$topic = get_posts( $args );
    			
    			$topic_forums = get_post_ancestors( $topic[0]->ID );
    
    			$root_forum_id = end($topic_forums);
    			$group_id = $wpdb->get_var(
    				" SELECT group_id
    				  FROM wp_bp_groups_groupmeta
    				  WHERE meta_key = 'forum_id' AND meta_value = '". serialize(array($root_forum_id)) ."'"
    			);
    			
    			if (isset($group_id)){
    				
    				$group = groups_get_group( array( 'group_id' => $group_id ) );
    				array_pop($topic_forums);  //Pop group's root forum
    				
    				foreach ($topic_forums as $forum){
    					$post = get_post($forum); 
    					$slug = $post->post_name;
    					$forum_parts .= $slug."/";
    				}
    				$permalink = bp_get_group_forum_permalink($group)."/".$forum_parts."topic/".$start_topic;
    			} else {
    				$permalink = $link;
    			}
    			
    		}	
    			
    	return $permalink;
    }
    add_filter('bbp_get_topic_permalink','buddyboss_topic_permalink',10,1);
    
    //Filters bbpress reply permalink if on a group forum page.  Keeps users from being redirected to sitewide forums
    function buddyboss_reply_permalink($link){
    	if (strpos($link, "/forums/reply/")){
    			$reply = str_replace(site_url()."/forums/reply/","reply/",$link);
    			$forum = str_replace("/forums/forum/".$bp->groups->current_group->slug, "/groups/".$bp->groups->current_group->slug ."/forum", bbp_get_topic_permalink(bbp_get_topic_id()));
    		$permalink = $forum.$reply;
    	}
    	return $link;
    }
    add_filter('bbp_get_reply_permalink','buddyboss_reply_permalink',10,1);
    
    function buddyboss_bbpress_pre_get_posts($query){
    	global $bp;
    
    	if( $query->is_main_query()) {
    		
    		if (bp_current_action() == 'forum'){
    		
    			if (!empty($bp->action_variables) && !in_array("topic", $bp->action_variables) && !in_array("reply", $bp->action_variables)){  //Sub Forum
    				$forum = end($bp->action_variables);
    				
    				$args = array(
    					'post_type' => 'forum',
    					'name' => $forum
    				);
    				$forums = get_posts( $args );	
    				$parent = $query->get('p');
    				$query->set('p','');
    				$query->set('post_parent',$parent);
    	
    				bbpress()->current_forum_id = $forums[0]->ID;
    				bbp_set_query_name( 'bbp_single_forum' );
    				
    				return $query;
    			} 
    			
    			if (empty($bp->action_variables) ) {  //Root Group Forum
    				bbp_set_query_name( 'bbp_single_forum' );
    				
    				return $query;
    				
    			}
    			
    			if (in_array("topic", $bp->action_variables) && !in_array("reply", $bp->action_variables)){  //Topic
    				$topic = end($bp->action_variables);
    				if ($topic == 'edit'){
    					$edit_key == array_search($topic,$bp->action_variables);
    					$topic = $bp->action_variables[$edit_key-1];
    				}
    				
    				$args = array(
    					'post_type' => 'topic',
    					'name' => $topic
    				);
    				$topics = get_posts( $args );	
    
    				$query->set('p','');
    				$query->set('post_parent',$topics[0]->post_parent);
    				
    				bbpress()->current_forum_id = $topics[0]->post_parent;
    				bbpress()->current_topic_id = $topics[0]->ID;
    				bbp_set_query_name( 'bbp_single_topic' );
    				if (end($bp->action_variables) == 'edit'){
    					bbpress()->current_view_id = 'edit';
    				}
    				
    				return $query;
    			}
    			
    			if (in_array("topic", $bp->action_variables) && in_array("reply", $bp->action_variables)){ //Reply
    				$reply = array_search('reply', $bp->action_variables);
    				$reply_id = $bp->action_variables[$reply+1];
    			
    				$reply_post = get_post( $reply_id );
    				$query->set('p',$reply_id);
    				
    				bbpress()->current_topic_id = $reply_post->post_parent;
    				bbpress()->current_reply_id = $reply_id;
    				bbp_set_query_name( 'bbp_single_reply' );
    				if (end($bp->action_variables) == 'edit'){
    					bbpress()->current_view_id = 'edit';
    				}
    				return $query;
    			}
    			
    		}
    	}
    	return $query;
    }
    add_action('pre_get_posts','buddyboss_bbpress_pre_get_posts',10, 1);
    
    function buddyboss_bbpress_is_edit($retval){
    	global $bp;
    	if (end($bp->action_variables) == 'edit') $retval = true;
    	return $retval;
    }
    add_filter('bbp_is_topic_edit','buddyboss_bbpress_is_edit', 10, 1);
    add_filter('bbp_is_reply_edit','buddyboss_bbpress_is_edit', 10, 1);
    
    function buddyboss_bbpress_form_reply_content($retval){
    	global $bp;
    	if (end($bp->action_variables) == 'edit' && in_array('topic', $bp->action_variables) && in_array('reply', $bp->action_variables)) {
    		$post = get_post( bbpress()->current_reply_id );
    		return esc_textarea( $post->post_content );
    	}
    }
    add_filter('bbp_get_form_reply_content','buddyboss_bbpress_form_reply_content', 10, 1);
    
    function buddyboss_bbpress_form_topic_content($retval){
    	global $bp;
    	if (end($bp->action_variables) == 'edit' && in_array('topic', $bp->action_variables) && !in_array('reply', $bp->action_variables)) {
    		$post = get_post( bbpress()->current_topic_id );
    	
    		return esc_textarea( $post->post_content );
    	}
    }
    add_filter('bbp_get_form_topic_content','buddyboss_bbpress_form_topic_content', 10, 1);
    
    function buddyboss_bbpress_form_title(){
    	global $bp;
    	if (end($bp->action_variables) == 'edit' && in_array('topic', $bp->action_variables) && !in_array('reply', $bp->action_variables)) {
    		$post = get_post( bbpress()->current_topic_id );
    		return esc_html( $post->post_title );
    	}
    }
    add_filter('bbp_get_form_topic_title','buddyboss_bbpress_form_title', 10, 1);
    
    //Filters bbpress admin links if on a group forum page.  Keeps users from being redirected to sitewide forums
    function buddyboss_reply_admin_links( $links, $args ) {
    	global $bp;
    	if (bp_current_action() == 'forum'){ 
    	$dom = new DOMDocument;
    		$dom->loadHTML($links);
    		
    		foreach ($dom->getElementsByTagName('a') as $node) {
    			//print_r($node);
    			if ($node->nodeValue == 'Edit'){
    				$forum = str_replace("/forums/forum/".$bp->groups->current_group->slug, "/groups/".$bp->groups->current_group->slug ."/forum", bbp_get_topic_permalink(bbp_get_topic_id()));
    				$reply = str_replace(site_url()."/forums/reply/","reply/",$node->getAttribute( 'href' ));
    				$node->setAttribute('href', $forum.$reply);
    			}
    			
    		}
    		$links = $dom->saveHTML();
    	}
    	return $links;
    }
    add_filter( 'bbp_get_reply_admin_links', 'buddyboss_reply_admin_links', 10, 2 );
    

    /buddypress/groups/single/plugins.php

    
    <?php
    global $bp;
    
    do_action( 'bp_before_group_plugin_template' );
    
    if (bp_current_action() == 'forum'){
    	if (empty($bp->action_variables)){  //Forum
    		$bp->groups->current_group->id;
    				$group_forum = groups_get_groupmeta( $bp->groups->current_group->id, $meta_key = 'forum_id');
    				$group_forum_id = $group_forum[0];
    
    				bbpress()->current_forum_id = $group_forum_id;
    				bbp_get_template_part('content','single-forum');	
    	} elseif (!empty($bp->action_variables) && !in_array("topic", $bp->action_variables) && !in_array("reply", $bp->action_variables)){ 
    		
    				bbp_get_template_part('content','single-forum');
    	} elseif (in_array("topic", $bp->action_variables) && !in_array("reply", $bp->action_variables)){  //Topic
    		if (bbpress()->current_view_id === 'edit'){
    			echo "<div id='bbpress-forums'>";
    			echo "<a href='".bbp_get_topic_permalink()."'><h4><img src='".get_stylesheet_directory_uri()."/images/back_button.png' />Back to Topic</h4></a>";
    			bbp_get_template_part('form','topic');
    			echo "</div>";
    		} else {
    			bbp_get_template_part('content','single-topic');
    		}
    	} elseif (in_array("topic", $bp->action_variables) && in_array("reply", $bp->action_variables)){ //Reply
    		if (bbpress()->current_view_id === 'edit'){
    			echo "<div id='bbpress-forums'>";
    			echo "<a href='".bbp_get_topic_permalink()."'><h4><img src='".get_stylesheet_directory_uri()."/images/back_button.png' /> Back to Topic</h4></a>";
    			bbp_get_template_part('form','reply');
    			echo "</div>";
    		} else {
    			bbp_get_template_part('content','single-reply');
    		}
    		
    	}	
    } else {
    	do_action( 'bp_template_content' ); 
    }
    ?>
    
    <?php do_action( 'bp_after_group_plugin_template' );
    

    bazaarocommunity
    Participant

    @bazaarocommunity

    Is this solution still working out for you? I’d really like to implement something similar.

    I reviewed the trac and didn’t see this anywhere, has this fallen off the to do list or am I overlooking something. I would love to see this in the core.


    wplove3268
    Participant

    @wplove3268

    I’m implementing derricksmith01’s solution but I couldn’t find this file in the latest version of buddypress (Version 2.2.3.1):
    /buddypress/groups/single/plugins.php
    but found it here:
    plugins/buddypress/bp-templates/bp-legacy/buddypress/groups/single/plugins.php

    His solution worked (awesome!!!!) but only when I modified both my functions.php file in my child theme and the plugins.php file in the core files. The plugins.php mod will get erased with the next buddypress update. I tried recreating the same file structure to house the plugins.php file in my child theme:
    childtheme/buddypress/bp-templates/bp-legacy/buddypress/groups/single/plugins.php
    but that did not work either.

    Any one know if derricksmith01’s fix is possible without changing a core file?


    wplove3268
    Participant

    @wplove3268

    Thanks derricksmith01 for the great patch! Totally needed!


    wplove3268
    Participant

    @wplove3268

    A follow up observation on this:
    I see in my breadcrumb that a sub-forum of a group’s forum reads correctly:
    Forums>Group Forum>Group sub-Forum

    But when I make a sub-sub-forum the breadcrumb breaks down:
    Forums>Group sub-sub-Forum
    instead of:
    Forums>Group Forum>Group sub-Forum>Group sub-sub-Forum

    However in both the Group sub forum and the Group sub-sub forum the forum displays, and is protected by, the parent Group.


    wplove3268
    Participant

    @wplove3268

    I also found that when, as Keymaster, I went to Edit a particular topic or reply, the Edit field displayed no text and I was not able to save any changes. When I commented out this particular snippet form derricksmith01’s solution the problem dissappeared.

    function buddyboss_bbpress_form_reply_content($retval){
    	global $bp;
    	if (end($bp->action_variables) == 'edit' && in_array('topic', $bp->action_variables) && in_array('reply', $bp->action_variables)) {
    		$post = get_post( bbpress()->current_reply_id );
    		return esc_textarea( $post->post_content );
    	}
    }
    
    add_filter('bbp_get_form_reply_content','buddyboss_bbpress_form_reply_content', 10, 1);
Viewing 23 replies - 1 through 23 (of 23 total)
  • You must be logged in to reply to this topic.
Skip to toolbar