Make WordPress Core

Ticket #39730: 39730.5.patch

File 39730.5.patch, 4.1 KB (added by enrico.sorcinelli, 8 years ago)

Updated to the current trunk.

  • src/wp-admin/includes/ajax-actions.php

    diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
    index e132ac8101..cddd0504cb 100644
    a b function wp_ajax_replyto_comment( $action ) { 
    11001100        }
    11011101
    11021102        $comment_id = wp_new_comment( $commentdata );
     1103
     1104        if ( is_wp_error( $comment_id ) ) {
     1105                wp_die ( $comment_id->get_error_message() );
     1106        }
     1107
    11031108        $comment = get_comment($comment_id);
    11041109        if ( ! $comment ) wp_die( 1 );
    11051110
  • src/wp-includes/class-wp-xmlrpc-server.php

    diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php
    index ffeb102d27..dac32e0860 100644
    a b class wp_xmlrpc_server extends IXR_Server { 
    65056505
    65066506                $comment_ID = wp_new_comment($commentdata);
    65076507
     6508                if ( is_wp_error( $comment_ID ) ) {
     6509                        return $this->pingback_error( 0, $comment_ID->get_error_message() );
     6510                }
     6511
    65086512                /**
    65096513                 * Fires after a post pingback has been sent.
    65106514                 *
  • src/wp-includes/comment.php

    diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
    index 7055db763f..16c102cdb4 100644
    a b function wp_allow_comment( $commentdata, $avoid_die = false ) { 
    757757         * Filters a comment's approval status before it is set.
    758758         *
    759759         * @since 2.1.0
     760         * @since 4.9.0 Returning a WP_Error value from the filter will shortcircuit comment insertion and
     761         *              allow skipping further processing.
    760762         *
    761          * @param bool|string $approved    The approval status. Accepts 1, 0, or 'spam'.
    762          * @param array       $commentdata Comment data.
     763         * @param bool|string|WP_Error $approved    The approval status. Accepts 1, 0, 'spam' or WP_Error.
     764         * @param array                $commentdata Comment data.
    763765         */
    764766        $approved = apply_filters( 'pre_comment_approved', $approved, $commentdata );
    765767        return $approved;
  • src/wp-trackback.php

    diff --git a/src/wp-trackback.php b/src/wp-trackback.php
    index 86e17b965d..802bb2ba6d 100644
    a b if ( !empty($tb_url) && !empty($title) ) { 
    126126
    127127        $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
    128128
    129         wp_new_comment($commentdata);
     129        $result = wp_new_comment( $commentdata );
     130
     131        if ( is_wp_error( $result ) ) {
     132                trackback_response( 1, $result->get_error_message() );
     133        }
     134
    130135        $trackback_id = $wpdb->insert_id;
    131136
    132137        /**
  • tests/phpunit/tests/ajax/ReplytoComment.php

    diff --git a/tests/phpunit/tests/ajax/ReplytoComment.php b/tests/phpunit/tests/ajax/ReplytoComment.php
    index 33a0650472..ac9db2bf1f 100644
    a b class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase { 
    3737
    3838        public function tearDown() {
    3939                remove_filter( 'query', array( $this, '_block_comments' ) );
     40                remove_filter( 'pre_comment_approved', array( $this, '_pre_comment_approved_filter' ), 10, 2 );
    4041                parent::tearDown();
    4142        }
    4243
    class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase { 
    222223                }
    223224                return $sql;
    224225        }
     226
     227        /**
     228         * @ticket 39730
     229         */
     230        public function test_pre_comments_approved () {
     231
     232                // Become an administrator
     233                $this->_setRole( 'administrator' );
     234
     235                // Set up a default request
     236                $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     237                $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     238                $_POST['comment_post_ID']             = self::$comment_post->ID;
     239
     240                // Simulate filter check error
     241                add_filter( 'pre_comment_approved', array( $this, '_pre_comment_approved_filter' ), 10, 2 );
     242
     243                // Make the request
     244                $this->setExpectedException( 'WPAjaxDieStopException', 'pre_comment_approved filter fails for new comment' );
     245                $this->_handleAjax( 'replyto-comment' );
     246        }
     247
     248        /**
     249         *  Block comments from being saved 'pre_comment_approved', by returning WP_Error
     250         */
     251        function _pre_comment_approved_filter ( $approved, $commentdata ) {
     252                return new WP_Error( 'comment_wrong', __( 'pre_comment_approved filter fails for new comment' ), 403 );
     253        }
    225254}