~canonical-sysadmins/wordpress/4.9.4

« back to all changes in this revision

Viewing changes to wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

  • Committer: Barry Price
  • Date: 2017-11-17 04:49:02 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: barry.price@canonical.com-20171117044902-5frux4ycbq6g9fyf
Merge WP4.9 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
         * Instance of a comment meta fields object.
21
21
         *
22
22
         * @since 4.7.0
23
 
         * @access protected
24
23
         * @var WP_REST_Comment_Meta_Fields
25
24
         */
26
25
        protected $meta;
29
28
         * Constructor.
30
29
         *
31
30
         * @since 4.7.0
32
 
         * @access public
33
31
         */
34
32
        public function __construct() {
35
33
                $this->namespace = 'wp/v2';
42
40
         * Registers the routes for the objects of the controller.
43
41
         *
44
42
         * @since 4.7.0
45
 
         * @access public
46
43
         */
47
44
        public function register_routes() {
48
45
 
111
108
         * Checks if a given request has access to read comments.
112
109
         *
113
110
         * @since 4.7.0
114
 
         * @access public
115
111
         *
116
112
         * @param WP_REST_Request $request Full details about the request.
117
113
         * @return WP_Error|bool True if the request has read access, error object otherwise.
164
160
         * Retrieves a list of comment items.
165
161
         *
166
162
         * @since 4.7.0
167
 
         * @access public
168
163
         *
169
164
         * @param WP_REST_Request $request Full details about the request.
170
165
         * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
339
334
         * Checks if a given request has access to read the comment.
340
335
         *
341
336
         * @since 4.7.0
342
 
         * @access public
343
337
         *
344
338
         * @param WP_REST_Request $request Full details about the request.
345
339
         * @return WP_Error|bool True if the request has read access for the item, error object otherwise.
371
365
         * Retrieves a comment.
372
366
         *
373
367
         * @since 4.7.0
374
 
         * @access public
375
368
         *
376
369
         * @param WP_REST_Request $request Full details about the request.
377
370
         * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
392
385
         * Checks if a given request has access to create a comment.
393
386
         *
394
387
         * @since 4.7.0
395
 
         * @access public
396
388
         *
397
389
         * @param WP_REST_Request $request Full details about the request.
398
390
         * @return WP_Error|bool True if the request has access to create items, error object otherwise.
480
472
         * Creates a comment.
481
473
         *
482
474
         * @since 4.7.0
483
 
         * @access public
484
475
         *
485
476
         * @param WP_REST_Request $request Full details about the request.
486
477
         * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
648
639
         * Checks if a given REST request has access to update a comment.
649
640
         *
650
641
         * @since 4.7.0
651
 
         * @access public
652
642
         *
653
643
         * @param WP_REST_Request $request Full details about the request.
654
644
         * @return WP_Error|bool True if the request has access to update the item, error object otherwise.
670
660
         * Updates a comment.
671
661
         *
672
662
         * @since 4.7.0
673
 
         * @access public
674
663
         *
675
664
         * @param WP_REST_Request $request Full details about the request.
676
665
         * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
767
756
         * Checks if a given request has access to delete a comment.
768
757
         *
769
758
         * @since 4.7.0
770
 
         * @access public
771
759
         *
772
760
         * @param WP_REST_Request $request Full details about the request.
773
761
         * @return WP_Error|bool True if the request has access to delete the item, error object otherwise.
788
776
         * Deletes a comment.
789
777
         *
790
778
         * @since 4.7.0
791
 
         * @access public
792
779
         *
793
780
         * @param WP_REST_Request $request Full details about the request.
794
781
         * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
823
810
                } else {
824
811
                        // If this type doesn't support trashing, error out.
825
812
                        if ( ! $supports_trash ) {
826
 
                                return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
 
813
                                /* translators: %s: force=true */
 
814
                                return new WP_Error( 'rest_trash_not_supported', sprintf( __( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) );
827
815
                        }
828
816
 
829
817
                        if ( 'trash' === $comment->comment_approved ) {
857
845
         * Prepares a single comment output for response.
858
846
         *
859
847
         * @since 4.7.0
860
 
         * @access public
861
848
         *
862
849
         * @param WP_Comment      $comment Comment object.
863
850
         * @param WP_REST_Request $request Request object.
923
910
         * Prepares links for the request.
924
911
         *
925
912
         * @since 4.7.0
926
 
         * @access protected
927
913
         *
928
914
         * @param WP_Comment $comment Comment object.
929
915
         * @return array Links for the given comment.
992
978
         * Prepends internal property prefix to query parameters to match our response fields.
993
979
         *
994
980
         * @since 4.7.0
995
 
         * @access protected
996
981
         *
997
982
         * @param string $query_param Query parameter.
998
983
         * @return string The normalized query parameter.
1025
1010
         * Checks comment_approved to set comment status for single comment output.
1026
1011
         *
1027
1012
         * @since 4.7.0
1028
 
         * @access protected
1029
1013
         *
1030
1014
         * @param string|int $comment_approved comment status.
1031
1015
         * @return string Comment status.
1057
1041
         * Prepares a single comment to be inserted into the database.
1058
1042
         *
1059
1043
         * @since 4.7.0
1060
 
         * @access protected
1061
1044
         *
1062
1045
         * @param WP_REST_Request $request Request object.
1063
1046
         * @return array|WP_Error Prepared comment, otherwise WP_Error object.
1153
1136
         * Retrieves the comment's schema, conforming to JSON Schema.
1154
1137
         *
1155
1138
         * @since 4.7.0
1156
 
         * @access public
1157
1139
         *
1158
1140
         * @return array
1159
1141
         */
1160
1142
        public function get_item_schema() {
1161
1143
                $schema = array(
1162
 
                        '$schema'              => 'http://json-schema.org/schema#',
 
1144
                        '$schema'              => 'http://json-schema.org/draft-04/schema#',
1163
1145
                        'title'                => 'comment',
1164
1146
                        'type'                 => 'object',
1165
1147
                        'properties'           => array(
1218
1200
                                        'context'         => array( 'view', 'edit', 'embed' ),
1219
1201
                                        'arg_options'     => array(
1220
1202
                                                'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
 
1203
                                                'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
1221
1204
                                        ),
1222
1205
                                        'properties'      => array(
1223
1206
                                                'raw'         => array(
1313
1296
         * Retrieves the query params for collections.
1314
1297
         *
1315
1298
         * @since 4.7.0
1316
 
         * @access public
1317
1299
         *
1318
1300
         * @return array Comments collection parameters.
1319
1301
         */
1471
1453
         * Sets the comment_status of a given comment object when creating or updating a comment.
1472
1454
         *
1473
1455
         * @since 4.7.0
1474
 
         * @access protected
1475
1456
         *
1476
1457
         * @param string|int $new_status New comment status.
1477
1458
         * @param int        $comment_id Comment ID.
1520
1501
         * Correctly handles posts with the inherit status.
1521
1502
         *
1522
1503
         * @since 4.7.0
1523
 
         * @access protected
1524
1504
         *
1525
1505
         * @param WP_Post         $post    Post object.
1526
1506
         * @param WP_REST_Request $request Request data to check.
1533
1513
                $has_password_filter = false;
1534
1514
 
1535
1515
                // Only check password if a specific post was queried for or a single comment
1536
 
                $requested_post = ! empty( $request['post'] ) && 1 === count( $request['post'] );
 
1516
                $requested_post = ! empty( $request['post'] ) && ( !is_array( $request['post'] ) || 1 === count( $request['post'] ) );
1537
1517
                $requested_comment = ! empty( $request['id'] );
1538
1518
                if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) {
1539
1519
                        add_filter( 'post_password_required', '__return_false' );
1558
1538
         * Checks if the comment can be read.
1559
1539
         *
1560
1540
         * @since 4.7.0
1561
 
         * @access protected
1562
1541
         *
1563
1542
         * @param WP_Comment      $comment Comment object.
1564
1543
         * @param WP_REST_Request $request Request data to check.
1593
1572
         * Checks if a comment can be edited or deleted.
1594
1573
         *
1595
1574
         * @since 4.7.0
1596
 
         * @access protected
1597
1575
         *
1598
1576
         * @param object $comment Comment object.
1599
1577
         * @return bool Whether the comment can be edited or deleted.
1618
1596
         * string is allowed when a comment is being updated.
1619
1597
         *
1620
1598
         * @since 4.7.0
1621
 
         * @access public
1622
1599
         *
1623
1600
         * @param string          $value   Author email value submitted.
1624
1601
         * @param WP_REST_Request $request Full details about the request.