BBP_Forums_Group_Extension::display_forums( $offset )

Output the forums for a group in the edit screens

Description

As of right now, Forums only supports 1-to-1 group forum relationships. In the future, many-to-many should be allowed.

Source

File: bp-forums/groups.php

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
public function display_forums( $offset = 0 ) {
    global $wp_query;
 
    // Allow actions immediately before group forum output
    do_action( 'bbp_before_group_forum_display' );
 
    // Load up Forums once
    $bbp = bbpress();
 
    /** Query Resets ******************************************************/
 
    // 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 );
 
    // Always load up the group forum
    bbp_has_forums( array(
        'p'           => $forum_id,
        'post_parent' => null
    ) );
 
    // Set the global forum ID
    $bbp->current_forum_id = $forum_id;
 
    // Assume forum query
    bbp_set_query_name( 'bbp_single_forum' ); ?>
 
    <!--<div id="bbpress-forums"> // *** Removed Due to duplicate id *** //-->
 
        <?php switch ( $forum_action ) :
 
            /** Single Forum **********************************************/
 
            case false  :
            case 'page' :
 
                // Strip the super stickies from topic query
                add_filter( 'bbp_get_super_stickies', array( $this, 'no_super_stickies'  ), 10, 1 );
 
                // Unset the super sticky option on topic form
                add_filter( 'bbp_get_topic_types',    array( $this, 'unset_super_sticky' ), 10, 1 );
 
                // Query forums and show them if they exist
                if ( bbp_forums() ) :
 
                    // Setup the forum
                    bbp_the_forum(); ?>
 
                    <?php bbp_get_template_part( 'content', 'single-forum' );
 
                // No forums found
                else : ?>
 
                    <div class="info bp-feedback">
                        <span class="bp-icon" aria-hidden="true"></span>
                        <p><?php esc_html_e( 'This group does not currently have a forum.', 'buddyboss' ); ?></p>
                    </div>
 
                <?php endif;
 
                break;
 
            /** Single Topic **********************************************/
 
            case $this->topic_slug :
 
                // hide the 'to front' admin links
                add_filter( 'bbp_get_topic_stick_link', array( $this, 'hide_super_sticky_admin_link' ), 10, 2 );
 
                // Get the topic
                bbp_has_topics( array(
                    'name'           => bp_action_variable( $offset + 1 ),
                    'posts_per_page' => 1,
                    'show_stickies'  => false
                ) );
 
                // If no topic, 404
                if ( ! bbp_topics() ) {
                    bp_do_404( bbp_get_forum_permalink( $forum_id ) ); ?>
                    <h3 class="bbp-forum-title"><?php bbp_forum_title(); ?></h3>
                    <?php bbp_get_template_part( 'feedback', 'no-topics' );
                    return;
                }
 
                // Setup the topic
                bbp_the_topic(); ?>
 
                <h3 class="bbp-topic-title"><?php bbp_topic_title(); ?></h3>
 
                <?php
 
                // Topic edit
                if ( bp_action_variable( $offset + 2 ) === bbp_get_edit_rewrite_id() ) :
 
                    // Unset the super sticky link on edit topic template
                    add_filter( 'bbp_get_topic_types', array( $this, 'unset_super_sticky' ), 10, 1 );
 
                    // Set the edit switches
                    $wp_query->bbp_is_edit       = true;
                    $wp_query->bbp_is_topic_edit = true;
 
                    // Setup the global forum ID
                    $bbp->current_topic_id       = get_the_ID();
 
                    // Merge
                    if ( !empty( $_GET['action'] ) && 'merge' === $_GET['action'] ) :
                        bbp_set_query_name( 'bbp_topic_merge' );
                        bbp_get_template_part( 'form', 'topic-merge' );
 
                    // Split
                    elseif ( !empty( $_GET['action'] ) && 'split' === $_GET['action'] ) :
                        bbp_set_query_name( 'bbp_topic_split' );
                        bbp_get_template_part( 'form', 'topic-split' );
 
                    // Edit
                    else :
                        bbp_set_query_name( 'bbp_topic_form' );
                        bbp_get_template_part( 'form', 'topic' );
 
                    endif;
 
                // Single Topic
                else:
                    bbp_set_query_name( 'bbp_single_topic' );
                    bbp_get_template_part( 'content', 'single-topic' );
                endif;
                break;
 
            /** Single Reply **********************************************/
 
            case $this->reply_slug :
 
                // Get the reply
                bbp_has_replies( array(
                    'name'           => bp_action_variable( $offset + 1 ),
                    'posts_per_page' => 1
                ) );
 
                // If no topic, 404
                if ( ! bbp_replies() ) {
                    bp_do_404( bbp_get_forum_permalink( $forum_id ) ); ?>
                    <h3><?php bbp_forum_title(); ?></h3>
                    <?php bbp_get_template_part( 'feedback', 'no-replies' );
                    return;
                }
 
                // Setup the reply
                bbp_the_reply(); ?>
 
                <h3><?php bbp_reply_title(); ?></h3>
 
                <?php if ( bp_action_variable( $offset + 2 ) === bbp_get_edit_rewrite_id() ) :
 
                    // Set the edit switches
                    $wp_query->bbp_is_edit       = true;
                    $wp_query->bbp_is_reply_edit = true;
 
                    // Setup the global reply ID
                    $bbp->current_reply_id       = get_the_ID();
 
                    // Move
                    if ( !empty( $_GET['action'] ) && ( 'move' === $_GET['action'] ) ) :
                        bbp_set_query_name( 'bbp_reply_move' );
                        bbp_get_template_part( 'form', 'reply-move' );
 
                    // Edit
                    else :
                        bbp_set_query_name( 'bbp_reply_form' );
                        bbp_get_template_part( 'form', 'reply' );
                    endif;
                endif;
                break;
        endswitch;
 
        // Reset the query
        wp_reset_query(); ?>
 
    <!--</div>-->
 
    <?php
 
    // Allow actions immediately after group forum output
    do_action( 'bbp_after_group_forum_display' );
}

Changelog

Changelog
Version Description
bbPress (r3653) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.