PHP 8.2.31
Preview: ProductReviewSchema.php Size: 6.12 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductReviewSchema.php

<?php
namespace Automattic\WooCommerce\StoreApi\Schemas\V1;

use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\SchemaController;

/**
 * ProductReviewSchema class.
 */
class ProductReviewSchema extends AbstractSchema {
	/**
	 * The schema item name.
	 *
	 * @var string
	 */
	protected $title = 'product_review';

	/**
	 * The schema item identifier.
	 *
	 * @var string
	 */
	const IDENTIFIER = 'product-review';

	/**
	 * Image attachment schema instance.
	 *
	 * @var ImageAttachmentSchema
	 */
	protected $image_attachment_schema;

	/**
	 * Constructor.
	 *
	 * @param ExtendSchema     $extend Rest Extending instance.
	 * @param SchemaController $controller Schema Controller instance.
	 */
	public function __construct( ExtendSchema $extend, SchemaController $controller ) {
		parent::__construct( $extend, $controller );
		$this->image_attachment_schema = $this->controller->get( ImageAttachmentSchema::IDENTIFIER );
	}

	/**
	 * Product review schema properties.
	 *
	 * @return array
	 */
	public function get_properties() {
		$properties = [
			'id'                     => [
				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
				'type'        => 'integer',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'date_created'           => [
				'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
				'type'        => 'string',
				'format'      => 'date-time',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'formatted_date_created' => [
				'description' => __( "The date the review was created, in the site's timezone in human-readable format.", 'woocommerce' ),
				'type'        => 'string',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'date_created_gmt'       => [
				'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
				'type'        => 'string',
				'format'      => 'date-time',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'product_id'             => [
				'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ),
				'type'        => 'integer',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'product_name'           => [
				'description' => __( 'Name of the product that the review belongs to.', 'woocommerce' ),
				'type'        => 'string',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'product_permalink'      => [
				'description' => __( 'Permalink of the product that the review belongs to.', 'woocommerce' ),
				'type'        => 'string',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'product_image'          => [
				'description' => __( 'Image of the product that the review belongs to.', 'woocommerce' ),
				'type'        => 'object',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
				'properties'  => $this->image_attachment_schema->get_properties(),
			],
			'reviewer'               => [
				'description' => __( 'Reviewer name.', 'woocommerce' ),
				'type'        => 'string',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'review'                 => [
				'description' => __( 'The content of the review.', 'woocommerce' ),
				'type'        => 'string',
				'context'     => [ 'view', 'edit' ],
				'arg_options' => [
					'sanitize_callback' => 'wp_filter_post_kses',
				],
				'readonly'    => true,
			],
			'rating'                 => [
				'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
				'type'        => 'integer',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
			'verified'               => [
				'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
				'type'        => 'boolean',
				'context'     => [ 'view', 'edit' ],
				'readonly'    => true,
			],
		];

		if ( get_option( 'show_avatars' ) ) {
			$avatar_properties = array();
			$avatar_sizes      = rest_get_avatar_sizes();

			foreach ( $avatar_sizes as $size ) {
				$avatar_properties[ $size ] = array(
					/* translators: %d: avatar image size in pixels */
					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ),
					'type'        => 'string',
					'format'      => 'uri',
					'context'     => array( 'embed', 'view', 'edit' ),
				);
			}
			$properties['reviewer_avatar_urls'] = array(
				'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ),
				'type'        => 'object',
				'context'     => array( 'view', 'edit' ),
				'readonly'    => true,
				'properties'  => $avatar_properties,
			);
		}

		return $properties;
	}

	/**
	 * Convert a WooCommerce product into an object suitable for the response.
	 *
	 * @param \WP_Comment $review Product review object.
	 * @return array
	 */
	public function get_item_response( $review ) {
		$rating = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
		return [
			'id'                     => (int) $review->comment_ID,
			'date_created'           => wc_rest_prepare_date_response( $review->comment_date ),
			'formatted_date_created' => get_comment_date( 'F j, Y', $review->comment_ID ),
			'date_created_gmt'       => wc_rest_prepare_date_response( $review->comment_date_gmt ),
			'product_id'             => (int) $review->comment_post_ID,
			'product_name'           => get_the_title( (int) $review->comment_post_ID ),
			'product_permalink'      => get_permalink( (int) $review->comment_post_ID ),
			'product_image'          => $this->image_attachment_schema->get_item_response( get_post_thumbnail_id( (int) $review->comment_post_ID ) ),
			'reviewer'               => $review->comment_author,
			'review'                 => wpautop( $review->comment_content ),
			'rating'                 => $rating,
			'verified'               => wc_review_is_from_verified_owner( $review->comment_ID ),
			'reviewer_avatar_urls'   => rest_get_avatar_urls( $review->comment_author_email ),
		];
	}
}

Directory Contents

Dirs: 2 × Files: 28

Name Size Perms Modified Actions
Agentic DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
AI DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
10.58 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
12.97 KB lrw-r--r-- 2026-05-11 17:17:08
Edit Download
427 B lrw-r--r-- 2023-12-27 00:45:02
Edit Download
4.46 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
2.98 KB lrw-r--r-- 2025-06-30 17:49:22
Edit Download
2.21 KB lrw-r--r-- 2024-08-27 23:04:44
Edit Download
2.12 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
7.54 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
17.07 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
11.37 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
752 B lrw-r--r-- 2023-12-27 00:45:02
Edit Download
15.05 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1.12 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
3.32 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
11.27 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
2.41 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
2.20 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
7.16 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
12.86 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
673 B lrw-r--r-- 2024-10-21 23:53:16
Edit Download
2.50 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
3.49 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
3.50 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
4.95 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.12 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
36.58 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.84 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
2.15 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).