WordPress at Your Fingertips
function is not described

WC_REST_Product_Reviews_Controller::get_review() protected WC 3.5.0

Get the reivew, if the ID is valid.

{} It's a method of the class: WC_REST_Product_Reviews_Controller{}

No Hooks.

Return

WP_Comment|WP_Error. Comment object if ID is valid, WP_Error otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_review( $id );
$id(int) (required)
Supplied ID.

Changelog

Since 3.5.0 Introduced.

Code of WC_REST_Product_Reviews_Controller::get_review() WC 5.7.1

protected function get_review( $id ) {
	$id    = (int) $id;
	$error = new WP_Error( 'woocommerce_rest_review_invalid_id', __( 'Invalid review ID.', 'woocommerce' ), array( 'status' => 404 ) );

	if ( 0 >= $id ) {
		return $error;
	}

	$review = get_comment( $id );
	if ( empty( $review ) ) {
		return $error;
	}

	if ( ! empty( $review->comment_post_ID ) ) {
		$post = get_post( (int) $review->comment_post_ID );

		if ( 'product' !== get_post_type( (int) $review->comment_post_ID ) ) {
			return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
		}
	}

	return $review;
}