BP_Group_Extension::setup_display_hooks()

Hook this extension’s group tab into BuddyPress, if necessary.

Description

Source

File: bp-groups/classes/class-bp-group-extension.php

709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
protected function setup_display_hooks() {
 
    // Bail if not a group.
    if ( ! bp_is_group() ) {
        return;
    }
 
    // Backward compatibility only.
    if ( ( 'public' !== $this->visibility ) && ! buddypress()->groups->current_group->user_has_access ) {
        return;
    }
 
    // If the user can see the nav item, we create it.
    $user_can_see_nav_item = $this->user_can_see_nav_item();
 
    if ( $user_can_see_nav_item ) {
        $group_permalink = bp_get_group_permalink( groups_get_current_group() );
 
        bp_core_create_subnav_link( array(
            'name'            => ! $this->nav_item_name ? $this->name : $this->nav_item_name,
            'slug'            => $this->slug,
            'parent_slug'     => bp_get_current_group_slug(),
            'parent_url'      => $group_permalink,
            'position'        => $this->nav_item_position,
            'item_css_id'     => 'nav-' . $this->slug,
            'screen_function' => array( &$this, '_display_hook' ),
            'user_has_access' => $user_can_see_nav_item,
            'no_access_url'   => $group_permalink,
        ), 'groups' );
    }
 
    // If the user can visit the screen, we register it.
    $user_can_visit = $this->user_can_visit();
 
    if ( $user_can_visit ) {
        $group_permalink = bp_get_group_permalink( groups_get_current_group() );
 
        bp_core_register_subnav_screen_function( array(
            'slug'            => $this->slug,
            'parent_slug'     => bp_get_current_group_slug(),
            'screen_function' => array( &$this, '_display_hook' ),
            'user_has_access' => $user_can_visit,
            'no_access_url'   => $group_permalink,
        ), 'groups' );
 
        // When we are viewing the extension display page, set the title and options title.
        if ( bp_is_current_action( $this->slug ) ) {
            add_filter( 'bp_group_user_has_access',   array( $this, 'group_access_protection' ), 10, 2 );
 
            $extension_name = $this->name;
            add_action( 'bp_template_content_header', function() use ( $extension_name ) {
                echo esc_attr( $extension_name );
            } );
            add_action( 'bp_template_title', function() use ( $extension_name ) {
                echo esc_attr( $extension_name );
            } );
        }
    }
 
    // Hook the group home widget.
    if ( bp_is_group_home() ) {
        add_action( $this->display_hook, array( &$this, 'widget_display' ) );
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.8.0 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.