Make WordPress Core

Ticket #33154: 33154.4.diff

File 33154.4.diff, 5.1 KB (added by ocean90, 10 years ago)
  • src/wp-admin/includes/class-wp-comments-list-table.php

     
    432432         * @param object $a_comment
    433433         */
    434434        public function single_row( $a_comment ) {
    435                 global $post, $comment;
     435                global $comment;
    436436
    437437                $comment = $a_comment;
    438438                $the_comment_class = wp_get_comment_status( $comment->comment_ID );
     
    441441                }
    442442                $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment->comment_ID, $comment->comment_post_ID ) );
    443443
    444                 $post = get_post( $comment->comment_post_ID );
    445 
    446444                $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
    447445
    448446                echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
     
    472470                        return;
    473471                }
    474472
    475                 $post = get_post();
    476 
    477473                $the_comment_status = wp_get_comment_status( $comment->comment_ID );
    478474
    479475                $out = '';
     
    534530
    535531                        $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" title="%s" href="#">%s</a>';
    536532
    537                         $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $post->ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick&nbsp;Edit' ) );
     533                        $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick&nbsp;Edit' ) );
    538534
    539                         $actions['reply'] = sprintf( $format, $comment->comment_ID, $post->ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
     535                        $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
    540536                }
    541537
    542538                /** This filter is documented in wp-admin/includes/dashboard.php */
     
    668664
    669665        /**
    670666         * @access public
     667         *
     668         * @param object $comment
    671669         */
    672         public function column_response() {
    673                 $post = get_post();
     670        public function column_response( $comment ) {
     671                $post = get_post( $comment->comment_post_ID );
    674672
     673                if ( ! $post ) {
     674                        return;
     675                }
     676
    675677                if ( isset( $this->pending_count[$post->ID] ) ) {
    676678                        $pending_comments = $this->pending_count[$post->ID];
    677679                } else {
  • src/wp-includes/capabilities.php

     
    13051305                if ( empty( $comment ) )
    13061306                        break;
    13071307                $post = get_post( $comment->comment_post_ID );
    1308                 $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
     1308
     1309                /*
     1310                 * If the post doesn't exist, we have an orphaned comment.
     1311                 * Fall back to the edit_posts capability, instead.
     1312                 */
     1313                if ( $post ) {
     1314                        $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
     1315                } else {
     1316                        $caps = map_meta_cap( 'edit_posts', $user_id );
     1317                }
    13091318                break;
    13101319        case 'unfiltered_upload':
    13111320                if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) )  )
  • tests/phpunit/tests/ajax/EditComment.php

     
    7575        }
    7676
    7777        /**
     78         * @ticket 33154
     79         */
     80        function test_editor_can_edit_orphan_comments() {
     81                global $wpdb;
     82
     83                // Become an editor
     84                $this->_setRole( 'editor' );
     85
     86                // Get a comment
     87                $comments = get_comments( array(
     88                        'post_id' => $this->_comment_post->ID
     89                ) );
     90                $comment = array_pop( $comments );
     91
     92                // Manually update the comment_post_ID, because wp_update_comment() will prevent it.
     93                $wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" );
     94                clean_comment_cache( $comment->comment_ID );
     95
     96                // Set up a default request
     97                $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     98                $_POST['comment_ID']                  = $comment->comment_ID;
     99                $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     100
     101                // Make the request
     102                try {
     103                        $this->_handleAjax( 'edit-comment' );
     104                } catch ( WPAjaxDieContinueException $e ) {
     105                        unset( $e );
     106                }
     107
     108                // Get the response
     109                $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
     110
     111                // Check the meta data
     112                $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
     113                $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
     114                $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     115
     116                // Check the payload
     117                $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
     118
     119                // And supplemental is empty
     120                $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
     121        }
     122
     123        /**
    78124         * Get comments as a non-privileged user (subscriber)
    79125         * Expects test to fail
    80126         * @return void