WordPress.org

Make WordPress Core

Ticket #4529: comment-trash-undo.diff

File comment-trash-undo.diff, 12.7 KB (added by caesarsgrunt, 5 years ago)

Undo for trashing of comments.

  • wp-includes/js/wp-lists.dev.js

     
    11(function($) { 
    2 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList; 
     2var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList, noticetimer; 
    33 
    44wpList = { 
    55        settings: { 
     
    121121 
    122122                s.element = cls[2] || s.element || null; 
    123123                if ( cls[3] ) { s.delColor = '#' + cls[3]; } 
     124                else if ($(s.target).parents('span.undo').size() || $(s.target).parents('span.untrash').size()) { s.delColor = '#339900'; } 
    124125                else { s.delColor = s.delColor || '#FF3333'; } 
    125126 
    126127                if ( !s || !s.element ) { return false; } 
     
    146147                        anim = 'slideUp'; 
    147148                        if ( element.css( 'display' ).match(/table/) ) 
    148149                                anim = 'fadeOut'; // Can't slideup table rows and other table elements.  Known jQuery bug 
    149                         element 
    150                                 .animate( { backgroundColor: s.delColor }, 'fast'  )[anim]( 'fast' ) 
    151                                 .queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); 
     150                        element.animate( { backgroundColor: s.delColor }, 'fast'  ); 
     151                                 
     152                        if ($(s.target).parents('span.trash').size() && s.data.untrash_nonce) { 
     153                                $('#trashnoticerow').hide().insertAfter(element); 
     154                                element.queue(function() { 
     155                                        $('#trashnoticerow').show(); 
     156                                        $(this).hide(); 
     157                                        list.wpList.recolor(); 
     158                                        $(this).dequeue(); 
     159                                }); 
     160                                $('#trashnoticerow').css({backgroundColor:s.delColor}).animate({backgroundColor:'#ffffff'}, 'slow'); 
     161                                $('#trashnoticerow a:first').attr('href','comment.php?action=untrashcomment&c='+s.data.id+'&_wpnonce='+s.data.untrash_nonce); 
     162                                $('#trashnoticerow a:first').attr('class','delete:the-comment-list:comment-'+s.data.id+'::undo=1&untrash=1 vim-t vim-destructive'); 
     163                                $('#trashnoticerow a:first').click(function() { $(this).unbind('click'); return list.wpList.del(this); }); 
     164                                if (element.is('.unapproved')) $('#trashnoticerow span:first').addClass('unapprove').removeClass('approve'); 
     165                                else $('#trashnoticerow span:first').addClass('approve').removeClass('unapprove'); 
     166                                clearTimeout(noticetimer); 
     167                                noticetimer = setTimeout(function() {$('#trashnoticerow')[anim]('slow')}, 30000); 
     168                        } 
     169                        else if ($(s.target).parents('span.undo').size() && s.data.undo) { 
     170                                $('#trashnoticerow').animate({backgroundColor:s.delColor}, 'fast'); 
     171                                $('#trashnoticerow').prev().css({backgroundColor:s.delColor}) 
     172                                $('#trashnoticerow').queue(function() { 
     173                                        var bg = $(this).prev().is('.unapproved') ? '#ffffe0' : $(this).prev().is('.alt') ? '#f9f9f9' : '#ffffff'; 
     174                                        $(this).prev().show().animate({backgroundColor:bg}, 'slow'); 
     175                                        $(this).hide(); 
     176                                        list.wpList.recolor(); 
     177                                        $(this).dequeue(); 
     178                                }); 
     179                                clearTimeout(noticetimer); 
     180                        } 
     181                        else element[anim]('fast').queue(function() { list.wpList.recolor(); $(this).dequeue(); }); 
    152182                } else { 
    153183                        list.wpList.recolor(); 
    154184                } 
  • wp-includes/comment.php

     
    889889 
    890890        //Either set comment_approved to the value in comment_meta or worse case to false which will mean moderation 
    891891        $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true); 
     892        if ($comment['comment_approved'] == false) $comment['comment_approved'] = 0; 
    892893 
    893894        wp_update_comment($comment); 
     895         
     896        delete_comment_meta($comment_id, '_wp_trash_meta_time'); 
     897        delete_comment_meta($comment_id, '_wp_trash_meta_status'); 
    894898 
    895899        do_action('untrashed_comment', $comment_id); 
    896900 
  • wp-admin/edit-comments.php

     
    2828        } elseif (($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments'])) { 
    2929                $comment_ids = $_REQUEST['delete_comments']; 
    3030                $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2']; 
     31        } elseif ($_REQUEST['action'] == 'untrash' && isset($_REQUEST['ids'])) { 
     32                $comment_ids = explode(',', $_REQUEST['ids']); 
     33                $doaction = 'untrash'; 
    3134        } else wp_redirect($_SERVER['HTTP_REFERER']); 
    3235 
    3336        $approved = $unapproved = $spammed = $trashed = $untrashed = $deleted = 0; 
     
    6669                } 
    6770        } 
    6871 
    69         $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&trashed=' . $trashed . '&untrashed=' . $untrashed . '&deleted=' . $deleted; 
     72        $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&trashed=' . $trashed . '&untrashed=' . $untrashed . '&deleted=' . $deleted . '&ids=' . join(',', $comment_ids); 
    7073        if ( $post_id ) 
    7174                $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to ); 
    7275        if ( isset($_REQUEST['apage']) ) 
     
    128131                        echo '<br />'; 
    129132                } 
    130133                if ( $trashed > 0 ) { 
    131                         printf( _n( '%s comment moved to the trash', '%s comments moved to the trash', $trashed ), $trashed ); 
    132                         echo ' <a href="' . admin_url('edit-comments.php?comment_status=trash') . '">' . __('View trash') . '</a><br />'; 
     134                        printf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed ), $trashed ); 
     135                        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0; 
     136                        echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo?') . '</a><br />'; 
    133137                } 
    134138                if ( $untrashed > 0 ) { 
    135139                        printf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed ); 
     
    414418 
    415419<?php 
    416420wp_comment_reply('-1', true, 'detail'); 
     421wp_comment_trashnotice('-1', true, 'detail'); 
    417422include('admin-footer.php'); ?> 
  • wp-admin/includes/dashboard.php

     
    509509<?php   } 
    510510 
    511511                wp_comment_reply( -1, false, 'dashboard', false ); 
     512                wp_comment_trashnotice( -1, false, 'dashboard', false ); 
    512513 
    513514        else : 
    514515?> 
     
    527528        $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>"; 
    528529        $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>'; 
    529530 
    530         $delete_url = esc_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) ); 
    531531        $approve_url = esc_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) ); 
    532532        $unapprove_url = esc_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) ); 
    533533        $spam_url = esc_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) ); 
     534        $trash_url = esc_url( wp_nonce_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "trash-comment_$comment->comment_ID" ) ); 
    534535 
    535536        $actions = array(); 
    536537 
     
    541542                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>'; 
    542543                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>'; 
    543544                $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */  _x( 'Spam', 'verb' ) . '</a>'; 
    544                 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Move to Trash') . '</a>'; 
     545                $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1&untrash_nonce=".wp_create_nonce("untrash-comment_$comment->comment_ID")." delete vim-t vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>'; 
    545546 
    546547                $actions = apply_filters( 'comment_row_actions', $actions, $comment ); 
    547548 
  • wp-admin/includes/template.php

     
    21732173                                                        $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>'; 
    21742174                                                } else { 
    21752175                                                        $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; 
    2176                                                         $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-t vim-destructive'>" . __('Trash') . '</a>'; 
     2176                                                        $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1&untrash_nonce=".wp_create_nonce("untrash-comment_$comment->comment_ID")." delete vim-t vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>'; 
    21772177                                                } 
    21782178 
    21792179                                                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>'; 
     
    23572357/** 
    23582358 * {@internal Missing Short Description}} 
    23592359 * 
     2360 * @since 2.9.0 
     2361 * 
     2362 * @param unknown_type $position 
     2363 * @param unknown_type $checkbox 
     2364 * @param unknown_type $mode 
     2365 */ 
     2366function wp_comment_trashnotice($position = '1', $checkbox = false, $mode = 'single', $table_row = true) { 
     2367        global $current_user; 
     2368 
     2369        $columns = get_column_headers('edit-comments'); 
     2370        $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns('edit-comments') ) ); 
     2371        $col_count = count($columns) - count($hidden); 
     2372 
     2373if ( $table_row ) : ?> 
     2374<table style="display:none;"><tbody id="com-trashnotice"><tr id="trashnoticerow" class="trash"><td colspan="<?php echo $col_count; ?>"> 
     2375<?php else : ?> 
     2376<div id="com-trashnotice" style="display:none;"><div id="trashnoticerow" class="comment-item trash"><p> 
     2377<?php endif; ?> 
     2378<?php _e('Comment moved to the trash.') ?> <span class="undo untrash"><a href="/" class=""><?php _e( 'Undo?' ) ?></a></span> 
     2379<?php if ( $table_row ) : ?> 
     2380</td></tr></tbody></table> 
     2381<?php else : ?> 
     2382</p></div></div> 
     2383<?php endif; 
     2384} 
     2385 
     2386/** 
     2387 * {@internal Missing Short Description}} 
     2388 * 
    23602389 * @since unknown 
    23612390 * 
    23622391 * @param unknown_type $currentcat 
  • wp-admin/js/edit-comments.dev.js

     
    6868                        n = a.html().replace(/[ ,.]+/g, ''); 
    6969                        n = parseInt(n,10); 
    7070                        if ( isNaN(n) ) return; 
    71                         if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment 
     71                        if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" 
     72                                n = n + 1; 
     73                        } else if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment 
    7274                                n = n - 1; 
    73                         } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" 
    74                                 n = n + 1; 
    7575                        } 
    7676                        if ( n < 0 ) { n = 0; } 
    7777                        a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); 
     
    105105                        if ( isNaN(n) ) return; 
    106106                        if ( $(settings.target).parents( 'span.trash' ).size() ) { // we trashed a comment 
    107107                                n = n + 1; 
     108                        } else if ( $(settings.target).parents( 'span.untrash' ).size() ) { // we undid the trashing of a comment 
     109                                n = n - 1; 
    108110                        } else if ( $('#' + settings.element).is('.trash') ) { // we deleted or untrashed a trash comment 
    109111                                n = n - 1; 
    110112                        } 
  • wp-admin/css/dashboard.dev.css

     
    202202        border-top: 1px solid; 
    203203} 
    204204 
     205#the-comment-list #trashnoticerow { 
     206        padding: 0.25em 10px 0.25em 70px; 
     207} 
     208 
    205209#the-comment-list .pingback { 
    206210        padding-left: 9px !important; 
    207211}