BP_REST_XProfile_Repeater_Endpoint::update_item_permissions_check( WP_REST_Request $request )

Check if a given request has access to update a Repeater Group.

Description

Parameters

$request

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

Return

(WP_Error|bool)

Source

File: bp-xprofile/classes/class-bp-rest-xprofile-repeater-endpoint.php

	public function update_item_permissions_check( $request ) {
		$retval = true;

		if ( ! is_user_logged_in() ) {
			$retval = new WP_Error(
				'bp_rest_authorization_required',
				__( 'Sorry, you are not allowed to update your profile repeater fields.', 'buddyboss' ),
				array(
					'status' => rest_authorization_required_code(),
				)
			);
		}

		// Get the field group before it's deleted.
		$field_group = xprofile_get_field_group( (int) $request['id'] );

		if ( true === $retval && empty( $field_group->id ) ) {
			$retval = new WP_Error(
				'bp_rest_invalid_id',
				__( 'Invalid Group ID.', 'buddyboss' ),
				array(
					'status' => 404,
				)
			);
		}

		$repeater_enabled = bp_xprofile_get_meta( $field_group->id, 'group', 'is_repeater_enabled', true );

		if ( empty( $field_group ) || 'on' !== $repeater_enabled ) {
			$retval = new WP_Error(
				'bp_rest_invalid_repeater_id',
				__( 'Invalid Repeater Group ID.', 'buddyboss' ),
				array(
					'status' => 404,
				)
			);
		}

		/**
		 * Filter the XProfile repeater fields `update_item` permissions check.
		 *
		 * @since 0.1.0
		 *
		 * @param bool|WP_Error   $retval  Returned value.
		 * @param WP_REST_Request $request The request sent to the API.
		 */
		return apply_filters( 'bp_rest_xprofile_repeater_fields_update_item_permissions_check', $retval, $request );
	}

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.