web/wp-admin/comment.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Comment Management Panel
     3  * Comment Management Screen
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** Load WordPress Bootstrap */
     9 /** Load WordPress Bootstrap */
    10 require_once('admin.php');
    10 require_once('./admin.php');
    11 
    11 
    12 $parent_file = 'edit-comments.php';
    12 $parent_file = 'edit-comments.php';
    13 $submenu_file = 'edit-comments.php';
    13 $submenu_file = 'edit-comments.php';
    14 
    14 
    15 wp_reset_vars( array('action') );
    15 wp_reset_vars( array('action') );
    34  *
    34  *
    35  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
    35  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
    36  */
    36  */
    37 function comment_footer_die( $msg ) {
    37 function comment_footer_die( $msg ) {
    38 	echo "<div class='wrap'><p>$msg</p></div>";
    38 	echo "<div class='wrap'><p>$msg</p></div>";
    39 	include('admin-footer.php');
    39 	include('./admin-footer.php');
    40 	die;
    40 	die;
    41 }
    41 }
    42 
    42 
    43 switch( $action ) {
    43 switch( $action ) {
    44 
    44 
    45 case 'editcomment' :
    45 case 'editcomment' :
    46 	$title = __('Edit Comment');
    46 	$title = __('Edit Comment');
    47 
    47 
       
    48 	get_current_screen()->add_help_tab( array(
       
    49 		'id'      => 'overview',
       
    50 		'title'   => __('Overview'),
       
    51 		'content' =>
       
    52 			'<p>' . __( 'You can edit the information left in a comment if needed. This is often useful when you notice that a commenter has made a typographical error.' ) . '</p>' .
       
    53 			'<p>' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '</p>'
       
    54 	) );
       
    55 
       
    56 	get_current_screen()->set_help_sidebar(
       
    57 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
       
    58 	'<p>' . __( '<a href="http://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
       
    59 	'<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
       
    60 	);
       
    61 
    48 	wp_enqueue_script('comment');
    62 	wp_enqueue_script('comment');
    49 	require_once('admin-header.php');
    63 	require_once('./admin-header.php');
    50 
    64 
    51 	$comment_id = absint( $_GET['c'] );
    65 	$comment_id = absint( $_GET['c'] );
    52 
    66 
    53 	if ( !$comment = get_comment( $comment_id ) )
    67 	if ( !$comment = get_comment( $comment_id ) )
    54 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'javascript:history.go(-1)') );
    68 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') );
    55 
    69 
    56 	if ( !current_user_can('edit_post', $comment->comment_post_ID) )
    70 	if ( !current_user_can( 'edit_comment', $comment_id ) )
    57 		comment_footer_die( __('You are not allowed to edit comments on this post.') );
    71 		comment_footer_die( __('You are not allowed to edit this comment.') );
    58 
    72 
    59 	if ( 'trash' == $comment->comment_approved )
    73 	if ( 'trash' == $comment->comment_approved )
    60 		comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
    74 		comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
    61 
    75 
    62 	$comment = get_comment_to_edit( $comment_id );
    76 	$comment = get_comment_to_edit( $comment_id );
    63 
    77 
    64 	include('edit-form-comment.php');
    78 	include('./edit-form-comment.php');
    65 
    79 
    66 	break;
    80 	break;
    67 
    81 
    68 case 'delete'  :
    82 case 'delete'  :
    69 case 'approve' :
    83 case 'approve' :
    70 case 'trash'   :
    84 case 'trash'   :
    71 case 'spam'    :
    85 case 'spam'    :
    72 
    86 
    73 	require_once('admin-header.php');
    87 	$title = __('Moderate Comment');
    74 
    88 
    75 	$comment_id = absint( $_GET['c'] );
    89 	$comment_id = absint( $_GET['c'] );
       
    90 
       
    91 	if ( !$comment = get_comment_to_edit( $comment_id ) ) {
       
    92 		wp_redirect( admin_url('edit-comments.php?error=1') );
       
    93 		die();
       
    94 	}
       
    95 
       
    96 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
       
    97 		wp_redirect( admin_url('edit-comments.php?error=2') );
       
    98 		die();
       
    99 	}
       
   100 
       
   101 	// No need to re-approve/re-trash/re-spam a comment.
       
   102 	if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
       
   103 		wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
       
   104 		die();
       
   105  	}
       
   106 
       
   107 	require_once('./admin-header.php');
       
   108 
    76 	$formaction    = $action . 'comment';
   109 	$formaction    = $action . 'comment';
    77 	$nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
   110 	$nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
    78 	$nonce_action .= $comment_id;
   111 	$nonce_action .= $comment_id;
    79 
   112 
    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.') );
       
    85 ?>
   113 ?>
    86 <div class='wrap'>
   114 <div class='wrap'>
    87 
   115 
    88 <div class="narrow">
   116 <div class="narrow">
       
   117 
       
   118 <?php screen_icon(); ?>
       
   119 <h2><?php echo esc_html( $title ); ?></h2>
       
   120 
    89 <?php
   121 <?php
    90 switch ( $action ) {
   122 switch ( $action ) {
    91 	case 'spam' :
   123 	case 'spam' :
    92 		$caution_msg = __('You are about to mark the following comment as spam:');
   124 		$caution_msg = __('You are about to mark the following comment as spam:');
    93 		$button      = __('Spam Comment');
   125 		$button      = __('Spam Comment');
   103 	default :
   135 	default :
   104 		$caution_msg = __('You are about to approve the following comment:');
   136 		$caution_msg = __('You are about to approve the following comment:');
   105 		$button      = __('Approve Comment');
   137 		$button      = __('Approve Comment');
   106 		break;
   138 		break;
   107 }
   139 }
       
   140 
       
   141 if ( $comment->comment_approved != '0' ) { // if not unapproved
       
   142 	$message = '';
       
   143 	switch ( $comment->comment_approved ) {
       
   144 		case '1' :
       
   145 			$message = __('This comment is currently approved.');
       
   146 			break;
       
   147 		case 'spam' :
       
   148 			$message  = __('This comment is currently marked as spam.');
       
   149 			break;
       
   150 		case 'trash' :
       
   151 			$message  = __('This comment is currently in the Trash.');
       
   152 			break;
       
   153 	}
       
   154 	if ( $message )
       
   155 		echo '<div class="updated"><p>' . $message . '</p></div>';
       
   156 }
   108 ?>
   157 ?>
   109 
       
   110 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
   158 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
   111 
   159 
   112 <table class="form-table comment-ays">
   160 <table class="form-table comment-ays">
   113 <tr class="alt">
   161 <tr class="alt">
   114 <th scope="row"><?php _e('Author'); ?></th>
   162 <th scope="row"><?php _e('Author'); ?></th>
   125 <th scope="row"><?php _e('URL'); ?></th>
   173 <th scope="row"><?php _e('URL'); ?></th>
   126 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
   174 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
   127 </tr>
   175 </tr>
   128 <?php } ?>
   176 <?php } ?>
   129 <tr>
   177 <tr>
   130 <th scope="row" valign="top"><?php /* translators: field name in comment form */ echo _x('Comment', 'noun'); ?></th>
   178 <th scope="row" valign="top"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
   131 <td><?php echo $comment->comment_content; ?></td>
   179 <td><?php echo $comment->comment_content; ?></td>
   132 </tr>
   180 </tr>
   133 </table>
   181 </table>
   134 
   182 
   135 <p><?php _e('Are you sure you want to do that?'); ?></p>
   183 <p><?php _e('Are you sure you want to do this?'); ?></p>
   136 
   184 
   137 <form action='comment.php' method='get'>
   185 <form action='comment.php' method='get'>
   138 
   186 
   139 <table width="100%">
   187 <table width="100%">
   140 <tr>
   188 <tr>
   141 <td><a class="button" href="<?php echo admin_url('edit-comments.php'); ?>"><?php esc_attr_e('No'); ?></a></td>
   189 <td><a class="button" href="<?php echo admin_url('edit-comments.php'); ?>"><?php esc_attr_e('No'); ?></a></td>
   142 <td class="textright"><input type='submit' class="button" value='<?php echo esc_attr($button); ?>' /></td>
   190 <td class="textright"><?php submit_button( $button, 'button' ); ?></td>
   143 </tr>
   191 </tr>
   144 </table>
   192 </table>
   145 
   193 
   146 <?php wp_nonce_field( $nonce_action ); ?>
   194 <?php wp_nonce_field( $nonce_action ); ?>
   147 <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' />
   195 <input type='hidden' name='action' value='<?php echo esc_attr($formaction); ?>' />
   148 <input type='hidden' name='p' value='<?php echo esc_attr($comment->comment_post_ID); ?>' />
       
   149 <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' />
   196 <input type='hidden' name='c' value='<?php echo esc_attr($comment->comment_ID); ?>' />
   150 <input type='hidden' name='noredir' value='1' />
   197 <input type='hidden' name='noredir' value='1' />
   151 </form>
   198 </form>
   152 
   199 
   153 </div>
   200 </div>
   154 </div>
   201 </div>
   155 <?php
   202 <?php
   156 	break;
   203 	break;
   157 
   204 
   158 case 'deletecomment' :
   205 case 'deletecomment'    :
   159 case 'trashcomment' :
   206 case 'trashcomment'     :
   160 case 'untrashcomment' :
   207 case 'untrashcomment'   :
   161 case 'spamcomment' :
   208 case 'spamcomment'      :
   162 case 'unspamcomment' :
   209 case 'unspamcomment'    :
       
   210 case 'approvecomment'   :
       
   211 case 'unapprovecomment' :
   163 	$comment_id = absint( $_REQUEST['c'] );
   212 	$comment_id = absint( $_REQUEST['c'] );
   164 	check_admin_referer( 'delete-comment_' . $comment_id );
   213 
       
   214 	if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
       
   215 		check_admin_referer( 'approve-comment_' . $comment_id );
       
   216 	else
       
   217 		check_admin_referer( 'delete-comment_' . $comment_id );
   165 
   218 
   166 	$noredir = isset($_REQUEST['noredir']);
   219 	$noredir = isset($_REQUEST['noredir']);
   167 
   220 
   168 	if ( !$comment = get_comment($comment_id) )
   221 	if ( !$comment = get_comment($comment_id) )
   169 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit-comments.php') );
   222 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
   170 	if ( !current_user_can('edit_post', $comment->comment_post_ID ) )
   223 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
   171 		comment_footer_die( __('You are not allowed to edit comments on this post.') );
   224 		comment_footer_die( __('You are not allowed to edit comments on this post.') );
   172 
   225 
   173 	if ( '' != wp_get_referer() && false == $noredir && false === strpos(wp_get_referer(), 'comment.php') )
   226 	if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
   174 		$redir = wp_get_referer();
   227 		$redir = wp_get_referer();
   175 	elseif ( '' != wp_get_original_referer() && false == $noredir )
   228 	elseif ( '' != wp_get_original_referer() && ! $noredir )
   176 		$redir = wp_get_original_referer();
   229 		$redir = wp_get_original_referer();
       
   230 	elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) )
       
   231 		$redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
   177 	else
   232 	else
   178 		$redir = admin_url('edit-comments.php');
   233 		$redir = admin_url('edit-comments.php');
   179 
   234 
   180 	$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids'), $redir );
   235 	$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
   181 
   236 
   182 	switch ( $action ) {
   237 	switch ( $action ) {
   183 		case 'deletecomment' :
   238 		case 'deletecomment' :
   184 			wp_delete_comment( $comment_id );
   239 			wp_delete_comment( $comment_id );
   185 			$redir = add_query_arg( array('deleted' => '1'), $redir );
   240 			$redir = add_query_arg( array('deleted' => '1'), $redir );
   198 			break;
   253 			break;
   199 		case 'unspamcomment' :
   254 		case 'unspamcomment' :
   200 			wp_unspam_comment($comment_id);
   255 			wp_unspam_comment($comment_id);
   201 			$redir = add_query_arg( array('unspammed' => '1'), $redir );
   256 			$redir = add_query_arg( array('unspammed' => '1'), $redir );
   202 			break;
   257 			break;
       
   258 		case 'approvecomment' :
       
   259 			wp_set_comment_status( $comment_id, 'approve' );
       
   260 			$redir = add_query_arg( array( 'approved' => 1 ), $redir );
       
   261 			break;
       
   262 		case 'unapprovecomment' :
       
   263 			wp_set_comment_status( $comment_id, 'hold' );
       
   264 			$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
       
   265 			break;
   203 	}
   266 	}
   204 
   267 
   205 	wp_redirect( $redir );
   268 	wp_redirect( $redir );
   206 
       
   207 	die;
   269 	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();
       
   243 	break;
   270 	break;
   244 
   271 
   245 case 'editedcomment' :
   272 case 'editedcomment' :
   246 
   273 
   247 	$comment_id = absint( $_POST['comment_ID'] );
   274 	$comment_id = absint( $_POST['comment_ID'] );
   262 	wp_die( __('Unknown action.') );
   289 	wp_die( __('Unknown action.') );
   263 	break;
   290 	break;
   264 
   291 
   265 } // end switch
   292 } // end switch
   266 
   293 
   267 include('admin-footer.php');
   294 include('./admin-footer.php');
   268 
       
   269 ?>