Make WordPress Core


Ignore:
Timestamp:
02/20/2010 11:18:25 AM (17 years ago)
Author:
nacin
Message:

Comments moderation code cleanup. Dry up some code, add screen icon to AYS, fix notice in comment_footer_die(). Redirect to edit-comments.php on an error, instead of stranding them with dull comment_footer_die() message. See #11441

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r13100 r13246  
    127127
    128128<?php
     129if ( isset( $_GET['error'] ) ) {
     130        $error = (int) $_GET['error'];
     131        $error_msg = '';
     132        switch ( $error ) {
     133                case 1 :
     134                        $error_msg = __( 'Oops, no comment with this ID.' );
     135                        break;
     136                case 2 :
     137                        $error_msg = __( 'You are not allowed to edit comments on this post.' );
     138                        break;
     139        }
     140        if ( $error_msg )
     141                echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
     142}
     143
    129144if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) ) {
    130         $approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
    131         $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
    132         $trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
    133         $untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
    134         $spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
    135         $unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
     145        $approved  = isset( $_GET['approved']  ) ? (int) $_GET['approved'] : 0;
     146        $deleted   = isset( $_GET['deleted']   ) ? (int) $_GET['deleted']  : 0;
     147        $trashed   = isset( $_GET['trashed']   ) ? (int) $_GET['trashed']  : 0;
     148        $untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0;
     149        $spammed   = isset( $_GET['spammed']   ) ? (int) $_GET['spammed']  : 0;
     150        $unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0;
    136151
    137152        if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 ) {
    138                 echo '<div id="moderated" class="updated"><p>';
    139 
    140                 if ( $approved > 0 ) {
    141                         printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
    142                         echo '<br />';
     153                if ( $approved > 0 )
     154                        $messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
     155
     156                if ( $spammed > 0 ) {
     157                        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     158                        $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
    143159                }
    144                 if ( $spammed > 0 ) {
    145                         printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
     160
     161                if ( $unspammed > 0 )
     162                        $messages = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
     163
     164                if ( $trashed > 0 ) {
    146165                        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
    147                         echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
     166                        $messages[] = sprintf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
    148167                }
    149                 if ( $unspammed > 0 ) {
    150                         printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
    151                         echo '<br />';
    152                 }
    153                 if ( $trashed > 0 ) {
    154                         printf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed ), $trashed );
    155                         $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
    156                         echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
    157                 }
    158                 if ( $untrashed > 0 ) {
    159                         printf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed );
    160                         echo '<br />';
    161                 }
    162                 if ( $deleted > 0 ) {
    163                         printf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
    164                         echo '<br />';
    165                 }
    166 
    167                 echo '</p></div>';
     168
     169                if ( $untrashed > 0 )
     170                        $messages[] = sprintf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed );
     171
     172                if ( $deleted > 0 )
     173                        $messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
     174
     175                echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
    168176        }
    169177}
Note: See TracChangeset for help on using the changeset viewer.