Title: WP_REST_Comments_Controller::get_item_schema
Published: December 6, 2016
Last modified: February 24, 2026

---

# WP_REST_Comments_Controller::get_item_schema(): array

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#wp--skip-link--target)

Retrieves the comment’s schema, conforming to JSON Schema.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#return)󠁿

 array

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#source)󠁿

    ```php
    public function get_item_schema() {
    	if ( $this->schema ) {
    		return $this->add_additional_fields_schema( $this->schema );
    	}

    	$schema = array(
    		'$schema'    => 'http://json-schema.org/draft-04/schema#',
    		'title'      => 'comment',
    		'type'       => 'object',
    		'properties' => array(
    			'id'                => array(
    				'description' => __( 'Unique identifier for the comment.' ),
    				'type'        => 'integer',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'readonly'    => true,
    			),
    			'author'            => array(
    				'description' => __( 'The ID of the user object, if author was a user.' ),
    				'type'        => 'integer',
    				'context'     => array( 'view', 'edit', 'embed' ),
    			),
    			'author_email'      => array(
    				'description' => __( 'Email address for the comment author.' ),
    				'type'        => 'string',
    				'format'      => 'email',
    				'context'     => array( 'edit' ),
    				'arg_options' => array(
    					'sanitize_callback' => array( $this, 'check_comment_author_email' ),
    					'validate_callback' => null, // Skip built-in validation of 'email'.
    				),
    			),
    			'author_ip'         => array(
    				'description' => __( 'IP address for the comment author.' ),
    				'type'        => 'string',
    				'format'      => 'ip',
    				'context'     => array( 'edit' ),
    			),
    			'author_name'       => array(
    				'description' => __( 'Display name for the comment author.' ),
    				'type'        => 'string',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'arg_options' => array(
    					'sanitize_callback' => 'sanitize_text_field',
    				),
    			),
    			'author_url'        => array(
    				'description' => __( 'URL for the comment author.' ),
    				'type'        => 'string',
    				'format'      => 'uri',
    				'context'     => array( 'view', 'edit', 'embed' ),
    			),
    			'author_user_agent' => array(
    				'description' => __( 'User agent for the comment author.' ),
    				'type'        => 'string',
    				'context'     => array( 'edit' ),
    				'arg_options' => array(
    					'sanitize_callback' => 'sanitize_text_field',
    				),
    			),
    			'content'           => array(
    				'description' => __( 'The content for the comment.' ),
    				'type'        => 'object',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'arg_options' => array(
    					'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database().
    					'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database().
    				),
    				'properties'  => array(
    					'raw'      => array(
    						'description' => __( 'Content for the comment, as it exists in the database.' ),
    						'type'        => 'string',
    						'context'     => array( 'edit' ),
    					),
    					'rendered' => array(
    						'description' => __( 'HTML content for the comment, transformed for display.' ),
    						'type'        => 'string',
    						'context'     => array( 'view', 'edit', 'embed' ),
    						'readonly'    => true,
    					),
    				),
    			),
    			'date'              => array(
    				'description' => __( "The date the comment was published, in the site's timezone." ),
    				'type'        => 'string',
    				'format'      => 'date-time',
    				'context'     => array( 'view', 'edit', 'embed' ),
    			),
    			'date_gmt'          => array(
    				'description' => __( 'The date the comment was published, as GMT.' ),
    				'type'        => 'string',
    				'format'      => 'date-time',
    				'context'     => array( 'view', 'edit' ),
    			),
    			'link'              => array(
    				'description' => __( 'URL to the comment.' ),
    				'type'        => 'string',
    				'format'      => 'uri',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'readonly'    => true,
    			),
    			'parent'            => array(
    				'description' => __( 'The ID for the parent of the comment.' ),
    				'type'        => 'integer',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'default'     => 0,
    			),
    			'post'              => array(
    				'description' => __( 'The ID of the associated post object.' ),
    				'type'        => 'integer',
    				'context'     => array( 'view', 'edit' ),
    				'default'     => 0,
    			),
    			'status'            => array(
    				'description' => __( 'State of the comment.' ),
    				'type'        => 'string',
    				'context'     => array( 'view', 'edit' ),
    				'arg_options' => array(
    					'sanitize_callback' => 'sanitize_key',
    				),
    			),
    			'type'              => array(
    				'description' => __( 'Type of the comment.' ),
    				'type'        => 'string',
    				'context'     => array( 'view', 'edit', 'embed' ),
    				'readonly'    => true,
    				'default'     => 'comment',
    			),
    		),
    	);

    	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.' ), $size ),
    				'type'        => 'string',
    				'format'      => 'uri',
    				'context'     => array( 'embed', 'view', 'edit' ),
    			);
    		}

    		$schema['properties']['author_avatar_urls'] = array(
    			'description' => __( 'Avatar URLs for the comment author.' ),
    			'type'        => 'object',
    			'context'     => array( 'view', 'edit', 'embed' ),
    			'readonly'    => true,
    			'properties'  => $avatar_properties,
    		);
    	}

    	$schema['properties']['meta'] = $this->meta->get_field_schema();

    	$this->schema = $schema;

    	return $this->add_additional_fields_schema( $this->schema );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L1487)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L1487-L1646)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#related)󠁿

| Uses | Description | 
| [rest_get_avatar_sizes()](https://developer.wordpress.org/reference/functions/rest_get_avatar_sizes/)`wp-includes/rest-api.php` |

Retrieves the pixel sizes for avatars.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#)

| Used by | Description | 
| [WP_REST_Comments_Controller::update_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/update_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Updates a comment.

  | 
| [WP_REST_Comments_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Creates a comment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/get_item_schema/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_comments_controller%2Fget_item_schema%2F)
before being able to contribute a note or feedback.