From cf783103fca3c640f76a693e7315cde9ce6a3f20 Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Fri, 17 Jun 2016 21:47:58 +0000 Subject: [PATCH] Comments: Wrap or unwrap the List Table comment_date as comment status changes via Ajax. Introduced in [36521]. Fixes #36742. Props imath, adamsilverstein. git-svn-id: https://develop.svn.wordpress.org/trunk@37743 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 19 +++++++++++++++---- src/wp-includes/js/wp-lists.js | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 7df3c61678..bcd1825332 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -352,8 +352,18 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { // JS didn't send us everything we need to know. Just die with success message if ( ! $total || ! $per_page || ! $page || ! $url ) { - $time = time(); - $comment = get_comment( $comment_id ); + $time = time(); + $comment = get_comment( $comment_id ); + $comment_status = ''; + $comment_link = ''; + + if ( $comment ) { + $comment_status = $comment->comment_approved; + } + + if ( 1 === (int) $comment_status ) { + $comment_link = get_comment_link( $comment ); + } $counts = wp_count_comments(); @@ -362,7 +372,7 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { // Here for completeness - not used. 'id' => $comment_id, 'supplemental' => array( - 'status' => $comment ? $comment->comment_approved : '', + 'status' => $comment_status, 'postId' => $comment ? $comment->comment_post_ID : '', 'time' => $time, 'in_moderation' => $counts->moderated, @@ -373,7 +383,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 'i18n_moderation_text' => sprintf( _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ), number_format_i18n( $counts->moderated ) - ) + ), + 'comment_link' => $comment_link, ) ) ); $x->send(); diff --git a/src/wp-includes/js/wp-lists.js b/src/wp-includes/js/wp-lists.js index 117e892f72..7a8791ce4d 100644 --- a/src/wp-includes/js/wp-lists.js +++ b/src/wp-includes/js/wp-lists.js @@ -297,6 +297,20 @@ wpList = { res = wpAjax.parseAjaxResponse(r, s.response, s.element); rres = r; + if ( 'undefined' !== typeof res.responses[0].supplemental.comment_link ) { + var submittedOn = element.find( '.submitted-on' ), + commentLink = submittedOn.find( 'a' ); + + // Comment is approved; link the date field. + if ( '' !== res.responses[0].supplemental.comment_link ) { + submittedOn.html( $('').text( submittedOn.text() ).prop( 'href', res.responses[0].supplemental.comment_link ) ); + + // Comment is not approved; unlink the date field. + } else if ( commentLink.length ) { + submittedOn.text( commentLink.text() ); + } + } + if ( !res || res.errors ) { element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); return false;