Make WordPress Core

Ticket #15898: 15898.9.diff

File 15898.9.diff, 6.7 KB (added by kirasong, 14 years ago)

Fixes Approve/Unapprove links not toggling visibility after comment is approved.

  • wp-includes/script-loader.php

     
    308308                        'noPerm' => __('You do not have permission to do that.'),
    309309                        'broken' => __('An unidentified error has occurred.'),
    310310                        'l10n_print_after' => 'try{convertEntities(tagsl10n);}catch(e){};'
    311                 ));
     311                ) );
    312312
    313313                $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20110429' );
    314314                $scripts->add_data( 'admin-custom-fields', 'group', 1 );
     
    317317                $scripts->add_data( 'admin-comments', 'group', 1 );
    318318                $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
    319319                        'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
    320                         'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last'])
     320                        'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
     321                        'replyApprove' => __( 'Approve and Reply' ),
     322                        'reply' => __( 'Reply' )
    321323                ) );
    322324
    323325                $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array('jquery'), '20100403' );
  • wp-admin/admin-ajax.php

     
    666666        $comment = get_comment($comment_id);
    667667        if ( ! $comment ) die('1');
    668668
     669        $parent = get_comment( $comment_parent );
     670
    669671        $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    670672
    671673        $x = new WP_Ajax_Response();
     
    685687                $comment_list_item = ob_get_contents();
    686688        ob_end_clean();
    687689
    688         $x->add( array(
     690        $response = array(
    689691                'what' => 'comment',
    690692                'id' => $comment->comment_ID,
    691693                'data' => $comment_list_item,
    692694                'position' => $position
    693         ));
     695        );
    694696
     697        // automatically approve parent comment if user has privileges
     698        if ( !( $parent->comment_approved ) && current_user_can( 'moderate_comments' ) ) {
     699                if ( wp_update_comment( array( 'comment_ID' => $comment_parent, 'comment_approved' => 'approve' ) ) )
     700                        $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
     701                else
     702                        die( '1' );
     703        }
     704
     705        $x->add( $response );
    695706        $x->send();
    696707        break;
    697708case 'edit-comment' :
  • wp-admin/js/edit-comments.dev.js

     
    1 var theList, theExtraList, toggleWithKeyboard = false;
     1var theList, theExtraList, toggleWithKeyboard = false, getCount, updateCount, dashboardTotals;
    22(function($) {
    33
    44setCommentsList = function() {
     
    99        pageInput = $('input[name="_page"]', '#comments-form');
    1010
    1111        dimAfter = function( r, settings ) {
    12                 var c = $('#' + settings.element);
     12                var c = $('#' + settings.element), editRow, replyID, replyButton;
    1313
    14                 if ( c.is('.unapproved') )
    15                         c.find('div.comment_status').html('0')
    16                 else
    17                         c.find('div.comment_status').html('1')
     14                editRow = $('#replyrow');
     15                replyID = $('#comment_ID', editRow).val();
     16                replyButton = $('#replybtn', editRow);
    1817
     18                if ( c.is('.unapproved') ) {
     19                        if (settings.data.id == replyID && editRow.is(':visible'))
     20                                replyButton.text(adminCommentsL10n.replyApprove);
     21
     22                        c.find('div.comment_status').html('0');
     23                } else {
     24                        if (settings.data.id == replyID && editRow.is(':visible'))
     25                                replyButton.text(adminCommentsL10n.reply);
     26
     27                        c.find('div.comment_status').html('1');
     28                }
     29               
     30
    1931                $('span.pending-count').each( function() {
    2032                        var a = $(this), n, dif;
    2133                        n = a.html().replace(/[^0-9]+/g, '');
     
    99111                });
    100112        };
    101113
    102         function dashboardTotals(n) {
     114        dashboardTotals = function dashboardTotals(n) {
    103115                var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
    104116
    105117                n = n || 0;
     
    115127                updateCount(total, totalN);
    116128                updateCount(appr, apprN);
    117129
    118         }
     130        };
    119131
    120         function getCount(el) {
     132        getCount = function getCount(el) {
    121133                var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
    122134                if ( isNaN(n) )
    123135                        return 0;
    124136                return n;
    125         }
     137        };
    126138
    127         function updateCount(el, n) {
     139        updateCount = function updateCount(el, n) {
    128140                var n1 = '';
    129141                if ( isNaN(n) )
    130142                        return;
     
    137149                        n = n + n1;
    138150                }
    139151                el.html(n);
    140         }
     152        };
    141153
    142154        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    143155        delAfter = function( r, settings ) {
     
    355367        },
    356368
    357369        open : function(id, p, a) {
    358                 var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
     370                var t = this, editRow, rowData, act, h, c = $('#comment-' + id), replyButton;
     371
    359372                t.close();
    360373                t.cid = id;
    361374
     
    387400                                $('#replyrow').fadeIn(300, function(){ $(this).show() });
    388401                        });
    389402                } else {
     403                        replyButton = $('#replybtn', editRow);
    390404                        $('#edithead, #savebtn', editRow).hide();
    391405                        $('#replyhead, #replybtn', editRow).show();
    392406                        c.after(editRow);
     407
     408                        if (c.hasClass('unapproved')) {
     409                                replyButton.text(adminCommentsL10n.replyApprove);
     410                        } else {
     411                                replyButton.text(adminCommentsL10n.reply);
     412                        }
     413                       
    393414                        $('#replyrow').fadeIn(300, function(){ $(this).show() });
    394415                }
    395416
     
    453474        },
    454475
    455476        show : function(xml) {
    456                 var r, c, id, bg;
     477                var t = this, r, c, id, bg, pid;
    457478
    458479                if ( typeof(xml) == 'string' ) {
    459                         this.error({'responseText': xml});
     480                        t.error({'responseText': xml});
    460481                        return false;
    461482                }
    462483
    463484                r = wpAjax.parseAjaxResponse(xml);
    464485                if ( r.errors ) {
    465                         this.error({'responseText': wpAjax.broken});
     486                        t.error({'responseText': wpAjax.broken});
    466487                        return false;
    467488                }
    468489
    469490                r = r.responses[0];
    470491                c = r.data;
    471492                id = '#comment-' + r.id;
    472                 if ( 'edit-comment' == this.act )
     493                if ( 'edit-comment' == t.act )
    473494                        $(id).remove();
    474495
    475496                $(c).hide()
    476497                $('#replyrow').after(c);
    477498
    478                 this.revert();
    479                 this.addEvents($(id));
     499                if ( r.supplemental.parent_approved ) {
     500                        pid = '#comment-' + r.supplemental.parent_approved;
     501
     502                        $('span.pending-count').each( function() {
     503                                var a = $(this), n = getCount(a);
     504                                if (! isNaN(n)) {
     505                                        n = n - 1;
     506                                        if ( n < 0 ) { n = 0; }
     507                                        a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
     508                                        updateCount(a, n);
     509                                        dashboardTotals();
     510                                }
     511                        });
     512                }
     513
     514                t.revert();
     515                t.addEvents($(id));
    480516                bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
    481517
    482518                $(id)
    483519                        .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
    484                         .animate( { 'backgroundColor': bg }, 600 );
     520                        .animate( { 'backgroundColor': bg }, 600, function() {
     521                                if ( pid ) {
     522                                        pid  = $(pid)
     523                                                .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
     524                                                .animate( { 'backgroundColor': '#FFFFFF' }, 600 )
     525                                                .removeClass('unapproved')
     526                                                .addClass('approved');
     527                                }
     528                        });
    485529
    486                 // $.fn.wpList.process($(id));
    487530        },
    488531
    489532        error : function(r) {