Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
089448c
Define each argument for updating comments and set the sanitization c…
rachelbaker May 18, 2015
6e069cc
Add handling for update comment arguments in `prepare_item_for_update…
rachelbaker May 18, 2015
9694f0e
Allow users with `moderate_comments` to set comment karma
rachelbaker May 18, 2015
de1b7bb
Return an error if the user is creating a comment tries to set the au…
rachelbaker May 18, 2015
6f8fe89
Don't set a default for the comment_type
rachelbaker May 18, 2015
9083a08
Remove double sanitization on create and update comment args
rachelbaker May 18, 2015
a3a64e3
Expand update comment tests to include added args.
rachelbaker May 18, 2015
15ff9f4
Add tests for creating comments karma and author error responses.
rachelbaker May 18, 2015
26e1d72
Merge branch 'develop' into fix-940
rachelbaker Jun 6, 2015
750d4c4
Merge branch 'develop' into fix-940
rachelbaker Jun 13, 2015
deb8ead
Remove duplicate `author` param setting in create comment arguments
rachelbaker Jun 13, 2015
db1d6b6
Merge branch 'develop' into fix-940
rachelbaker Jun 14, 2015
3050f78
Remove duplicate author argument in comment create endpoint.
rachelbaker Jun 14, 2015
ebb0497
Add missing `author_name` parameter to the create and edit comment en…
rachelbaker Jun 15, 2015
3e1e25d
Remove prepare_item_for_update method in favor of using prepare_item_…
rachelbaker Jun 15, 2015
4c0881c
Add unit test for updating a comment with the date_gmt argument
rachelbaker Jun 17, 2015
96436e7
Return error for comments that try to change type with test
rachelbaker Jun 17, 2015
15df46e
Remove type casting from prepare_item_for_database method
rachelbaker Jun 17, 2015
30988dc
Allow the status param to be set when creating comments if user has m…
rachelbaker Jun 17, 2015
a08d2fb
Add tests for setting the status parameter when creating comments
rachelbaker Jun 17, 2015
fb95029
Add test_ prefix to comment tests where missing
rachelbaker Jun 17, 2015
e1191d0
Fix bugs in test methods
rachelbaker Jun 17, 2015
a2728a0
Escape smart quotes in test string
rachelbaker Jun 17, 2015
056d8fe
Correct return value on prepare_item_for_database
rachelbaker Jun 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add handling for update comment arguments in `prepare_item_for_update…
…` method
  • Loading branch information
rachelbaker committed May 18, 2015
commit 6e069cc51ddddb34cd88f9252782d4efcd8dab4e
22 changes: 22 additions & 0 deletions lib/endpoints/class-wp-rest-comments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ protected function prepare_item_for_database( $request ) {
/**
* Prepare a single comment for database update.
*
* `wp_update_comment()` doesn't allow us to set `comment_date_gmt`.
*
* @param WP_REST_Request $request Request object.
* @return array $prepared_comment
*/
Expand All @@ -661,6 +663,18 @@ protected function prepare_item_for_update( $request ) {
$prepared_comment['comment_content'] = $request['content'];
}

if ( isset( $request['post'] ) ) {
$prepared_comment['comment_post_ID'] = (int) $request['post'];
}

if ( isset( $request['parent'] ) ) {
$prepared_comment['comment_parent'] = (int) $request['parent'];
}

if ( isset( $request['author'] ) ) {
$prepared_comment['user_id'] = (int) $request['author'];
}

if ( isset( $request['author_name'] ) ) {
$prepared_comment['comment_author'] = sanitize_text_field( $request['author_name'] );
}
Expand All @@ -673,6 +687,14 @@ protected function prepare_item_for_update( $request ) {
$prepared_comment['comment_author_url'] = esc_url_raw( $request['author_url'] );
}

if ( isset( $request['type'] ) ) {
$prepared_comment['comment_type'] = $request['type'];
}

if ( isset( $request['karma'] ) ) {
$prepared_comment['comment_karma'] = (int) $request['karma'] ;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think casting shouldn't be needed as this is sanitized with absint

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joehoyle addressed in 15df46e

}

if ( ! empty( $request['date'] ) ) {
$prepared_comment['comment_date'] = $request['date'];
}
Expand Down