BP_REST_Attachments_Member_Cover_Endpoint::delete_item( WP_REST_Request $request )

Delete an existing user cover.

Description

Parameters

$request

(Required) Full details about the request.

Return

(WP_REST_Response) | WP_Error

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.', 'buddyboss' ),
				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.
		 *
		 * @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.
		 *
		 * @since 0.1.0
		 */
		do_action( 'bp_rest_attachments_member_cover_delete_item', $this->user, $response, $request );

		return $response;
	}

Changelog

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.