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: https://develop.svn.wordpress.org/trunk@13246 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ea9e869ea8
commit
91e432abfe
|
@ -35,6 +35,7 @@ if ( isset( $_GET['dt'] ) ) {
|
||||||
* @param string $msg Error Message. Assumed to contain HTML and be sanitized.
|
* @param string $msg Error Message. Assumed to contain HTML and be sanitized.
|
||||||
*/
|
*/
|
||||||
function comment_footer_die( $msg ) {
|
function comment_footer_die( $msg ) {
|
||||||
|
global $hook_suffix;
|
||||||
echo "<div class='wrap'><p>$msg</p></div>";
|
echo "<div class='wrap'><p>$msg</p></div>";
|
||||||
include('admin-footer.php');
|
include('admin-footer.php');
|
||||||
die;
|
die;
|
||||||
|
@ -70,22 +71,32 @@ case 'approve' :
|
||||||
case 'trash' :
|
case 'trash' :
|
||||||
case 'spam' :
|
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');
|
require_once('admin-header.php');
|
||||||
|
|
||||||
$comment_id = absint( $_GET['c'] );
|
|
||||||
$formaction = $action . 'comment';
|
$formaction = $action . 'comment';
|
||||||
$nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
|
$nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
|
||||||
$nonce_action .= $comment_id;
|
$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='wrap'>
|
||||||
|
|
||||||
<div class="narrow">
|
<div class="narrow">
|
||||||
|
|
||||||
|
<?php screen_icon(); ?>
|
||||||
|
<h2><?php esc_html_e( 'Moderate Comment' ); ?></h2>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
switch ( $action ) {
|
switch ( $action ) {
|
||||||
case 'spam' :
|
case 'spam' :
|
||||||
|
@ -160,7 +171,13 @@ case 'trashcomment' :
|
||||||
case 'untrashcomment' :
|
case 'untrashcomment' :
|
||||||
case 'spamcomment' :
|
case 'spamcomment' :
|
||||||
case 'unspamcomment' :
|
case 'unspamcomment' :
|
||||||
|
case 'approvecomment' :
|
||||||
|
case 'unapprovecomment' :
|
||||||
$comment_id = absint( $_REQUEST['c'] );
|
$comment_id = absint( $_REQUEST['c'] );
|
||||||
|
|
||||||
|
if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
|
||||||
|
check_admin_referer( 'approve-comment_' . $comment_id );
|
||||||
|
else
|
||||||
check_admin_referer( 'delete-comment_' . $comment_id );
|
check_admin_referer( 'delete-comment_' . $comment_id );
|
||||||
|
|
||||||
$noredir = isset($_REQUEST['noredir']);
|
$noredir = isset($_REQUEST['noredir']);
|
||||||
|
@ -170,14 +187,16 @@ case 'unspamcomment' :
|
||||||
if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
|
if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
|
||||||
comment_footer_die( __('You are not allowed to edit comments on this post.') );
|
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();
|
$redir = wp_get_referer();
|
||||||
elseif ( '' != wp_get_original_referer() && false == $noredir )
|
elseif ( '' != wp_get_original_referer() && ! $noredir )
|
||||||
$redir = wp_get_original_referer();
|
$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
|
else
|
||||||
$redir = admin_url('edit-comments.php');
|
$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 ) {
|
switch ( $action ) {
|
||||||
case 'deletecomment' :
|
case 'deletecomment' :
|
||||||
|
@ -200,46 +219,18 @@ case 'unspamcomment' :
|
||||||
wp_unspam_comment($comment_id);
|
wp_unspam_comment($comment_id);
|
||||||
$redir = add_query_arg( array('unspammed' => '1'), $redir );
|
$redir = add_query_arg( array('unspammed' => '1'), $redir );
|
||||||
break;
|
break;
|
||||||
}
|
case 'approvecomment' :
|
||||||
|
|
||||||
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' );
|
wp_set_comment_status( $comment_id, 'approve' );
|
||||||
$redir = add_query_arg( array( 'approved' => 1 ), $redir );
|
$redir = add_query_arg( array( 'approved' => 1 ), $redir );
|
||||||
} else {
|
break;
|
||||||
|
case 'unapprovecomment' :
|
||||||
wp_set_comment_status( $comment_id, 'hold' );
|
wp_set_comment_status( $comment_id, 'hold' );
|
||||||
$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
|
$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_redirect( $redir );
|
wp_redirect( $redir );
|
||||||
|
die;
|
||||||
exit();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'editedcomment' :
|
case 'editedcomment' :
|
||||||
|
|
|
@ -126,45 +126,53 @@ if ( isset($_GET['s']) && $_GET['s'] )
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<?php
|
<?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']) ) {
|
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;
|
$approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
|
||||||
$deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
|
$deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
|
||||||
$trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
|
$trashed = isset( $_GET['trashed'] ) ? (int) $_GET['trashed'] : 0;
|
||||||
$untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
|
$untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0;
|
||||||
$spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
|
$spammed = isset( $_GET['spammed'] ) ? (int) $_GET['spammed'] : 0;
|
||||||
$unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
|
$unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0;
|
||||||
|
|
||||||
if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $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 ) {
|
if ( $spammed > 0 ) {
|
||||||
printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
|
|
||||||
$ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
|
$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 />';
|
$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 />';
|
||||||
}
|
|
||||||
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 />';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue