WordPress.org

Make WordPress Core

Ticket #17380: 17380.diff

File 17380.diff, 1.8 KB (added by mikeschroder, 7 years ago)

Moves the approval of the new comment to before the new list-item is created, so that the pending comment 'title

  • wp-admin/admin-ajax.php

     
    660660                die( __('Error: please type a comment.') );
    661661
    662662        $comment_parent = absint($_POST['comment_ID']);
     663        $comment_auto_approved = false;
    663664        $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
    664665
    665666        $comment_id = wp_new_comment( $commentdata );
     
    668669
    669670        $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
    670671
     672
     673        // automatically approve parent comment
     674        if ( !empty($_POST['approve_parent']) ) {
     675                $parent = get_comment( $comment_parent );
     676
     677                if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
     678                        if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
     679                                $comment_auto_approved = true;
     680                }
     681        }
     682
    671683        ob_start();
    672684                if ( 'dashboard' == $_REQUEST['mode'] ) {
    673685                        require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
     
    690702                'position' => $position
    691703        );
    692704
    693         // automatically approve parent comment
    694         if ( !empty($_POST['approve_parent']) ) {
    695                 $parent = get_comment( $comment_parent );
     705        if ( $comment_auto_approved )
     706                $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
    696707
    697                 if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
    698                         if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
    699                                 $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
    700                 }
    701         }
    702 
    703708        $x = new WP_Ajax_Response();
    704709        $x->add( $response );
    705710        $x->send();