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

git-svn-id: http://svn.automattic.com/wordpress/trunk@13246 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-02-20 11:18:25 +00:00
parent f3bf4ec676
commit 0b023e884c
2 changed files with 82 additions and 83 deletions

View File

@ -35,6 +35,7 @@ if ( isset( $_GET['dt'] ) ) {
* @param string $msg Error Message. Assumed to contain HTML and be sanitized.
*/
function comment_footer_die( $msg ) {
global $hook_suffix;
echo "<div class='wrap'><p>$msg</p></div>";
include('admin-footer.php');
die;
@ -70,22 +71,32 @@ case 'approve' :
case 'trash' :
case 'spam' :
$comment_id = absint( $_GET['c'] );
if ( !$comment = get_comment_to_edit( $comment_id ) ) {
wp_redirect( admin_url('edit-comments.php?error=1') );
die();
}
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
wp_redirect( admin_url('edit-comments.php?error=2') );
die();
}
require_once('admin-header.php');
$comment_id = absint( $_GET['c'] );
$formaction = $action . 'comment';
$nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
$nonce_action .= $comment_id;
if ( !$comment = get_comment_to_edit( $comment_id ) )
comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit.php') );
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
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.') );
?>
<div class='wrap'>
<div class="narrow">
<?php screen_icon(); ?>
<h2><?php esc_html_e( 'Moderate Comment' ); ?></h2>
<?php
switch ( $action ) {
case 'spam' :
@ -155,13 +166,19 @@ switch ( $action ) {
<?php
break;
case 'deletecomment' :
case 'trashcomment' :
case 'untrashcomment' :
case 'spamcomment' :
case 'unspamcomment' :
case 'deletecomment' :
case 'trashcomment' :
case 'untrashcomment' :
case 'spamcomment' :
case 'unspamcomment' :
case 'approvecomment' :
case 'unapprovecomment' :
$comment_id = absint( $_REQUEST['c'] );
check_admin_referer( 'delete-comment_' . $comment_id );
if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
check_admin_referer( 'approve-comment_' . $comment_id );
else
check_admin_referer( 'delete-comment_' . $comment_id );
$noredir = isset($_REQUEST['noredir']);
@ -170,14 +187,16 @@ case 'unspamcomment' :
if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
comment_footer_die( __('You are not allowed to edit comments on this post.') );
if ( '' != wp_get_referer() && false == $noredir && false === strpos(wp_get_referer(), 'comment.php') )
if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
$redir = wp_get_referer();
elseif ( '' != wp_get_original_referer() && false == $noredir )
elseif ( '' != wp_get_original_referer() && ! $noredir )
$redir = wp_get_original_referer();
elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
$redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
else
$redir = admin_url('edit-comments.php');
$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids'), $redir );
$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
switch ( $action ) {
case 'deletecomment' :
@ -200,48 +219,20 @@ case 'unspamcomment' :
wp_unspam_comment($comment_id);
$redir = add_query_arg( array('unspammed' => '1'), $redir );
break;
case 'approvecomment' :
wp_set_comment_status( $comment_id, 'approve' );
$redir = add_query_arg( array( 'approved' => 1 ), $redir );
break;
case 'unapprovecomment' :
wp_set_comment_status( $comment_id, 'hold' );
$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
break;
}
wp_redirect( $redir );
die;
break;
case 'approvecomment' :
case 'unapprovecomment' :
$comment_id = absint( $_GET['c'] );
check_admin_referer( 'approve-comment_' . $comment_id );
$noredir = isset( $_GET['noredir'] );
if ( !$comment = get_comment( $comment_id ) )
comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit.php') );
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
if ( 'approvecomment' == $action )
comment_footer_die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
else
comment_footer_die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
}
if ( '' != wp_get_referer() && false == $noredir )
$redir = remove_query_arg( array('approved', 'unapproved'), wp_get_referer() );
else
$redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
if ( 'approvecomment' == $action ) {
wp_set_comment_status( $comment_id, 'approve' );
$redir = add_query_arg( array( 'approved' => 1 ), $redir );
} else {
wp_set_comment_status( $comment_id, 'hold' );
$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
}
wp_redirect( $redir );
exit();
break;
case 'editedcomment' :
$comment_id = absint( $_POST['comment_ID'] );

View File

@ -126,45 +126,53 @@ if ( isset($_GET['s']) && $_GET['s'] )
</h2>
<?php
if ( isset( $_GET['error'] ) ) {
$error = (int) $_GET['error'];
$error_msg = '';
switch ( $error ) {
case 1 :
$error_msg = __( 'Oops, no comment with this ID.' );
break;
case 2 :
$error_msg = __( 'You are not allowed to edit comments on this post.' );
break;
}
if ( $error_msg )
echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
}
if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) ) {
$approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
$deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
$trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
$untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
$spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
$unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
$approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
$deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
$trashed = isset( $_GET['trashed'] ) ? (int) $_GET['trashed'] : 0;
$untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0;
$spammed = isset( $_GET['spammed'] ) ? (int) $_GET['spammed'] : 0;
$unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0;
if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 ) {
echo '<div id="moderated" class="updated"><p>';
if ( $approved > 0 )
$messages[] = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
if ( $approved > 0 ) {
printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
echo '<br />';
}
if ( $spammed > 0 ) {
printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
$ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
}
if ( $unspammed > 0 ) {
printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
echo '<br />';
}
if ( $trashed > 0 ) {
printf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed ), $trashed );
$ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
}
if ( $untrashed > 0 ) {
printf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed );
echo '<br />';
}
if ( $deleted > 0 ) {
printf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
echo '<br />';
$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 />';
}
echo '</p></div>';
if ( $unspammed > 0 )
$messages = sprintf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
if ( $trashed > 0 ) {
$ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
$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 />';
}
if ( $untrashed > 0 )
$messages[] = sprintf( _n( '%s comment restored from the trash', '%s comments restored from the trash', $untrashed ), $untrashed );
if ( $deleted > 0 )
$messages[] = sprintf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
echo '<div id="moderated" class="updated"><p>' . implode( "<br/>\n", $messages ) . '</p></div>';
}
}
?>