BP_REST_Reply_Endpoint::get_reply_revisions( int $reply_id )

Get revisions for reply.

Description

from: bbp_get_reply_revision_log()

Parameters

$reply_id

(Required) ID of the reply.

Return

(bool|void)

Source

File: bp-forums/classes/class-bp-rest-reply-endpoint.php

	protected function get_reply_revisions( $reply_id = 0 ) {

		// Create necessary variables.
		$reply_id = bbp_get_reply_id( $reply_id );

		// Show the topic reply log if this is a topic in a reply loop.
		if ( bbp_is_topic( $reply_id ) ) {
			return $this->topic_endpoint->get_topic_revisions( $reply_id );
		}

		// Get the reply revision log.
		$revision_log = bbp_get_reply_raw_revision_log( $reply_id );

		// Check reply and revision log exist.
		if ( empty( $reply_id ) || empty( $revision_log ) || ! is_array( $revision_log ) ) {
			return false;
		}

		// Get the actual revisions.
		$revisions = bbp_get_reply_revisions( $reply_id );
		if ( empty( $revisions ) ) {
			return false;
		}

		if ( empty( $revisions ) ) {
			return false;
		}

		$retval = array();

		// Loop through revisions.
		foreach ( (array) $revisions as $revision ) {

			if ( empty( $revision_log[ $revision->ID ] ) ) {
				$author_id = $revision->post_author;
				$reason    = '';
			} else {
				$author_id = $revision_log[ $revision->ID ]['author'];
				$reason    = $revision_log[ $revision->ID ]['reason'];
			}

			$retval[] = array(
				'time'        => esc_html( bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ) ),
				'author_id'   => $author_id,
				'author_name' => bbp_get_reply_author_display_name( $revision->ID ),
				'avatar'      => ( ! empty( $author_id ) ? get_avatar_url( $author_id, 300 ) : '' ),
				'reason'      => $reason,
			);
		}

		return apply_filters( 'bp_rest_bbp_get_reply_revision_log', $retval, $reply_id );
	}

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.