BP_REST_Attachments_Group_Avatar_Endpoint::create_item_permissions_check( WP_REST_Request $request )

Checks if a given request has access to upload a group avatar.

Description

Parameters

$request

(Required) Full details about the request.

Return

(bool|WP_Error)

Source

File: bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php

297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
public function create_item_permissions_check( $request ) {
    $retval = $this->get_item_permissions_check( $request );
 
    if ( true === $retval && ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) ) {
        $retval = new WP_Error(
            'bp_rest_attachments_group_avatar_disabled',
            __( 'Sorry, group avatar upload is disabled.', 'buddyboss' ),
            array(
                'status' => 500,
            )
        );
    }
 
    if (
        true === $retval
        && ! groups_is_user_admin( bp_loggedin_user_id(), $this->group->id )
        && ! current_user_can( 'bp_moderate' )
    ) {
        $retval = new WP_Error(
            'bp_rest_authorization_required',
            __( 'Sorry, you are not authorized to perform this action.', 'buddyboss' ),
            array(
                'status' => rest_authorization_required_code(),
            )
        );
    }
 
    /**
     * Filter the group avatar `create_item` permissions check.
     *
     * @param bool|WP_Error $retval Returned value.
     * @param WP_REST_Request $request The request sent to the API.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_attachments_group_avatar_create_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.