Make WordPress Core

Changeset 49303

Timestamp:
10/24/2020 10:44:38 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API, XML-RPC: Synchronise empty comment content checks.

The REST API and XML-RPC now uses the same detection methodology for empty comment content as wp_handle_comment_submission(). Specifically, comments now have their content trimmed and '0' is allowed.

Props jaswrks, rmccue, dd32, rachelbaker, Cawa-93, aduth, TimothyBlynJacobs.
Fixes #43177.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r49271 r49303  
    38773877        }
    38783878
    3879         if ( empty( $content_struct['content'] ) ) {
    3880             return new IXR_Error( 403, __( 'Comment is required.' ) );
    3881         }
    3882 
    38833879        $comment = array(
    38843880            'comment_post_ID' => $post_id,
    3885             'comment_content' => $content_struct['content'],
     3881            'comment_content' => ,
    38863882        );
    38873883
     
    39233919
    39243920        $comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0;
     3921
     3922
     3923
     3924
     3925
     3926
     3927
    39253928
    39263929        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r49299 r49303  
    588588        $prepared_comment['comment_type'] = 'comment';
    589589
    590         /*
    591          * Do not allow a comment to be created with missing or empty
    592          * comment_content. See wp_handle_comment_submission().
    593          */
    594         if ( empty( $prepared_comment['comment_content'] ) ) {
     590       
     591       
     592       
     593
     594        if ( ) ) {
    595595            return new WP_Error(
    596596                'rest_comment_content_invalid',
     
    12811281         */
    12821282        if ( isset( $request['content'] ) && is_string( $request['content'] ) ) {
    1283             $prepared_comment['comment_content'] = $request['content'];
     1283            $prepared_comment['comment_content'] = ;
    12841284        } elseif ( isset( $request['content']['raw'] ) && is_string( $request['content']['raw'] ) ) {
    1285             $prepared_comment['comment_content'] = $request['content']['raw'];
     1285            $prepared_comment['comment_content'] = ;
    12861286        }
    12871287
     
    18671867        return $email;
    18681868    }
     1869
     1870
     1871
     1872
     1873
     1874
     1875
     1876
     1877
     1878
     1879
     1880
     1881
     1882
     1883
     1884
     1885
     1886
     1887
     1888
     1889
     1890
     1891
     1892
     1893
     1894
     1895
     1896
     1897
     1898
     1899
     1900
     1901
     1902
     1903
    18691904}
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r49299 r49303  
    13991399    }
    14001400
     1401
     1402
     1403
     1404
     1405
     1406
     1407
     1408
     1409
     1410
     1411
     1412
     1413
     1414
     1415
     1416
     1417
     1418
     1419
     1420
     1421
     1422
     1423
     1424
     1425
     1426
     1427
     1428
     1429
     1430
     1431
     1432
     1433
     1434
     1435
     1436
     1437
     1438
     1439
     1440
     1441
     1442
     1443
     1444
     1445
     1446
     1447
     1448
     1449
     1450
     1451
     1452
     1453
     1454
     1455
     1456
     1457
     1458
     1459
     1460
     1461
     1462
     1463
     1464
     1465
     1466
     1467
     1468
     1469
     1470
    14011471    public function test_create_item_invalid_date() {
    14021472        wp_set_current_user( self::$admin_id );
  • trunk/tests/phpunit/tests/xmlrpc/wp/newComment.php

    r49271 r49303  
    5151    }
    5252
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
    53112    function test_new_comment_post_closed() {
    54113        $post = self::factory()->post->create_and_get(
Note: See TracChangeset for help on using the changeset viewer.