bp_get_group_join_button( object|bool $group = false )

Return button to join a group.

Description

Parameters

$group

(Optional) Single group object.

Default value: false

Return

(false|string)

Source

File: bp-groups/bp-groups-template.php

	function bp_get_group_join_button( $group = false ) {
		global $groups_template;

		// Set group to current loop group if none passed.
		if ( empty( $group ) ) {
			$group =& $groups_template->group;
		}

		// Don't show button if not logged in or previously banned.
		if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
			return false;
		}

		// Group creation was not completed or status is unknown.
		if ( empty( $group->status ) ) {
			return false;
		}

		// Already a member.
		if ( ! empty( $group->is_member ) ) {

		    $is_only_admin = false;
			// Stop sole admins from abandoning their group.
			$group_admins = groups_get_group_admins( $group->id );
			if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
				$is_only_admin = true;
			}

			if ( groups_is_user_admin( bp_loggedin_user_id(), $group->id ) ) {
				if ( 'Organizer' === get_group_role_label( $group->id, 'organizer_singular_label_name') ) {
					$button_text = __( 'You\'re an ' . get_group_role_label( $group->id, 'organizer_singular_label_name'), 'buddyboss' );
				} else {
					$button_text = __( 'You\'re a ' . get_group_role_label( $group->id, 'organizer_singular_label_name'), 'buddyboss' );
				}
			} elseif ( groups_is_user_mod( bp_loggedin_user_id(), $group->id ) ) {
				$button_text = __( 'You\'re a ' . get_group_role_label( $group->id, 'moderator_singular_label_name'), 'buddyboss' );
			} else {
				$button_text = __( 'You\'re a ' . get_group_role_label( $group->id, 'member_singular_label_name'), 'buddyboss' );
			}

			// Setup button attributes.
			$button = array(
				'id'                => 'leave_group',
				'component'         => 'groups',
				'must_be_logged_in' => true,
				'block_self'        => false,
				'wrapper_class'     => 'group-button ' . $group->status,
				'wrapper_id'        => 'groupbutton-' . $group->id,
				'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'leave-group' ), 'groups_leave_group' ),
				'link_text'         => $button_text,
				'link_class'        => 'group-button leave-group bp-toggle-action-button',
				'button_attr' => array(
					'data-title'           => __( 'Leave group', 'buddyboss' ),
					'data-title-displayed' => $button_text
				)
			);

			if ( $is_only_admin ) {
			    $button['button_attr']['data-only-admin'] = '1';
            }

		// Not a member.
		} else {

			// Show different buttons based on group status.
			switch ( $group->status ) {
				case 'hidden' :
					return false;

				case 'public':
					$button = array(
						'id'                => 'join_group',
						'component'         => 'groups',
						'must_be_logged_in' => true,
						'block_self'        => false,
						'wrapper_class'     => 'group-button ' . $group->status,
						'wrapper_id'        => 'groupbutton-' . $group->id,
						'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'join' ), 'groups_join_group' ),
						'link_text'         => __( 'Join group', 'buddyboss' ),
						'link_class'        => 'group-button join-group',
					);
					break;

				case 'private' :

					// Member has outstanding invitation -
					// show an "Accept Invitation" button.
					if ( $group->is_invited ) {
						$button = array(
							'id'                => 'accept_invite',
							'component'         => 'groups',
							'must_be_logged_in' => true,
							'block_self'        => false,
							'wrapper_class'     => 'group-button ' . $group->status,
							'wrapper_id'        => 'groupbutton-' . $group->id,
							'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
							'link_text'         => __( 'Accept Invitation', 'buddyboss' ),
							'link_class'        => 'group-button accept-invite',
						);

					// Member has requested membership but request is pending -
					// show a "Request Sent" button.
					} elseif ( $group->is_pending ) {
						$button = array(
							'id'                => 'membership_requested',
							'component'         => 'groups',
							'must_be_logged_in' => true,
							'block_self'        => false,
							'wrapper_class'     => 'group-button pending ' . $group->status,
							'wrapper_id'        => 'groupbutton-' . $group->id,
							'link_href'         => bp_get_group_permalink( $group ),
							'link_text'         => __( 'Request Sent', 'buddyboss' ),
							'link_class'        => 'group-button pending membership-requested',
						);

					// Member has not requested membership yet -
					// show a "Request Membership" button.
					} else {

						if ( true === bp_member_type_enable_disable() && true === bp_disable_group_type_creation() ) {

							$group_type = bp_groups_get_group_type( $group->id );

							$group_type_id = bp_get_group_type_post_id( $group_type );

							$get_selected_member_type_join = get_post_meta( $group_type_id, '_bp_group_type_enabled_member_type_join', true );

							$get_selected_member_type_join = ( isset( $get_selected_member_type_join ) && !empty( $get_selected_member_type_join ) ) ? $get_selected_member_type_join : array();

							$get_requesting_user_member_type = bp_get_member_type( bp_loggedin_user_id() );

							if ( in_array( $get_requesting_user_member_type, $get_selected_member_type_join ) ) {
								$button = array(
									'id'                => 'request_membership',
									'component'         => 'groups',
									'must_be_logged_in' => true,
									'block_self'        => false,
									'wrapper_class'     => 'group-button ' . $group->status,
									'wrapper_id'        => 'groupbutton-' . $group->id,
									'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'request-membership' ), 'groups_request_membership' ),
									'link_text'         => __( 'Join group', 'buddyboss' ),
									'link_class'        => 'group-button request-membership',
								);
							} else {
								$button = array(
									'id'                => 'request_membership',
									'component'         => 'groups',
									'must_be_logged_in' => true,
									'block_self'        => false,
									'wrapper_class'     => 'group-button ' . $group->status,
									'wrapper_id'        => 'groupbutton-' . $group->id,
									'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'request-membership' ), 'groups_request_membership' ),
									'link_text'         => __( 'Request Access', 'buddyboss' ),
									'link_class'        => 'group-button request-membership',
								);
							}

						} else {
							$button = array(
								'id'                => 'request_membership',
								'component'         => 'groups',
								'must_be_logged_in' => true,
								'block_self'        => false,
								'wrapper_class'     => 'group-button ' . $group->status,
								'wrapper_id'        => 'groupbutton-' . $group->id,
								'link_href'         => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'request-membership' ), 'groups_request_membership' ),
								'link_text'         => __( 'Request Access', 'buddyboss' ),
								'link_class'        => 'group-button request-membership',
							);
						}
					}

					break;
			}
		}

		/**
		 * Filters the HTML button for joining a group.
		 *
		 * @since BuddyPress 1.2.6
		 * @since BuddyPress 2.4.0 Added $group parameter to filter args.
		 *
		 * @param string $button HTML button for joining a group.
		 * @param object $group BuddyPress group object
		 */
		return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );
	}

Changelog

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