Make WordPress Core


Ignore:
Timestamp:
11/18/2016 06:52:19 PM (8 years ago)
Author:
rachelbaker
Message:

REST API: Remove the karma property and query parameter from the Comments 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r39290 r39292  
    122122
    123123        if ( ! current_user_can( 'edit_posts' ) ) {
    124             $protected_params = array( 'author', 'author_exclude', 'karma', 'author_email', 'type', 'status' );
     124            $protected_params = array( 'author', 'author_exclude', 'author_email', 'type', 'status' );
    125125            $forbidden_params = array();
    126126
     
    173173            'exclude'        => 'comment__not_in',
    174174            'include'        => 'comment__in',
    175             'karma'          => 'karma',
    176175            'offset'         => 'offset',
    177176            'order'          => 'order',
     
    198197
    199198        // Ensure certain parameter values default to empty strings.
    200         foreach ( array( 'author_email', 'karma', 'search' ) as $param ) {
     199        foreach ( array( 'author_email', 'search' ) as $param ) {
    201200            if ( ! isset( $prepared_args[ $param ] ) ) {
    202201                $prepared_args[ $param ] = '';
     
    373372        }
    374373
    375         // Limit who can set comment `author`, `karma` or `status` to anything other than the default.
     374        // Limit who can set comment `author` or `status` to anything other than the default.
    376375        if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
    377376            return new WP_Error( 'rest_comment_invalid_author', __( 'Comment author invalid.' ), array( 'status' => rest_authorization_required_code() ) );
    378         }
    379 
    380         if ( isset( $request['karma'] ) && $request['karma'] > 0 && ! current_user_can( 'moderate_comments' ) ) {
    381             return new WP_Error( 'rest_comment_invalid_karma', __( 'Sorry, you are not allowed to set karma for comments.' ), array( 'status' => rest_authorization_required_code() ) );
    382377        }
    383378
     
    818813                'raw'      => $comment->comment_content,
    819814            ),
    820             'karma'              => (int) $comment->comment_karma,
    821815            'link'               => get_comment_link( $comment ),
    822816            'status'             => $this->prepare_status_response( $comment->comment_approved ),
     
    10591053            // Comment type "comment" needs to be created as an empty string.
    10601054            $prepared_comment['comment_type'] = 'comment' === $request['type'] ? '' : $request['type'];
    1061         }
    1062 
    1063         if ( isset( $request['karma'] ) ) {
    1064             $prepared_comment['comment_karma'] = $request['karma'] ;
    10651055        }
    10661056
     
    11851175                    'context'      => array( 'view', 'edit' ),
    11861176                ),
    1187                 'karma'             => array(
    1188                     'description'  => __( 'Karma for the object.' ),
    1189                     'type'         => 'integer',
    1190                     'context'      => array( 'edit' ),
    1191                 ),
    11921177                'link'             => array(
    11931178                    'description'  => __( 'URL to the object.' ),
     
    13211306            ),
    13221307            'default'            => array(),
    1323         );
    1324 
    1325         $query_params['karma'] = array(
    1326             'default'           => null,
    1327             'description'       => __( 'Limit result set to that of a particular comment karma. Requires authorization.' ),
    1328             'type'              => 'integer',
    13291308        );
    13301309
Note: See TracChangeset for help on using the changeset viewer.