BP_REST_Invites_Endpoint::get_invite_profile_type( WP_REST_Request $request )

Sent Invites Profile Type.

Description

Parameters

$request

(WP_REST_Request) (Required) Full details about the request.

Return

(WP_REST_Response) | WP_Error List of bp-invite profile types

Source

File: bp-invites/classes/class-bp-rest-invites-endpoint.php

	public function get_invite_profile_type( $request ) {

		$member_types = array();

		if ( function_exists( 'bp_check_member_send_invites_tab_member_type_allowed' ) && true === bp_check_member_send_invites_tab_member_type_allowed() ) {
			$current_user              = bp_loggedin_user_id();
			$member_type               = bp_get_member_type( $current_user );
			$member_type_post_id       = bp_member_type_post_by_type( $member_type );
			$get_selected_member_types = get_post_meta( $member_type_post_id, '_bp_member_type_allowed_member_type_invite', true );
			if ( isset( $get_selected_member_types ) && ! empty( $get_selected_member_types ) ) {
				$member_types = $get_selected_member_types;
			} else {
				$member_types = bp_get_active_member_types();
			}
		}

		$retval = array();

		if ( ! empty( $member_types ) ) {
			foreach ( $member_types as $type ) {
				$name     = bp_get_member_type_key( $type );
				$type_obj = bp_get_member_type_object( $name );
				if ( ! empty( $type_obj ) ) {
					$member_type = $type_obj->labels['singular_name'];
				}

				$retval[] = array(
					'value' => $name,
					'label' => esc_html( $member_type ),
				);
			}
		}

		$response = rest_ensure_response( $retval );

		/**
		 * Fires after a list of sent invites profile type is fetched via the REST API.
		 *
		 * @param WP_REST_Response $response     The response data.
		 * @param WP_REST_Request  $request      The request sent to the API.
		 *
		 * @since 0.1.0
		 */
		do_action( 'bp_rest_invites_get_invite_profile_type', $response, $request );

		return $response;
	}

Changelog

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