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

	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.