BP_REST_XProfile_Repeater_Endpoint::create_item_permissions_check( WP_REST_Request $request )

Check if a given request has access to create a new Repeater Group.

Description

Parameters

$request

(Required) Full data about the request.

Return

(WP_Error|bool)

Source

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

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
public function create_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 `create_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_items_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.