Make WordPress Core

Ticket #27471: 27471.2.diff

File 27471.2.diff, 2.3 KB (added by wonderboymusic, 9 years ago)
  • src/wp-includes/class-wp-xmlrpc-server.php

     
    34533453                else
    34543454                        $post_id = url_to_postid($post);
    34553455
    3456                 if ( ! $post_id )
     3456                if ( ! $post_id ) {
    34573457                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
     3458                }
    34583459
    3459                 if ( ! get_post($post_id) )
     3460                if ( ! get_post( $post_id ) ) {
    34603461                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
     3462                }
    34613463
     3464                if ( ! comments_open( $post_id ) ) {
     3465                        return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) );
     3466                }
     3467
    34623468                $comment = array();
    34633469                $comment['comment_post_ID'] = $post_id;
    34643470
    34653471                if ( $logged_in ) {
    3466                         $comment['comment_author'] = $this->escape( $user->display_name );
    3467                         $comment['comment_author_email'] = $this->escape( $user->user_email );
    3468                         $comment['comment_author_url'] = $this->escape( $user->user_url );
     3472                        $display_name = $user->display_name;
     3473                        $user_email = $user->user_email;
     3474                        $user_url = $user->user_url;
     3475
     3476                        $comment['comment_author'] = $this->escape( $display_name );
     3477                        $comment['comment_author_email'] = $this->escape( $user_email );
     3478                        $comment['comment_author_url'] = $this->escape( $user_url );
    34693479                        $comment['user_ID'] = $user->ID;
    34703480                } else {
    34713481                        $comment['comment_author'] = '';
  • tests/phpunit/tests/xmlrpc/wp/newComment.php

     
     1<?php
     2
     3/**
     4 * @group xmlrpc
     5 */
     6class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase {
     7        function test_new_comment_post_closed() {
     8                $this->make_user_by_role( 'administrator' );
     9                $post = $this->factory->post->create_and_get( array(
     10                        'comment_status' => 'closed'
     11                ) );
     12
     13                $this->assertEquals( 'closed', $post->comment_status );
     14
     15                $result = $this->myxmlrpcserver->wp_newComment( array( 1, 'administrator', 'administrator', $post->ID, array(
     16                        'comment_content' => rand_str( 100 ),
     17                        'status' => 'approved'
     18                ) ) );
     19
     20                $this->assertInstanceOf( 'IXR_Error', $result );
     21                $this->assertEquals( 403, $result->code );
     22        }
     23}
     24 No newline at end of file