BP_Group_Extension::setup_access_settings()

Set up access-related settings for this extension.

Description

Source

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

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
protected function setup_access_settings() {
 
    // Bail if no group ID is available.
    if ( empty( $this->group_id ) ) {
        return;
    }
 
    // Backward compatibility.
    if ( isset( $this->params['enable_nav_item'] ) ) {
        $this->enable_nav_item = (bool) $this->params['enable_nav_item'];
    }
 
    // Tab Access.
    $this->user_can_visit = false;
 
    // Backward compatibility for components that do not provide
    // explicit 'access' parameter.
    if ( empty( $this->params['access'] ) ) {
        if ( false === $this->params['enable_nav_item'] ) {
            $this->params['access'] = 'noone';
        } else {
            $group = groups_get_group( $this->group_id );
 
            if ( ! empty( $group->status ) && 'public' === $group->status ) {
                // Tabs in public groups are accessible to anyone by default.
                $this->params['access'] = 'anyone';
            } else {
                // All other groups have members-only as the default.
                $this->params['access'] = 'member';
            }
        }
    }
 
    // Parse multiple access conditions into an array.
    $access_conditions = $this->params['access'];
    if ( ! is_array( $access_conditions ) ) {
        $access_conditions = explode( ',', $access_conditions );
    }
 
    // If the current user meets at least one condition, the
    // get access.
    foreach ( $access_conditions as $access_condition ) {
        if ( $this->user_meets_access_condition( $access_condition ) ) {
            $this->user_can_visit = true;
            break;
        }
    }
 
    // Tab Visibility.
    $this->user_can_see_nav_item = false;
 
    // Backward compatibility for components that do not provide
    // explicit 'show_tab' parameter.
    if ( empty( $this->params['show_tab'] ) ) {
        if ( false === $this->params['enable_nav_item'] ) {
            // The enable_nav_item index is only false if it's been
            // defined explicitly as such in the
            // constructor. So we always trust this value.
            $this->params['show_tab'] = 'noone';
 
        } elseif ( isset( $this->params_raw['enable_nav_item'] ) || isset( $this->params_raw['visibility'] ) ) {
            // If enable_nav_item or visibility is passed,
            // we assume this  is a legacy extension.
            // Legacy behavior is that enable_nav_item=true +
            // visibility=private implies members-only.
            if ( 'public' !== $this->visibility ) {
                $this->params['show_tab'] = 'member';
            } else {
                $this->params['show_tab'] = 'anyone';
            }
 
        } else {
            // No show_tab or enable_nav_item value is
            // available, so match the value of 'access'.
            $this->params['show_tab'] = $this->params['access'];
        }
    }
 
    // Parse multiple access conditions into an array.
    $access_conditions = $this->params['show_tab'];
    if ( ! is_array( $access_conditions ) ) {
        $access_conditions = explode( ',', $access_conditions );
    }
 
    // If the current user meets at least one condition, the
    // get access.
    foreach ( $access_conditions as $access_condition ) {
        if ( $this->user_meets_access_condition( $access_condition ) ) {
            $this->user_can_see_nav_item = true;
            break;
        }
    }
}

Changelog

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