BP_REST_Group_Settings_Endpoint::get_settings_fields( integer $group_id )

Get Group Settings.

Description

Parameters

$group_id

(Required) Group ID.

Return

(mixed|void)

Source

File: bp-groups/classes/class-bp-rest-group-settings-endpoint.php

	protected function get_settings_fields( $group_id ) {
		$fields                             = array();
		buddypress()->groups->current_group = groups_get_group( $group_id );

		$fields[] = array(
			'label'       => esc_html__( 'Privacy Options', 'buddyboss' ),
			'name'        => 'group-status',
			'description' => '',
			'field'       => 'radio',
			'value'       => bp_get_new_group_status(),
			'options'     => array(
				array(
					'label'             => esc_html__( 'This is a public group', 'buddyboss' ),
					'value'             => 'public',
					'description'       => '<ul id="public-group-description">' .
											'<li>' . esc_html__( 'Any site member can join this group.', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'This group will be listed in the groups directory and in search results.', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'Group content and activity will be visible to any site member.', 'buddyboss' ) . '</li>' .
										'</ul>',
					'is_default_option' => 'public' === bp_get_new_group_status() || ! bp_get_new_group_status(),
				),
				array(
					'label'             => esc_html__( 'This is a private group', 'buddyboss' ),
					'value'             => 'private',
					'description'       => '<ul id="public-group-description">' .
											'<li>' . esc_html__( 'Only people who request membership and are accepted can join the group.', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'This group will be listed in the groups directory and in search results.', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'Group content and activity will only be visible to members of the group.', 'buddyboss' ) . '</li>' .
										'</ul>',
					'is_default_option' => 'private' === bp_get_new_group_status(),
				),
				array(
					'label'             => esc_html__( 'This is a hidden group', 'buddyboss' ),
					'value'             => 'hidden',
					'description'       => '<ul id="public-group-description">' .
											'<li>' . esc_html__( 'Only people who are invited can join the group.', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'This group will not be listed in the groups directory or search results', 'buddyboss' ) . '</li>' .
											'<li>' . esc_html__( 'Group content and activity will only be visible to members of the group.', 'buddyboss' ) . '</li>' .
										'</ul>',
					'is_default_option' => 'private' === bp_get_new_group_status(),
				),
			),
		);

		$fields[] = array(
			'label'       => esc_html__( 'Group Invitations', 'buddyboss' ),
			'name'        => 'group-invite-status',
			'description' => esc_html__( 'Which members of this group are allowed to invite others?', 'buddyboss' ),
			'field'       => 'radio',
			'value'       => bp_group_get_invite_status( $group_id ),
			'options'     => array(
				array(
					'label'             => esc_html__( 'All group members', 'buddyboss' ),
					'value'             => 'members',
					'description'       => '',
					'is_default_option' => 'members' === bp_group_get_invite_status( $group_id ),
				),
				array(
					'label'             => esc_html__( 'Organizers and Moderators only', 'buddyboss' ),
					'value'             => 'mods',
					'description'       => '',
					'is_default_option' => 'mods' === bp_group_get_invite_status( $group_id ),
				),
				array(
					'label'             => esc_html__( 'Organizers only', 'buddyboss' ),
					'value'             => 'admins',
					'description'       => '',
					'is_default_option' => 'admins' === bp_group_get_invite_status( $group_id ),
				),
			),
		);

		$fields[] = array(
			'label'       => esc_html__( 'Activity Feeds', 'buddyboss' ),
			'name'        => 'group-activity-feed-status',
			'description' => esc_html__( 'Which members of this group are allowed to post into the activity feed?', 'buddyboss' ),
			'field'       => 'radio',
			'value'       => bp_group_get_activity_feed_status( $group_id ),
			'options'     => array(
				array(
					'label'             => esc_html__( 'All group members', 'buddyboss' ),
					'value'             => 'members',
					'description'       => '',
					'is_default_option' => 'members' === bp_group_get_activity_feed_status( $group_id ),
				),
				array(
					'label'             => esc_html__( 'Organizers and Moderators only', 'buddyboss' ),
					'value'             => 'mods',
					'description'       => '',
					'is_default_option' => 'mods' === bp_group_get_activity_feed_status( $group_id ),
				),
				array(
					'label'             => esc_html__( 'Organizers only', 'buddyboss' ),
					'value'             => 'admins',
					'description'       => '',
					'is_default_option' => 'admins' === bp_group_get_activity_feed_status( $group_id ),
				),
			),
		);

		if ( bp_is_active( 'media' ) && bp_is_group_media_support_enabled() ) {
			$fields[] = array(
				'label'       => esc_html__( 'Group Photos', 'buddyboss' ),
				'name'        => 'group-media-status',
				'description' => esc_html__( 'Which members of this group are allowed to manage photos?', 'buddyboss' ),
				'field'       => 'radio',
				'value'       => bp_group_get_media_status( $group_id ),
				'options'     => array(
					array(
						'label'             => esc_html__( 'All group members', 'buddyboss' ),
						'value'             => 'members',
						'description'       => '',
						'is_default_option' => 'members' === bp_group_get_media_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers and Moderators only', 'buddyboss' ),
						'value'             => 'mods',
						'description'       => '',
						'is_default_option' => 'mods' === bp_group_get_media_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers only', 'buddyboss' ),
						'value'             => 'admins',
						'description'       => '',
						'is_default_option' => 'admins' === bp_group_get_media_status( $group_id ),
					),
				),
			);
		}

		if ( bp_is_active( 'media' ) && bp_is_group_media_support_enabled() ) {
			$fields[] = array(
				'label'       => esc_html__( 'Group Albums', 'buddyboss' ),
				'name'        => 'group-album-status',
				'description' => esc_html__( 'Which members of this group are allowed to manage albums?', 'buddyboss' ),
				'field'       => 'radio',
				'value'       => bp_group_get_album_status( $group_id ),
				'options'     => array(
					array(
						'label'             => esc_html__( 'All group members', 'buddyboss' ),
						'value'             => 'members',
						'description'       => '',
						'is_default_option' => 'members' === bp_group_get_album_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers and Moderators only', 'buddyboss' ),
						'value'             => 'mods',
						'description'       => '',
						'is_default_option' => 'mods' === bp_group_get_album_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers only', 'buddyboss' ),
						'value'             => 'admins',
						'description'       => '',
						'is_default_option' => 'admins' === bp_group_get_album_status( $group_id ),
					),
				),
			);
		}

		if ( bp_is_active( 'messages' ) && function_exists( 'bp_disable_group_messages' ) && true === bp_disable_group_messages() ) {
			$fields[] = array(
				'label'       => esc_html__( 'Group Messages', 'buddyboss' ),
				'name'        => 'group-message-status',
				'description' => esc_html__( 'Which members of this group are allowed to send group messages?', 'buddyboss' ),
				'field'       => 'radio',
				'value'       => bp_group_get_message_status( $group_id ),
				'options'     => array(
					array(
						'label'             => esc_html__( 'All group members', 'buddyboss' ),
						'value'             => 'members',
						'description'       => '',
						'is_default_option' => 'members' === bp_group_get_message_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers and Moderators only', 'buddyboss' ),
						'value'             => 'mods',
						'description'       => '',
						'is_default_option' => 'mods' === bp_group_get_message_status( $group_id ),
					),
					array(
						'label'             => esc_html__( 'Organizers only', 'buddyboss' ),
						'value'             => 'admins',
						'description'       => '',
						'is_default_option' => 'admins' === bp_group_get_message_status( $group_id ),
					),
				),
			);
		}

		// Group Types.
		$group_types = bp_groups_get_group_types( array( 'show_in_create_screen' => true ), 'objects' );

		// Hide Group Types if none is selected in Users > Profile Type > E.g. (Students) > Allowed Group Types meta box.
		if (
			function_exists( 'bp_restrict_group_creation' )
			&& function_exists( 'bp_member_type_enable_disable' )
			&& false === bp_restrict_group_creation()
			&& true === bp_member_type_enable_disable()
		) {
			$get_all_registered_member_types = bp_get_active_member_types();
			if ( isset( $get_all_registered_member_types ) && ! empty( $get_all_registered_member_types ) ) {

				$current_user_member_type = bp_get_member_type( bp_loggedin_user_id() );
				if ( '' !== $current_user_member_type ) {
					$member_type_post_id = bp_member_type_post_by_type( $current_user_member_type );
					$include_group_type  = get_post_meta( $member_type_post_id, '_bp_member_type_enabled_group_type_create', true );
					if ( isset( $include_group_type ) && ! empty( $include_group_type ) && 'none' === $include_group_type[0] ) {
						$group_types = '';
					}
				}
			}
		}

		if ( $group_types ) {
			$group_type_field = array(
				'label'       => esc_html__( 'Group Type', 'buddyboss' ),
				'name'        => 'group-types',
				'description' => esc_html__( 'What type of group is this? (optional)', 'buddyboss' ),
				'field'       => 'select',
				'value'       => '',
				'options'     => array(),
			);

			$group_hierarchies['options'][] = array(
				'label'             => __( 'Select Group Type', 'buddyboss' ),
				'value'             => '',
				'description'       => '',
				'is_default_option' => '',
			);

			foreach ( $group_types as $type ) {

				if (
					function_exists( 'bp_restrict_group_creation' )
					&& function_exists( 'bp_member_type_enable_disable' )
					&& false === bp_restrict_group_creation()
					&& true === bp_member_type_enable_disable()
				) {

					$get_all_registered_member_types = bp_get_active_member_types();

					if ( isset( $get_all_registered_member_types ) && ! empty( $get_all_registered_member_types ) ) {

						$current_user_member_type = bp_get_member_type( bp_loggedin_user_id() );

						if ( '' !== $current_user_member_type ) {

							$member_type_post_id = bp_member_type_post_by_type( $current_user_member_type );
							$include_group_type  = get_post_meta( $member_type_post_id, '_bp_member_type_enabled_group_type_create', true );

							if ( isset( $include_group_type ) && ! empty( $include_group_type ) ) {
								if ( in_array( $type->name, $include_group_type, true ) ) {
									$group_type_field['options'][] = array(
										'label'       => $type->labels['singular_name'],
										'value'       => $type->name,
										'description' => '',
										'is_default_option' => ( ( ( true === bp_groups_has_group_type( $group_id, $type->name ) ) ? $type->name : '' ) === $type->name ),
									);
								}
							} else {
								$group_type_field['options'][] = array(
									'label'             => $type->labels['singular_name'],
									'value'             => $type->name,
									'description'       => '',
									'is_default_option' => ( ( ( true === bp_groups_has_group_type( $group_id, $type->name ) ) ? $type->name : '' ) === $type->name ),
								);
							}
						} else {
							$group_type_field['options'][] = array(
								'label'             => $type->labels['singular_name'],
								'value'             => $type->name,
								'description'       => '',
								'is_default_option' => ( ( ( true === bp_groups_has_group_type( $group_id, $type->name ) ) ? $type->name : '' ) === $type->name ),
							);
						}
					} else {
						$group_type_field['options'][] = array(
							'label'             => $type->labels['singular_name'],
							'value'             => $type->name,
							'description'       => '',
							'is_default_option' => ( ( ( true === bp_groups_has_group_type( $group_id, $type->name ) ) ? $type->name : '' ) === $type->name ),
						);
					}
				} else {
					$group_type_field['options'][] = array(
						'label'             => $type->labels['singular_name'],
						'value'             => $type->name,
						'description'       => '',
						'is_default_option' => ( ( ( true === bp_groups_has_group_type( $group_id, $type->name ) ) ? $type->name : '' ) === $type->name ),
					);
				}
			}

			$fields[] = $group_type_field;
		}
		// --Group Types.

		if ( function_exists( 'bp_enable_group_hierarchies' ) && bp_enable_group_hierarchies() ) {
			$current_parent_group_id = bp_get_parent_group_id();
			$possible_parent_groups  = bp_get_possible_parent_groups();

			$group_hierarchies = array(
				'label'       => esc_html__( 'Group Parent', 'buddyboss' ),
				'name'        => 'bp-groups-parent',
				'description' => esc_html__( 'Which group should be the parent of this group? (optional)', 'buddyboss' ),
				'field'       => 'select',
				'value'       => $current_parent_group_id,
				'options'     => array(),
			);

			if ( $possible_parent_groups ) {
				$group_hierarchies['options'][] = array(
					'label'             => __( 'Select Parent', 'buddyboss' ),
					'value'             => 0,
					'description'       => '',
					'is_default_option' => empty( $current_parent_group_id ) || 0 === $current_parent_group_id,
				);
				foreach ( $possible_parent_groups as $possible_parent_group ) {
					$group_hierarchies['options'][] = array(
						'label'             => $possible_parent_group->name,
						'value'             => $possible_parent_group->id,
						'description'       => '',
						'is_default_option' => ( $current_parent_group_id === $possible_parent_group->id ),
					);
				}
			}

			$fields[] = $group_hierarchies;
		}

		return apply_filters( 'bp_rest_group_settings', $fields, $group_id );

	}

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.