WP_REST_Comments_Controller
- Since
- 4.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:17
Core controller used to access comments via the REST API.
Compatibility
- WordPress
- since 4.7.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 15
Every hook that fires from inside WP_REST_Comments_Controller, in the order it appears in the class, grouped by the method that fires it.
WP_REST_Comments_Controller::create_item_permissions_check()
- apply_filters( rest_allow_anonymous_comments )filter line 531
WP_REST_Comments_Controller::create_item()
- apply_filters( rest_pre_insert_comment )filter line 788
- do_action( rest_insert_comment )action line 819
- do_action( rest_after_insert_comment )action line 850
WP_REST_Comments_Controller::update_item()
- do_action( rest_insert_comment )action line 982
- do_action( rest_after_insert_comment )action line 1003
WP_REST_Comments_Controller::delete_item()
- apply_filters( rest_comment_trashable )filter line 1060
- do_action( rest_delete_comment )action line 1115
WP_REST_Comments_Controller::prepare_item_for_response()
- apply_filters( rest_prepare_comment )filter line 1137
- apply_filters( comment_text )filter line 1190
- apply_filters( rest_prepare_comment )filter line 1237
WP_REST_Comments_Controller::prepare_item_for_database()
- apply_filters( rest_preprocess_comment )filter line 1485
Properties · 1
$metaWP_REST_Comment_Meta_Fieldsprotected- Instance of a comment meta fields object.
Methods · 27
- __construct()Constructor.
- register_routes()Registers the routes for comments.
- get_items_permissions_check()Checks if a given request has access to read comments.
- get_items()Retrieves a list of comment items.
- get_comment()Get the comment, if the ID is valid.
- get_item_permissions_check()Checks if a given request has access to read the comment.
- get_item()Retrieves a comment.
- create_item_permissions_check()Checks if a given request has access to create a comment.
- create_item()Creates a comment.
- update_item_permissions_check()Checks if a given REST request has access to update a comment.
- update_item()Updates a comment.
- delete_item_permissions_check()Checks if a given request has access to delete a comment.
- delete_item()Deletes a comment.
- prepare_item_for_response()Prepares a single comment output for response.
- prepare_links()Prepares links for the request.
- normalize_query_param()Prepends internal property prefix to query parameters to match our response fields.
- prepare_status_response()Checks comment_approved to set comment status for single comment output.
- prepare_item_for_database()Prepares a single comment to be inserted into the database.
- get_item_schema()Retrieves the comment's schema, conforming to JSON Schema.
- get_collection_params()Retrieves the query params for collections.
- handle_status_param()Sets the comment_status of a given comment object when creating or updating a comment.
- check_read_post_permission()Checks if the post can be read.
- check_read_permission()Checks if the comment can be read.
- check_edit_permission()Checks if a comment can be edited or deleted.
- check_comment_author_email()Checks a comment author email for validity.
- check_is_comment_content_allowed()If empty comments are not allowed, checks if the provided comment content is not empty.
- check_post_type_supports_notes()Check if post type supports notes.
Source code
class WP_REST_Comments_Controller extends WP_REST_Controller { /** * Instance of a comment meta fields object. * * @since 4.7.0 * @var WP_REST_Comment_Meta_Fields */ protected $meta; /** * Constructor. * * @since 4.7.0 */ public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'comments'; $this->meta = new WP_REST_Comment_Meta_Fields(); } /** * Registers the routes for comments. * * @since 4.7.0 * * @see register_rest_route() */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 'args' => array( 'id' => array( 'description' => __( 'Unique identifier for the comment.' ), 'type' => 'integer', ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'password' => array( 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 'type' => 'string', ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), array(Changelog
Introduced in 4.7.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Method
check_post_type_supports_notes() added.verified against source4.7.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.