WC_REST_Product_Reviews_Controller::get_review()protectedWC 3.5.0

Get the reivew, if the ID is valid.

Метод класса: WC_REST_Product_Reviews_Controller{}

Хуков нет.

Возвращает

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

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_review( $id );
$id(int) (обязательный)
Supplied ID.

Список изменений

С версии 3.5.0 Введена.

Код WC_REST_Product_Reviews_Controller::get_review() WC 8.7.0

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;
}