BP_REST_Attachments_Member_Cover_Endpoint::delete_item( WP_REST_Request $request )

Delete an existing user cover.


Parameters Parameters

$request

(WP_REST_Request) (Required) Full details about the request.


Top ↑

Return Return

(WP_REST_Response|WP_Error)


Source Source

File: bp-members/classes/class-bp-rest-attachments-member-cover-endpoint.php

	public function delete_item( $request ) {
		$request->set_param( 'context', 'edit' );

		$cover_url = bp_attachments_get_attachment(
			'url',
			array(
				'item_id' => $this->user->ID,
			)
		);

		$deleted = bp_attachments_delete_file(
			array(
				'item_id' => (int) $this->user->ID,
			)
		);

		if ( ! $deleted ) {
			return new WP_Error(
				'bp_rest_attachments_member_cover_delete_failed',
				__( 'Sorry, there was a problem deleting this user cover.', 'buddypress' ),
				array(
					'status' => 500,
				)
			);
		}

		// Build the response.
		$response = new WP_REST_Response();
		$response->set_data(
			array(
				'deleted'  => true,
				'previous' => $cover_url,
			)
		);

		/**
		 * Fires after a user cover is deleted via the REST API.
		 *
		 * @since 6.0.0
		 *
		 * @param WP_User           $user      The user object.
		 * @param WP_REST_Response  $response  The response data.
		 * @param WP_REST_Request   $request   The request sent to the API.
		 */
		do_action( 'bp_rest_attachments_member_cover_delete_item', $this->user, $response, $request );

		return $response;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.