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
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | 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.