BP_REST_XProfile_Repeater_Endpoint::delete_item_permissions_check( WP_REST_Request $request )

Check if a given request has access to delete a XProfile Repeater field.

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

672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
public function delete_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 delete this field.', '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 fields `delete_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_delete_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.