bp_nouveau_restrict_rest_group_invite_to_friends( bool|WP_Error $retval, WP_REST_Request $request )

Makes sure the BP REST API groups/invites endpoint respects invite restrictions.


Parameters Parameters

$retval

(bool|WP_Error) (Required) Whether the request can continue.

$request

(WP_REST_Request) (Required) The request sent to the API.


Top ↑

Return Return

(bool|WP_Error)


Source Source

File: bp-templates/bp-nouveau/includes/groups/functions.php

function bp_nouveau_restrict_rest_group_invite_to_friends( $retval, $request ) {
	if ( true === $retval && bp_is_active( 'friends' ) ) {
		$group_id   = $request->get_param( 'group_id' );
		$user_id    = $request->get_param( 'user_id' );
		$inviter_id = $request->get_param( 'inviter_id' );

		if ( ! $inviter_id ) {
			$inviter_id = bp_loggedin_user_id();
		}

		if ( bp_nouveau_groups_get_group_invites_setting( $user_id ) && 'is_friend' !== BP_Friends_Friendship::check_is_friend( $inviter_id, $user_id ) ) {
			$retval = new WP_Error(
				'bp_rest_group_invite_cannot_create_item',
				__( 'Sorry, you are not allowed to create the invitation as requested.', 'buddypress' ),
				array(
					'status' => rest_authorization_required_code(),
				)
			);
		}
	}

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.2.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.