~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

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

  • Committer: Jamon Camisso
  • Date: 2017-01-12 15:30:45 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: jamon.camisso@canonical.com-20170112153045-dekfwsu8mcsdxa7x
New upstream release 4.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
392
392
                         *                                 response.
393
393
                         */
394
394
                        $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );
395
 
                        if ( false === $allow_anonymous ) {
 
395
                        if ( ! $allow_anonymous ) {
396
396
                                return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
397
397
                        }
398
398
                }
664
664
                        return $prepared_args;
665
665
                }
666
666
 
 
667
                if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
 
668
                        $post = get_post( $prepared_args['comment_post_ID'] );
 
669
                        if ( empty( $post ) ) {
 
670
                                return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) );
 
671
                        }
 
672
                }
 
673
 
667
674
                if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
668
675
                        // Only the comment status is being changed.
669
676
                        $change = $this->handle_status_param( $request['status'], $id );
690
697
 
691
698
                        $updated = wp_update_comment( wp_slash( (array) $prepared_args ) );
692
699
 
693
 
                        if ( 0 === $updated ) {
 
700
                        if ( false === $updated ) {
694
701
                                return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) );
695
702
                        }
696
703
 
1430
1437
                 *
1431
1438
                 * @since 4.7.0
1432
1439
                 *
1433
 
                 * @param $params JSON Schema-formatted collection parameters.
 
1440
                 * @param array $query_params JSON Schema-formatted collection parameters.
1434
1441
                 */
1435
1442
                return apply_filters( 'rest_comment_collection_params', $query_params );
1436
1443
        }