BP_REST_Media_Albums_Endpoint::create_item( WP_REST_Request $request )
Create medias.
Description
Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-media/classes/class-bp-rest-media-albums-endpoint.php
public function create_item( $request ) { $args = array( 'upload_ids' => $request['upload_ids'], 'privacy' => $request['privacy'], 'title' => $request['title'], 'user_id' => ( ! empty( $request['user_id'] ) ? (int) $request['user_id'] : get_current_user_id() ), ); if ( empty( $request['title'] ) ) { return new WP_Error( 'bp_rest_no_album_title_not_found', __( 'Sorry, you are not allowed to create a Album.', 'buddyboss' ), array( 'status' => 400, ) ); } if ( isset( $request['group_id'] ) && ! empty( $request['group_id'] ) ) { $args['group_id'] = $request['group_id']; } /** * Filter the query arguments for the request. * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ $args = apply_filters( 'bp_rest_media_albums_create_items_query_args', $args, $request ); $album = $this->bp_rest_create_media_album( $args ); if ( is_wp_error( $album ) ) { return $album; } $medias = $this->assemble_response_data( array( 'album_ids' => $album['album_id'] ) ); $retval = array( 'created' => $album['created'], 'error' => $album['error'], ); foreach ( $medias['albums'] as $album ) { $retval['album'] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $album, $request ) ); } $response = rest_ensure_response( $retval ); /** * Fires after a Media is created 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_album_create_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.