Skip to content

Commit

Permalink
REST API: Remove the karma property and query parameter from the Co…
Browse files Browse the repository at this point in the history
…mments endpoints.

WordPress has not used the `karma` property internally for the past 8 years. There is no need to expose it in the REST API endpoints. Sites that use `karma` can include it using the `register_rest_field()` function.

Props dd32, danielbachhuber.
Fixes #38821.
Built from https://develop.svn.wordpress.org/trunk@39292


git-svn-id: http://core.svn.wordpress.org/trunk@39232 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
rachelbaker committed Nov 18, 2016
1 parent 7d96057 commit 3f6131c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
Expand Up @@ -121,7 +121,7 @@ public function get_items_permissions_check( $request ) {
}

if ( ! current_user_can( 'edit_posts' ) ) {
$protected_params = array( 'author', 'author_exclude', 'karma', 'author_email', 'type', 'status' );
$protected_params = array( 'author', 'author_exclude', 'author_email', 'type', 'status' );
$forbidden_params = array();

foreach ( $protected_params as $param ) {
Expand Down Expand Up @@ -172,7 +172,6 @@ public function get_items( $request ) {
'author_exclude' => 'author__not_in',
'exclude' => 'comment__not_in',
'include' => 'comment__in',
'karma' => 'karma',
'offset' => 'offset',
'order' => 'order',
'parent' => 'parent__in',
Expand All @@ -197,7 +196,7 @@ public function get_items( $request ) {
}

// Ensure certain parameter values default to empty strings.
foreach ( array( 'author_email', 'karma', 'search' ) as $param ) {
foreach ( array( 'author_email', 'search' ) as $param ) {
if ( ! isset( $prepared_args[ $param ] ) ) {
$prepared_args[ $param ] = '';
}
Expand Down Expand Up @@ -372,15 +371,11 @@ public function create_item_permissions_check( $request ) {
return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
}

// Limit who can set comment `author`, `karma` or `status` to anything other than the default.
// Limit who can set comment `author` or `status` to anything other than the default.
if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
return new WP_Error( 'rest_comment_invalid_author', __( 'Comment author invalid.' ), array( 'status' => rest_authorization_required_code() ) );
}

if ( isset( $request['karma'] ) && $request['karma'] > 0 && ! current_user_can( 'moderate_comments' ) ) {
return new WP_Error( 'rest_comment_invalid_karma', __( 'Sorry, you are not allowed to set karma for comments.' ), array( 'status' => rest_authorization_required_code() ) );
}

if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) {
return new WP_Error( 'rest_comment_invalid_status', __( 'Sorry, you are not allowed to set status for comments.' ), array( 'status' => rest_authorization_required_code() ) );
}
Expand Down Expand Up @@ -817,7 +812,6 @@ public function prepare_item_for_response( $comment, $request ) {
'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
'raw' => $comment->comment_content,
),
'karma' => (int) $comment->comment_karma,
'link' => get_comment_link( $comment ),
'status' => $this->prepare_status_response( $comment->comment_approved ),
'type' => get_comment_type( $comment->comment_ID ),
Expand Down Expand Up @@ -1060,10 +1054,6 @@ protected function prepare_item_for_database( $request ) {
$prepared_comment['comment_type'] = 'comment' === $request['type'] ? '' : $request['type'];
}

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

if ( ! empty( $request['date'] ) ) {
$date_data = rest_get_date_with_gmt( $request['date'] );

Expand Down Expand Up @@ -1184,11 +1174,6 @@ public function get_item_schema() {
'format' => 'date-time',
'context' => array( 'view', 'edit' ),
),
'karma' => array(
'description' => __( 'Karma for the object.' ),
'type' => 'integer',
'context' => array( 'edit' ),
),
'link' => array(
'description' => __( 'URL to the object.' ),
'type' => 'string',
Expand Down Expand Up @@ -1322,12 +1307,6 @@ public function get_collection_params() {
'default' => array(),
);

$query_params['karma'] = array(
'default' => null,
'description' => __( 'Limit result set to that of a particular comment karma. Requires authorization.' ),
'type' => 'integer',
);

$query_params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of comments.' ),
'type' => 'integer',
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-beta4-39291';
$wp_version = '4.7-beta4-39292';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 3f6131c

Please sign in to comment.