Make WordPress Core


Ignore:
Timestamp:
02/20/2010 11:18:25 AM (15 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/comment.php

    r12789 r13246  
    3636 */
    3737function comment_footer_die( $msg ) {
     38    global $hook_suffix;
    3839    echo "<div class='wrap'><p>$msg</p></div>";
    3940    include('admin-footer.php');
     
    7172case 'spam'    :
    7273
     74    $comment_id = absint( $_GET['c'] );
     75
     76    if ( !$comment = get_comment_to_edit( $comment_id ) ) {
     77        wp_redirect( admin_url('edit-comments.php?error=1') );
     78        die();
     79    }
     80
     81    if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
     82        wp_redirect( admin_url('edit-comments.php?error=2') );
     83        die();
     84    }
     85
    7386    require_once('admin-header.php');
    7487
    75     $comment_id = absint( $_GET['c'] );
    7688    $formaction    = $action . 'comment';
    7789    $nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
    7890    $nonce_action .= $comment_id;
    7991
    80     if ( !$comment = get_comment_to_edit( $comment_id ) )
    81         comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit.php') );
    82 
    83     if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    84         comment_footer_die( 'approve' != $action ? __('You are not allowed to delete comments on this post.') : __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
    8592?>
    8693<div class='wrap'>
    8794
    8895<div class="narrow">
     96
     97<?php screen_icon(); ?>
     98<h2><?php esc_html_e( 'Moderate Comment' ); ?></h2>
     99
    89100<?php
    90101switch ( $action ) {
     
    156167    break;
    157168
    158 case 'deletecomment' :
    159 case 'trashcomment' :
    160 case 'untrashcomment' :
    161 case 'spamcomment' :
    162 case 'unspamcomment' :
     169case 'deletecomment'    :
     170case 'trashcomment'     :
     171case 'untrashcomment'   :
     172case 'spamcomment'      :
     173case 'unspamcomment'    :
     174case 'approvecomment'   :
     175case 'unapprovecomment' :
    163176    $comment_id = absint( $_REQUEST['c'] );
    164     check_admin_referer( 'delete-comment_' . $comment_id );
     177
     178    if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
     179        check_admin_referer( 'approve-comment_' . $comment_id );
     180    else
     181        check_admin_referer( 'delete-comment_' . $comment_id );
    165182
    166183    $noredir = isset($_REQUEST['noredir']);
     
    171188        comment_footer_die( __('You are not allowed to edit comments on this post.') );
    172189
    173     if ( '' != wp_get_referer() && false == $noredir && false === strpos(wp_get_referer(), 'comment.php') )
     190    if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
    174191        $redir = wp_get_referer();
    175     elseif ( '' != wp_get_original_referer() && false == $noredir )
     192    elseif ( '' != wp_get_original_referer() && ! $noredir )
    176193        $redir = wp_get_original_referer();
     194    elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
     195        $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
    177196    else
    178197        $redir = admin_url('edit-comments.php');
    179198
    180     $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids'), $redir );
     199    $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
    181200
    182201    switch ( $action ) {
     
    201220            $redir = add_query_arg( array('unspammed' => '1'), $redir );
    202221            break;
    203     }
     222        case 'approvecomment' :
     223            wp_set_comment_status( $comment_id, 'approve' );
     224            $redir = add_query_arg( array( 'approved' => 1 ), $redir );
     225            break;
     226        case 'unapprovecomment' :
     227            wp_set_comment_status( $comment_id, 'hold' );
     228            $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
     229            break;
     230    }   
    204231
    205232    wp_redirect( $redir );
    206 
    207233    die;
    208     break;
    209 
    210 case 'approvecomment'   :
    211 case 'unapprovecomment' :
    212     $comment_id = absint( $_GET['c'] );
    213     check_admin_referer( 'approve-comment_' . $comment_id );
    214 
    215     $noredir = isset( $_GET['noredir'] );
    216 
    217     if ( !$comment = get_comment( $comment_id ) )
    218         comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit.php') );
    219 
    220     if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
    221         if ( 'approvecomment' == $action )
    222             comment_footer_die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
    223         else
    224             comment_footer_die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
    225     }
    226 
    227     if ( '' != wp_get_referer() && false == $noredir )
    228         $redir = remove_query_arg( array('approved', 'unapproved'), wp_get_referer() );
    229     else
    230         $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
    231 
    232     if ( 'approvecomment' == $action ) {
    233         wp_set_comment_status( $comment_id, 'approve' );
    234         $redir = add_query_arg( array( 'approved' => 1 ), $redir );
    235     } else {
    236         wp_set_comment_status( $comment_id, 'hold' );
    237         $redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
    238     }
    239 
    240     wp_redirect( $redir );
    241 
    242     exit();
    243234    break;
    244235
Note: See TracChangeset for help on using the changeset viewer.