PHP Class WP_REST_Comments_Controller, wordpress

Inheritance: extends WP_REST_Controller
Datei anzeigen Open project: johnpbloch/wordpress Class Usage Examples

Protected Properties

Property Type Description
$meta WP_REST_Comment_Meta_Fields Instance of a comment meta fields object.

Public Methods

Method Description
__construct ( ) Constructor.
create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Creates a comment.
create_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean Checks if a given request has access to create a comment.
delete_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Deletes a comment.
delete_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean Checks if a given request has access to delete a comment.
get_collection_params ( ) : array Retrieves the query params for collections.
get_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Retrieves a comment.
get_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean Checks if a given request has access to read the comment.
get_item_schema ( ) : array Retrieves the comment's schema, conforming to JSON Schema.
get_items ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Retrieves a list of comment items.
get_items_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean Checks if a given request has access to read comments.
prepare_item_for_response ( WP_Comment $comment, WP_REST_Request $request ) : WP_REST_Response Prepares a single comment output for response.
register_routes ( ) Registers the routes for the objects of the controller.
update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Updates a comment.
update_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean Checks if a given REST request has access to update a comment.

Protected Methods

Method Description
check_edit_permission ( object $comment ) : boolean Checks if a comment can be edited or deleted.
check_read_permission ( WP_Comment $comment, WP_REST_Request $request ) : boolean Checks if the comment can be read.
check_read_post_permission ( WP_Post $post, WP_REST_Request $request ) : boolean Checks if the post can be read.
handle_status_param ( string | integer $new_status, integer $comment_id ) : boolean Sets the comment_status of a given comment object when creating or updating a comment.
normalize_query_param ( string $query_param ) : string Prepends internal property prefix to query parameters to match our response fields.
prepare_item_for_database ( WP_REST_Request $request ) : array | WP_Error Prepares a single comment to be inserted into the database.
prepare_links ( WP_Comment $comment ) : array Prepares links for the request.
prepare_status_response ( string | integer $comment_approved ) : string Checks comment_approved to set comment status for single comment output.

Method Details

__construct() public method

Constructor.
Since: 4.7.0
public __construct ( )

check_edit_permission() protected method

Checks if a comment can be edited or deleted.
Since: 4.7.0
protected check_edit_permission ( object $comment ) : boolean
$comment object Comment object.
return boolean Whether the comment can be edited or deleted.

check_read_permission() protected method

Checks if the comment can be read.
Since: 4.7.0
protected check_read_permission ( WP_Comment $comment, WP_REST_Request $request ) : boolean
$comment WP_Comment Comment object.
$request WP_REST_Request Request data to check.
return boolean Whether the comment can be read.

check_read_post_permission() protected method

Correctly handles posts with the inherit status.
Since: 4.7.0
protected check_read_post_permission ( WP_Post $post, WP_REST_Request $request ) : boolean
$post WP_Post Post object.
$request WP_REST_Request Request data to check.
return boolean Whether post can be read.

create_item() public method

Creates a comment.
Since: 4.7.0
public create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, or error object on failure.

create_item_permissions_check() public method

Checks if a given request has access to create a comment.
Since: 4.7.0
public create_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean
$request WP_REST_Request Full details about the request.
return WP_Error | boolean True if the request has access to create items, error object otherwise.

delete_item() public method

Deletes a comment.
Since: 4.7.0
public delete_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, or error object on failure.

delete_item_permissions_check() public method

Checks if a given request has access to delete a comment.
Since: 4.7.0
public delete_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean
$request WP_REST_Request Full details about the request.
return WP_Error | boolean True if the request has access to delete the item, error object otherwise.

get_collection_params() public method

Retrieves the query params for collections.
Since: 4.7.0
public get_collection_params ( ) : array
return array Comments collection parameters.

get_item() public method

Retrieves a comment.
Since: 4.7.0
public get_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, or error object on failure.

get_item_permissions_check() public method

Checks if a given request has access to read the comment.
Since: 4.7.0
public get_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean
$request WP_REST_Request Full details about the request.
return WP_Error | boolean True if the request has read access for the item, error object otherwise.

get_item_schema() public method

Retrieves the comment's schema, conforming to JSON Schema.
Since: 4.7.0
public get_item_schema ( ) : array
return array

get_items() public method

Retrieves a list of comment items.
Since: 4.7.0
public get_items ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, or error object on failure.

get_items_permissions_check() public method

Checks if a given request has access to read comments.
Since: 4.7.0
public get_items_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean
$request WP_REST_Request Full details about the request.
return WP_Error | boolean True if the request has read access, error object otherwise.

handle_status_param() protected method

Sets the comment_status of a given comment object when creating or updating a comment.
Since: 4.7.0
protected handle_status_param ( string | integer $new_status, integer $comment_id ) : boolean
$new_status string | integer New comment status.
$comment_id integer Comment ID.
return boolean Whether the status was changed.

normalize_query_param() protected method

Prepends internal property prefix to query parameters to match our response fields.
Since: 4.7.0
protected normalize_query_param ( string $query_param ) : string
$query_param string Query parameter.
return string The normalized query parameter.

prepare_item_for_database() protected method

Prepares a single comment to be inserted into the database.
Since: 4.7.0
protected prepare_item_for_database ( WP_REST_Request $request ) : array | WP_Error
$request WP_REST_Request Request object.
return array | WP_Error Prepared comment, otherwise WP_Error object.

prepare_item_for_response() public method

Prepares a single comment output for response.
Since: 4.7.0
public prepare_item_for_response ( WP_Comment $comment, WP_REST_Request $request ) : WP_REST_Response
$comment WP_Comment Comment object.
$request WP_REST_Request Request object.
return WP_REST_Response Response object.

prepare_status_response() protected method

Checks comment_approved to set comment status for single comment output.
Since: 4.7.0
protected prepare_status_response ( string | integer $comment_approved ) : string
$comment_approved string | integer comment status.
return string Comment status.

register_routes() public method

Registers the routes for the objects of the controller.
Since: 4.7.0
public register_routes ( )

update_item() public method

Updates a comment.
Since: 4.7.0
public update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response Response object on success, or error object on failure.

update_item_permissions_check() public method

Checks if a given REST request has access to update a comment.
Since: 4.7.0
public update_item_permissions_check ( WP_REST_Request $request ) : WP_Error | boolean
$request WP_REST_Request Full details about the request.
return WP_Error | boolean True if the request has access to update the item, error object otherwise.

Property Details

$meta protected_oe property

Instance of a comment meta fields object.
Since: 4.7.0
protected WP_REST_Comment_Meta_Fields $meta
return WP_REST_Comment_Meta_Fields