BP_REST_Messages_Actions_Endpoint::action_items( WP_REST_Request $request )

Perform Action on the Message Thread.

Description

Parameters

$request

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

Return

(WP_REST_Response) | WP_Error

Source

File: bp-messages/classes/class-bp-rest-messages-actions-endpoint.php

	public function action_items( $request ) {
		$action    = $request->get_param( 'action' );
		$value     = $request->get_param( 'value' );
		$thread_id = $request->get_param( 'id' );

		switch ( $action ) {
			case 'delete_messages':
				$retval = $this->rest_delete_messages( $thread_id, $value );
				break;
			case 'hide_thread':
				$retval = $this->rest_hide_thread( $thread_id, $value );
				break;
			case 'unread':
				$retval = $this->rest_unread_thread( $thread_id, $value );
				break;
		}

		if ( is_wp_error( $retval ) ) {
			return $retval;
		}

		// Clear recipients cache after update hidden property.
		wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );

		$thread = new BP_Messages_Thread( $thread_id );

		$retval = $this->prepare_response_for_collection(
			$this->message_endppoint->prepare_item_for_response( $thread, $request )
		);

		$response = rest_ensure_response( $retval );

		/**
		 * Fires after a thread is fetched via the REST API.
		 *
		 * @param BP_Messages_Thread $thread  Thread object.
		 * @param WP_REST_Response   $retval  The response data.
		 * @param WP_REST_Request    $request The request sent to the API.
		 *
		 * @since 0.1.0
		 */
		do_action( 'bp_rest_messages_action_items', $thread, $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.