BP_REST_Attachments_Group_Avatar_Endpoint::create_item( WP_REST_Request $request )
Upload a group avatar.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | public function create_item( $request ) { $request ->set_param( 'context' , 'edit' ); // Get the image file from $_FILES. $files = $request ->get_file_params(); if ( empty ( $files ) ) { return new WP_Error( 'bp_rest_attachments_group_avatar_no_image_file' , __( 'Sorry, you need an image file to upload.' , 'buddyboss' ), array ( 'status' => 500, ) ); } // Upload the avatar. $avatar = $this ->upload_avatar_from_file( $files ); if ( is_wp_error( $avatar ) ) { return $avatar ; } $retval = $this ->prepare_response_for_collection( $this ->prepare_item_for_response( $avatar , $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a group avatar is uploaded via the REST API. * * @param stdClass $avatar The group avatar object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_attachments_group_avatar_create_item' , $avatar , $response , $request ); return $response ; } |
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.