BP_REST_Media_Endpoint::upload_item( WP_REST_Request $request )
Upload Media.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-media/classes/class-bp-rest-media-endpoint.php
public function upload_item( $request ) { $file = $request->get_file_params(); if ( empty( $file ) ) { return new WP_Error( 'bp_rest_media_file_required', __( 'Sorry, you have not uploaded any media.', 'buddyboss' ), array( 'status' => 400, ) ); } /** * Create and upload the media file. */ $upload = bp_media_upload(); if ( is_wp_error( $upload ) ) { return new WP_Error( 'bp_rest_media_upload_error', $upload->get_error_message(), array( 'status' => 400, ) ); } $retval = array( 'upload_id' => $upload['id'], 'upload' => $upload['url'], 'upload_thumb' => $upload['thumb'], ); $response = rest_ensure_response( $retval ); /** * Fires after a list of members is fetched via the REST API. * * @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_media_upload_item', $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.