BP_REST_Media_Albums_Endpoint::update_item( WP_REST_Request $request )
Update a single album.
Description
Parameters
- $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 update_item( $request ) { $medias = $this->assemble_response_data( array( 'album_ids' => array( $request['id'] ) ) ); if ( empty( $medias['albums'] ) ) { return new WP_Error( 'bp_rest_album_invalid_id', __( 'Invalid Album ID.', 'buddyboss' ), array( 'status' => 404, ) ); } $album = end( $medias['albums'] ); $args = array( 'id' => $album->id, 'title' => $album->title, 'privacy' => $album->privacy, 'user_id' => $album->user_id, 'group_id' => $album->group_id, ); if ( isset( $request['title'] ) && ! empty( $request['title'] ) ) { $args['title'] = $request['title']; } if ( isset( $request['privacy'] ) && ! empty( $request['privacy'] ) && $album->privacy !== $request['privacy'] ) { $args['privacy'] = $request['privacy']; } /** * 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_update_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( 'updated' => $album['updated'], '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 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_update_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.