Make WordPress Core

Ticket #38821: 38821.2.diff

File 38821.2.diff, 9.4 KB (added by danielbachhuber, 7 years ago)

Remove all traces of karma

  • src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
    index ccd172f..32d9db3 100644
    a b class WP_REST_Comments_Controller extends WP_REST_Controller { 
    121121                }
    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
    127127                        foreach ( $protected_params as $param ) {
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    172172                        'author_exclude' => 'author__not_in',
    173173                        'exclude'        => 'comment__not_in',
    174174                        'include'        => 'comment__in',
    175                         'karma'          => 'karma',
    176175                        'offset'         => 'offset',
    177176                        'order'          => 'order',
    178177                        'parent'         => 'parent__in',
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    197196                }
    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 ] = '';
    203202                        }
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    377376                        return new WP_Error( 'rest_comment_invalid_author', __( 'Comment author invalid.' ), array( 'status' => rest_authorization_required_code() ) );
    378377                }
    379378
    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() ) );
    382                 }
    383 
    384379                if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) {
    385380                        return new WP_Error( 'rest_comment_invalid_status', __( 'Sorry, you are not allowed to set status for comments.' ), array( 'status' => rest_authorization_required_code() ) );
    386381                }
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    812807                                'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
    813808                                'raw'      => $comment->comment_content,
    814809                        ),
    815                         'karma'              => (int) $comment->comment_karma,
    816810                        'link'               => get_comment_link( $comment ),
    817811                        'status'             => $this->prepare_status_response( $comment->comment_approved ),
    818812                        'type'               => get_comment_type( $comment->comment_ID ),
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    10551049                        $prepared_comment['comment_type'] = 'comment' === $request['type'] ? '' : $request['type'];
    10561050                }
    10571051
    1058                 if ( isset( $request['karma'] ) ) {
    1059                         $prepared_comment['comment_karma'] = $request['karma'] ;
    1060                 }
    1061 
    10621052                if ( ! empty( $request['date'] ) ) {
    10631053                        $date_data = rest_get_date_with_gmt( $request['date'] );
    10641054
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    11791169                                        'format'       => 'date-time',
    11801170                                        'context'      => array( 'view', 'edit' ),
    11811171                                ),
    1182                                 'karma'             => array(
    1183                                         'description'  => __( 'Karma for the object.' ),
    1184                                         'type'         => 'integer',
    1185                                         'context'      => array( 'edit' ),
    1186                                 ),
    11871172                                'link'             => array(
    11881173                                        'description'  => __( 'URL to the object.' ),
    11891174                                        'type'         => 'string',
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    13171302                        'default'            => array(),
    13181303                );
    13191304
    1320                 $query_params['karma'] = array(
    1321                         'default'           => null,
    1322                         'description'       => __( 'Limit result set to that of a particular comment karma. Requires authorization.' ),
    1323                         'type'              => 'integer',
    1324                 );
    1325 
    13261305                $query_params['offset'] = array(
    13271306                        'description'        => __( 'Offset the result set by a specific number of comments.' ),
    13281307                        'type'               => 'integer',
  • tests/phpunit/tests/rest-api/rest-comments-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
    index 33ac37d..df88734 100644
    a b class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    135135                        'context',
    136136                        'exclude',
    137137                        'include',
    138                         'karma',
    139138                        'offset',
    140139                        'order',
    141140                        'orderby',
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    11351134                $this->assertErrorResponse( 'rest_comment_invalid_author', $response, 403 );
    11361135        }
    11371136
    1138         public function test_create_comment_karma_without_permission() {
    1139                 wp_set_current_user( self::$subscriber_id );
    1140 
    1141                 $params = array(
    1142                         'post'         => self::$post_id,
    1143                         'author_name'  => 'Homer Jay Simpson',
    1144                         'author_email' => 'chunkylover53@aol.com',
    1145                         'author_url'   => 'http://compuglobalhypermeganet.com',
    1146                         'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1147                         'author'       => self::$subscriber_id,
    1148                         'karma'        => 100,
    1149                 );
    1150 
    1151                 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1152                 $request->add_header( 'content-type', 'application/json' );
    1153                 $request->set_body( wp_json_encode( $params ) );
    1154                 $response = $this->server->dispatch( $request );
    1155 
    1156                 $this->assertErrorResponse( 'rest_comment_invalid_karma', $response, 403 );
    1157         }
    1158 
    11591137        public function test_create_comment_invalid_post() {
    11601138                wp_set_current_user( self::$subscriber_id );
    11611139
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    11761154                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    11771155        }
    11781156
    1179         public function test_create_comment_karma_invalid_value() {
    1180                 wp_set_current_user( self::$subscriber_id );
    1181 
    1182                 $params = array(
    1183                         'post'           => self::$post_id,
    1184                         'author_name'  => 'Homer Jay Simpson',
    1185                         'author_email' => 'chunkylover53@aol.com',
    1186                         'author_url'   => 'http://compuglobalhypermeganet.com',
    1187                         'content'         => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1188                         'author'           => self::$subscriber_id,
    1189                         'karma'         => 'themostkarmaever',
    1190                 );
    1191 
    1192                 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1193                 $request->add_header( 'content-type', 'application/json' );
    1194                 $request->set_body( wp_json_encode( $params ) );
    1195                 $response = $this->server->dispatch( $request );
    1196 
    1197                 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    1198         }
    1199 
    12001157        public function test_create_comment_status_without_permission() {
    12011158                wp_set_current_user( self::$subscriber_id );
    12021159
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    16231580                        'author_ip'    => '4.4.4.4',
    16241581                        'content'      => 'Testing.',
    16251582                        'date'         => '2014-11-07T10:14:25',
    1626                         'karma'        => 100,
    16271583                        'post'         => $post_id,
    16281584                );
    16291585                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    16421598                $this->assertEquals( $params['author_email'], $comment['author_email'] );
    16431599                $this->assertEquals( $params['author_ip'], $comment['author_ip'] );
    16441600                $this->assertEquals( $params['post'], $comment['post'] );
    1645                 $this->assertEquals( $params['karma'], $comment['karma'] );
    16461601
    16471602                $this->assertEquals( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] );
    16481603                $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] );
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    21972152                $response = $this->server->dispatch( $request );
    21982153                $data = $response->get_data();
    21992154                $properties = $data['schema']['properties'];
    2200                 $this->assertEquals( 18, count( $properties ) );
     2155                $this->assertEquals( 17, count( $properties ) );
    22012156                $this->assertArrayHasKey( 'id', $properties );
    22022157                $this->assertArrayHasKey( 'author', $properties );
    22032158                $this->assertArrayHasKey( 'author_avatar_urls', $properties );
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    22092164                $this->assertArrayHasKey( 'content', $properties );
    22102165                $this->assertArrayHasKey( 'date', $properties );
    22112166                $this->assertArrayHasKey( 'date_gmt', $properties );
    2212                 $this->assertArrayHasKey( 'karma', $properties );
    22132167                $this->assertArrayHasKey( 'link', $properties );
    22142168                $this->assertArrayHasKey( 'meta', $properties );
    22152169                $this->assertArrayHasKey( 'parent', $properties );
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    23532307                        $this->assertEquals( $comment->comment_author_IP, $data['author_ip'] );
    23542308                        $this->assertEquals( $comment->comment_agent, $data['author_user_agent'] );
    23552309                        $this->assertEquals( $comment->comment_content, $data['content']['raw'] );
    2356                         $this->assertEquals( $comment->comment_karma, $data['karma'] );
    23572310                }
    23582311
    23592312                if ( 'edit' !== $context ) {
    class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 
    23612314                        $this->assertArrayNotHasKey( 'author_ip', $data );
    23622315                        $this->assertArrayNotHasKey( 'author_user_agent', $data );
    23632316                        $this->assertArrayNotHasKey( 'raw', $data['content'] );
    2364                         $this->assertArrayNotHasKey( 'karma', $data );
    23652317                }
    23662318        }
    23672319}