wp/wp-admin/comment.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/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 /**
       
    16  * @global string $action
       
    17  */
    15 global $action;
    18 global $action;
    16 wp_reset_vars( array('action') );
    19 wp_reset_vars( array('action') );
    17 
    20 
    18 if ( isset( $_POST['deletecomment'] ) )
    21 if ( isset( $_POST['deletecomment'] ) )
    19 	$action = 'deletecomment';
    22 	$action = 'deletecomment';
    26 if ( isset( $_GET['dt'] ) ) {
    29 if ( isset( $_GET['dt'] ) ) {
    27 	if ( 'spam' == $_GET['dt'] )
    30 	if ( 'spam' == $_GET['dt'] )
    28 		$action = 'spam';
    31 		$action = 'spam';
    29 	elseif ( 'trash' == $_GET['dt'] )
    32 	elseif ( 'trash' == $_GET['dt'] )
    30 		$action = 'trash';
    33 		$action = 'trash';
    31 }
       
    32 
       
    33 /**
       
    34  * Display error message at bottom of comments.
       
    35  *
       
    36  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
       
    37  */
       
    38 function comment_footer_die( $msg ) {
       
    39 	echo "<div class='wrap'><p>$msg</p></div>";
       
    40 	include( ABSPATH . 'wp-admin/admin-footer.php' );
       
    41 	die;
       
    42 }
    34 }
    43 
    35 
    44 switch( $action ) {
    36 switch( $action ) {
    45 
    37 
    46 case 'editcomment' :
    38 case 'editcomment' :
    54 			'<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>'
    46 			'<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>'
    55 	) );
    47 	) );
    56 
    48 
    57 	get_current_screen()->set_help_sidebar(
    49 	get_current_screen()->set_help_sidebar(
    58 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    50 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    59 	'<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments" target="_blank">Documentation on Comments</a>' ) . '</p>' .
    51 	'<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments">Documentation on Comments</a>' ) . '</p>' .
    60 	'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
    52 	'<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    61 	);
    53 	);
    62 
    54 
    63 	wp_enqueue_script('comment');
    55 	wp_enqueue_script('comment');
    64 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
    56 	require_once( ABSPATH . 'wp-admin/admin-header.php' );
    65 
    57 
    66 	$comment_id = absint( $_GET['c'] );
    58 	$comment_id = absint( $_GET['c'] );
    67 
    59 
    68 	if ( !$comment = get_comment( $comment_id ) )
    60 	if ( !$comment = get_comment( $comment_id ) )
    69 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') );
    61 		comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'javascript:history.go(-1)') );
    70 
    62 
    71 	if ( !current_user_can( 'edit_comment', $comment_id ) )
    63 	if ( !current_user_can( 'edit_comment', $comment_id ) )
    72 		comment_footer_die( __('You are not allowed to edit this comment.') );
    64 		comment_footer_die( __('Sorry, you are not allowed to edit this comment.') );
    73 
    65 
    74 	if ( 'trash' == $comment->comment_approved )
    66 	if ( 'trash' == $comment->comment_approved )
    75 		comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
    67 		comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
    76 
    68 
    77 	$comment = get_comment_to_edit( $comment_id );
    69 	$comment = get_comment_to_edit( $comment_id );
    87 
    79 
    88 	$title = __('Moderate Comment');
    80 	$title = __('Moderate Comment');
    89 
    81 
    90 	$comment_id = absint( $_GET['c'] );
    82 	$comment_id = absint( $_GET['c'] );
    91 
    83 
    92 	if ( !$comment = get_comment_to_edit( $comment_id ) ) {
    84 	if ( ! $comment = get_comment( $comment_id ) ) {
    93 		wp_redirect( admin_url('edit-comments.php?error=1') );
    85 		wp_redirect( admin_url('edit-comments.php?error=1') );
    94 		die();
    86 		die();
    95 	}
    87 	}
    96 
    88 
    97 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    89 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
   112 	$nonce_action .= $comment_id;
   104 	$nonce_action .= $comment_id;
   113 
   105 
   114 ?>
   106 ?>
   115 <div class="wrap">
   107 <div class="wrap">
   116 
   108 
   117 <h2><?php echo esc_html( $title ); ?></h2>
   109 <h1><?php echo esc_html( $title ); ?></h1>
   118 
   110 
   119 <?php
   111 <?php
   120 switch ( $action ) {
   112 switch ( $action ) {
   121 	case 'spam' :
   113 	case 'spam' :
   122 		$caution_msg = __('You are about to mark the following comment as spam:');
   114 		$caution_msg = __('You are about to mark the following comment as spam:');
   123 		$button      = __('Mark as Spam');
   115 		$button      = _x( 'Mark as Spam', 'comment' );
   124 		break;
   116 		break;
   125 	case 'trash' :
   117 	case 'trash' :
   126 		$caution_msg = __('You are about to move the following comment to the Trash:');
   118 		$caution_msg = __('You are about to move the following comment to the Trash:');
   127 		$button      = __('Move to Trash');
   119 		$button      = __('Move to Trash');
   128 		break;
   120 		break;
   148 		case 'trash' :
   140 		case 'trash' :
   149 			$message  = __('This comment is currently in the Trash.');
   141 			$message  = __('This comment is currently in the Trash.');
   150 			break;
   142 			break;
   151 	}
   143 	}
   152 	if ( $message ) {
   144 	if ( $message ) {
   153 		echo '<div class="notice notice-info"><p>' . $message . '</p></div>';
   145 		echo '<div id="message" class="notice notice-info"><p>' . $message . '</p></div>';
   154 	}
   146 	}
   155 }
   147 }
   156 ?>
   148 ?>
   157 <p><strong><?php _e('Caution:'); ?></strong> <?php echo $caution_msg; ?></p>
   149 <div id="message" class="notice notice-warning"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo $caution_msg; ?></p></div>
   158 
   150 
   159 <table class="form-table comment-ays">
   151 <table class="form-table comment-ays">
   160 <tr>
   152 <tr>
   161 <th scope="row"><?php _e('Author'); ?></th>
   153 <th scope="row"><?php _e('Author'); ?></th>
   162 <td><?php echo $comment->comment_author; ?></td>
   154 <td><?php comment_author( $comment ); ?></td>
   163 </tr>
   155 </tr>
   164 <?php if ( $comment->comment_author_email ) { ?>
   156 <?php if ( get_comment_author_email( $comment ) ) { ?>
   165 <tr>
   157 <tr>
   166 <th scope="row"><?php _e('E-mail'); ?></th>
   158 <th scope="row"><?php _e('Email'); ?></th>
   167 <td><?php echo $comment->comment_author_email; ?></td>
   159 <td><?php comment_author_email( $comment ); ?></td>
   168 </tr>
   160 </tr>
   169 <?php } ?>
   161 <?php } ?>
   170 <?php if ( $comment->comment_author_url ) { ?>
   162 <?php if ( get_comment_author_url( $comment ) ) { ?>
   171 <tr>
   163 <tr>
   172 <th scope="row"><?php _e('URL'); ?></th>
   164 <th scope="row"><?php _e('URL'); ?></th>
   173 <td><a href="<?php echo $comment->comment_author_url; ?>"><?php echo $comment->comment_author_url; ?></a></td>
   165 <td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td>
   174 </tr>
   166 </tr>
   175 <?php } ?>
   167 <?php } ?>
   176 <tr>
   168 <tr>
   177 	<th scope="row"><?php _e( 'In Response To' ); ?></th>
   169 	<th scope="row"><?php /* translators: column name or table row header */ _e( 'In Response To' ); ?></th>
   178 	<td>
   170 	<td>
   179 	<?php
   171 	<?php
   180 		$post_id = $comment->comment_post_ID;
   172 		$post_id = $comment->comment_post_ID;
   181 		if ( current_user_can( 'edit_post', $post_id ) ) {
   173 		if ( current_user_can( 'edit_post', $post_id ) ) {
   182 			$post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
   174 			$post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
   186 		}
   178 		}
   187 		echo $post_link;
   179 		echo $post_link;
   188 
   180 
   189 		if ( $comment->comment_parent ) {
   181 		if ( $comment->comment_parent ) {
   190 			$parent      = get_comment( $comment->comment_parent );
   182 			$parent      = get_comment( $comment->comment_parent );
   191 			$parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
   183 			$parent_link = esc_url( get_comment_link( $parent ) );
   192 			$name        = get_comment_author( $parent->comment_ID );
   184 			$name        = get_comment_author( $parent );
   193 			printf( ' | ' . __( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
   185 			printf(
       
   186 				/* translators: %s: comment link */
       
   187 				' | ' . __( 'In reply to %s.' ),
       
   188 				'<a href="' . $parent_link . '">' . $name . '</a>'
       
   189 			);
   194 		}
   190 		}
   195 	?>
   191 	?>
   196 	</td>
   192 	</td>
   197 </tr>
   193 </tr>
   198 <tr>
   194 <tr>
   199 	<th scope="row"><?php _e( 'Submitted on' ); ?></th>
   195 	<th scope="row"><?php _e( 'Submitted on' ); ?></th>
   200 	<td>
   196 	<td>
   201 	<?php
   197 	<?php
   202 		/* translators: 2: comment date, 3: comment time */
   198 		/* translators: 1: comment date, 2: comment time */
   203 		printf( __( '<a href="%1$s">%2$s at %3$s</a>' ),
   199 		$submitted = sprintf( __( '%1$s at %2$s' ),
   204 			esc_url( get_comment_link( $comment->comment_ID ) ),
   200 			/* translators: comment date format. See https://secure.php.net/date */
   205 			/* translators: comment date format. See http://php.net/date */
   201 			get_comment_date( __( 'Y/m/d' ), $comment ),
   206 			get_comment_date( __( 'Y/m/d' ) ),
   202 			get_comment_date( __( 'g:i a' ), $comment )
   207 			get_comment_date( get_option( 'time_format' ) )
       
   208 		);
   203 		);
       
   204 		if ( 'approved' === wp_get_comment_status( $comment ) && ! empty ( $comment->comment_post_ID ) ) {
       
   205 			echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
       
   206 		} else {
       
   207 			echo $submitted;
       
   208 		}
   209 	?>
   209 	?>
   210 	</td>
   210 	</td>
   211 </tr>
   211 </tr>
   212 <tr>
   212 <tr>
   213 <th scope="row"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
   213 <th scope="row"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
   214 <td><?php echo $comment->comment_content; ?></td>
   214 <td class="comment-content">
       
   215 	<?php comment_text( $comment ); ?>
       
   216 	<p class="edit-comment"><a href="<?php echo admin_url( "comment.php?action=editcomment&amp;c={$comment->comment_ID}" ); ?>"><?php esc_html_e( 'Edit' ); ?></a></p>
       
   217 </td>
   215 </tr>
   218 </tr>
   216 </table>
   219 </table>
   217 
   220 
   218 <form action="comment.php" method="get" class="comment-ays-submit">
   221 <form action="comment.php" method="get" class="comment-ays-submit">
   219 
   222 
   220 <p>
   223 <p>
   221 	<?php submit_button( $button, 'primary', 'submit', false ); ?>
   224 	<?php submit_button( $button, 'primary', 'submit', false ); ?>
   222 	<a href="<?php echo admin_url('edit-comments.php'); ?>" class="button-cancel"><?php esc_attr_e( 'Cancel' ); ?></a></td>
   225 	<a href="<?php echo admin_url('edit-comments.php'); ?>" class="button-cancel"><?php esc_html_e( 'Cancel' ); ?></a>
   223 </p>
   226 </p>
   224 
   227 
   225 <?php wp_nonce_field( $nonce_action ); ?>
   228 <?php wp_nonce_field( $nonce_action ); ?>
   226 <input type="hidden" name="action" value="<?php echo esc_attr($formaction); ?>" />
   229 <input type="hidden" name="action" value="<?php echo esc_attr($formaction); ?>" />
   227 <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID); ?>" />
   230 <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID); ?>" />
   247 		check_admin_referer( 'delete-comment_' . $comment_id );
   250 		check_admin_referer( 'delete-comment_' . $comment_id );
   248 
   251 
   249 	$noredir = isset($_REQUEST['noredir']);
   252 	$noredir = isset($_REQUEST['noredir']);
   250 
   253 
   251 	if ( !$comment = get_comment($comment_id) )
   254 	if ( !$comment = get_comment($comment_id) )
   252 		comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
   255 		comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
   253 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
   256 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
   254 		comment_footer_die( __('You are not allowed to edit comments on this post.') );
   257 		comment_footer_die( __('Sorry, you are not allowed to edit comments on this post.') );
   255 
   258 
   256 	if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
   259 	if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
   257 		$redir = wp_get_referer();
   260 		$redir = wp_get_referer();
   258 	elseif ( '' != wp_get_original_referer() && ! $noredir )
   261 	elseif ( '' != wp_get_original_referer() && ! $noredir )
   259 		$redir = wp_get_original_referer();
   262 		$redir = wp_get_original_referer();
   264 
   267 
   265 	$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
   268 	$redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir );
   266 
   269 
   267 	switch ( $action ) {
   270 	switch ( $action ) {
   268 		case 'deletecomment' :
   271 		case 'deletecomment' :
   269 			wp_delete_comment( $comment_id );
   272 			wp_delete_comment( $comment );
   270 			$redir = add_query_arg( array('deleted' => '1'), $redir );
   273 			$redir = add_query_arg( array('deleted' => '1'), $redir );
   271 			break;
   274 			break;
   272 		case 'trashcomment' :
   275 		case 'trashcomment' :
   273 			wp_trash_comment($comment_id);
   276 			wp_trash_comment( $comment );
   274 			$redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
   277 			$redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
   275 			break;
   278 			break;
   276 		case 'untrashcomment' :
   279 		case 'untrashcomment' :
   277 			wp_untrash_comment($comment_id);
   280 			wp_untrash_comment( $comment );
   278 			$redir = add_query_arg( array('untrashed' => '1'), $redir );
   281 			$redir = add_query_arg( array('untrashed' => '1'), $redir );
   279 			break;
   282 			break;
   280 		case 'spamcomment' :
   283 		case 'spamcomment' :
   281 			wp_spam_comment($comment_id);
   284 			wp_spam_comment( $comment );
   282 			$redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
   285 			$redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
   283 			break;
   286 			break;
   284 		case 'unspamcomment' :
   287 		case 'unspamcomment' :
   285 			wp_unspam_comment($comment_id);
   288 			wp_unspam_comment( $comment );
   286 			$redir = add_query_arg( array('unspammed' => '1'), $redir );
   289 			$redir = add_query_arg( array('unspammed' => '1'), $redir );
   287 			break;
   290 			break;
   288 		case 'approvecomment' :
   291 		case 'approvecomment' :
   289 			wp_set_comment_status( $comment_id, 'approve' );
   292 			wp_set_comment_status( $comment, 'approve' );
   290 			$redir = add_query_arg( array( 'approved' => 1 ), $redir );
   293 			$redir = add_query_arg( array( 'approved' => 1 ), $redir );
   291 			break;
   294 			break;
   292 		case 'unapprovecomment' :
   295 		case 'unapprovecomment' :
   293 			wp_set_comment_status( $comment_id, 'hold' );
   296 			wp_set_comment_status( $comment, 'hold' );
   294 			$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
   297 			$redir = add_query_arg( array( 'unapproved' => 1 ), $redir );
   295 			break;
   298 			break;
   296 	}
   299 	}
   297 
   300 
   298 	wp_redirect( $redir );
   301 	wp_redirect( $redir );
   308 	edit_comment();
   311 	edit_comment();
   309 
   312 
   310 	$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
   313 	$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
   311 
   314 
   312 	/**
   315 	/**
   313 	 * Filter the URI the user is redirected to after editing a comment in the admin.
   316 	 * Filters the URI the user is redirected to after editing a comment in the admin.
   314 	 *
   317 	 *
   315 	 * @since 2.1.0
   318 	 * @since 2.1.0
   316 	 *
   319 	 *
   317 	 * @param string $location The URI the user will be redirected to.
   320 	 * @param string $location The URI the user will be redirected to.
   318 	 * @param int $comment_id The ID of the comment being edited.
   321 	 * @param int $comment_id The ID of the comment being edited.