wp/wp-admin/comment.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     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( dirname( __FILE__ ) . '/admin.php' );
    10 require_once __DIR__ . '/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 /**
    15 /**
    20 
    20 
    21 if ( isset( $_POST['deletecomment'] ) ) {
    21 if ( isset( $_POST['deletecomment'] ) ) {
    22 	$action = 'deletecomment';
    22 	$action = 'deletecomment';
    23 }
    23 }
    24 
    24 
    25 if ( 'cdc' == $action ) {
    25 if ( 'cdc' === $action ) {
    26 	$action = 'delete';
    26 	$action = 'delete';
    27 } elseif ( 'mac' == $action ) {
    27 } elseif ( 'mac' === $action ) {
    28 	$action = 'approve';
    28 	$action = 'approve';
    29 }
    29 }
    30 
    30 
    31 if ( isset( $_GET['dt'] ) ) {
    31 if ( isset( $_GET['dt'] ) ) {
    32 	if ( 'spam' == $_GET['dt'] ) {
    32 	if ( 'spam' === $_GET['dt'] ) {
    33 		$action = 'spam';
    33 		$action = 'spam';
    34 	} elseif ( 'trash' == $_GET['dt'] ) {
    34 	} elseif ( 'trash' === $_GET['dt'] ) {
    35 		$action = 'trash';
    35 		$action = 'trash';
    36 	}
    36 	}
       
    37 }
       
    38 
       
    39 $comment_id = absint( $_GET['c'] );
       
    40 $comment    = get_comment( $comment_id );
       
    41 
       
    42 // Prevent actions on a comment associated with a trashed post.
       
    43 if ( 'trash' === get_post_status( $comment->comment_post_ID ) ) {
       
    44 	wp_die(
       
    45 		__( 'You can’t edit this comment because the associated post is in the Trash. Please restore the post first, then try again.' )
       
    46 	);
    37 }
    47 }
    38 
    48 
    39 switch ( $action ) {
    49 switch ( $action ) {
    40 
    50 
    41 	case 'editcomment':
    51 	case 'editcomment':
    44 		get_current_screen()->add_help_tab(
    54 		get_current_screen()->add_help_tab(
    45 			array(
    55 			array(
    46 				'id'      => 'overview',
    56 				'id'      => 'overview',
    47 				'title'   => __( 'Overview' ),
    57 				'title'   => __( 'Overview' ),
    48 				'content' =>
    58 				'content' =>
    49 					  '<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>' .
    59 					'<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>' .
    50 					  '<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>',
    60 					'<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>',
    51 			)
    61 			)
    52 		);
    62 		);
    53 
    63 
    54 		get_current_screen()->set_help_sidebar(
    64 		get_current_screen()->set_help_sidebar(
    55 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    65 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    56 			'<p>' . __( '<a href="https://codex.wordpress.org/Administration_Screens#Comments">Documentation on Comments</a>' ) . '</p>' .
    66 			'<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' .
    57 			'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    67 			'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    58 		);
    68 		);
    59 
    69 
    60 		wp_enqueue_script( 'comment' );
    70 		wp_enqueue_script( 'comment' );
    61 		require_once( ABSPATH . 'wp-admin/admin-header.php' );
    71 		require_once ABSPATH . 'wp-admin/admin-header.php';
    62 
    72 
    63 		$comment_id = absint( $_GET['c'] );
    73 		if ( ! $comment ) {
    64 
       
    65 		if ( ! $comment = get_comment( $comment_id ) ) {
       
    66 			comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'javascript:history.go(-1)' ) );
    74 			comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'javascript:history.go(-1)' ) );
    67 		}
    75 		}
    68 
    76 
    69 		if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    77 		if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    70 			comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) );
    78 			comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) );
    71 		}
    79 		}
    72 
    80 
    73 		if ( 'trash' == $comment->comment_approved ) {
    81 		if ( 'trash' === $comment->comment_approved ) {
    74 			comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) );
    82 			comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) );
    75 		}
    83 		}
    76 
    84 
    77 		$comment = get_comment_to_edit( $comment_id );
    85 		$comment = get_comment_to_edit( $comment_id );
    78 
    86 
    79 		include( ABSPATH . 'wp-admin/edit-form-comment.php' );
    87 		require ABSPATH . 'wp-admin/edit-form-comment.php';
    80 
    88 
    81 		break;
    89 		break;
    82 
    90 
    83 	case 'delete':
    91 	case 'delete':
    84 	case 'approve':
    92 	case 'approve':
    85 	case 'trash':
    93 	case 'trash':
    86 	case 'spam':
    94 	case 'spam':
    87 		$title = __( 'Moderate Comment' );
    95 		$title = __( 'Moderate Comment' );
    88 
    96 
    89 		$comment_id = absint( $_GET['c'] );
    97 		if ( ! $comment ) {
    90 
       
    91 		if ( ! $comment = get_comment( $comment_id ) ) {
       
    92 			wp_redirect( admin_url( 'edit-comments.php?error=1' ) );
    98 			wp_redirect( admin_url( 'edit-comments.php?error=1' ) );
    93 			die();
    99 			die();
    94 		}
   100 		}
    95 
   101 
    96 		if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
   102 		if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    97 			wp_redirect( admin_url( 'edit-comments.php?error=2' ) );
   103 			wp_redirect( admin_url( 'edit-comments.php?error=2' ) );
    98 			die();
   104 			die();
    99 		}
   105 		}
   100 
   106 
   101 		// No need to re-approve/re-trash/re-spam a comment.
   107 		// No need to re-approve/re-trash/re-spam a comment.
   102 		if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) {
   108 		if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) {
   103 			wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
   109 			wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) );
   104 			die();
   110 			die();
   105 		}
   111 		}
   106 
   112 
   107 		require_once( ABSPATH . 'wp-admin/admin-header.php' );
   113 		require_once ABSPATH . 'wp-admin/admin-header.php';
   108 
   114 
   109 		$formaction    = $action . 'comment';
   115 		$formaction    = $action . 'comment';
   110 		$nonce_action  = 'approve' == $action ? 'approve-comment_' : 'delete-comment_';
   116 		$nonce_action  = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_';
   111 		$nonce_action .= $comment_id;
   117 		$nonce_action .= $comment_id;
   112 
   118 
   113 		?>
   119 		?>
   114 	<div class="wrap">
   120 	<div class="wrap">
   115 
   121 
   117 
   123 
   118 		<?php
   124 		<?php
   119 		switch ( $action ) {
   125 		switch ( $action ) {
   120 			case 'spam':
   126 			case 'spam':
   121 				$caution_msg = __( 'You are about to mark the following comment as spam:' );
   127 				$caution_msg = __( 'You are about to mark the following comment as spam:' );
   122 				$button      = _x( 'Mark as Spam', 'comment' );
   128 				$button      = _x( 'Mark as spam', 'comment' );
   123 				break;
   129 				break;
   124 			case 'trash':
   130 			case 'trash':
   125 				$caution_msg = __( 'You are about to move the following comment to the Trash:' );
   131 				$caution_msg = __( 'You are about to move the following comment to the Trash:' );
   126 				$button      = __( 'Move to Trash' );
   132 				$button      = __( 'Move to Trash' );
   127 				break;
   133 				break;
   128 			case 'delete':
   134 			case 'delete':
   129 				$caution_msg = __( 'You are about to delete the following comment:' );
   135 				$caution_msg = __( 'You are about to delete the following comment:' );
   130 				$button      = __( 'Permanently Delete Comment' );
   136 				$button      = __( 'Permanently delete comment' );
   131 				break;
   137 				break;
   132 			default:
   138 			default:
   133 				$caution_msg = __( 'You are about to approve the following comment:' );
   139 				$caution_msg = __( 'You are about to approve the following comment:' );
   134 				$button      = __( 'Approve Comment' );
   140 				$button      = __( 'Approve comment' );
   135 				break;
   141 				break;
   136 		}
   142 		}
   137 
   143 
   138 		if ( $comment->comment_approved != '0' ) { // if not unapproved
   144 		if ( '0' !== $comment->comment_approved ) { // If not unapproved.
   139 			$message = '';
   145 			$message = '';
   140 			switch ( $comment->comment_approved ) {
   146 			switch ( $comment->comment_approved ) {
   141 				case '1':
   147 				case '1':
   142 					$message = __( 'This comment is currently approved.' );
   148 					$message = __( 'This comment is currently approved.' );
   143 					break;
   149 					break;
   171 <th scope="row"><?php _e( 'URL' ); ?></th>
   177 <th scope="row"><?php _e( 'URL' ); ?></th>
   172 <td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td>
   178 <td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td>
   173 </tr>
   179 </tr>
   174 <?php } ?>
   180 <?php } ?>
   175 <tr>
   181 <tr>
   176 	<th scope="row"><?php /* translators: column name or table row header */ _e( 'In Response To' ); ?></th>
   182 	<th scope="row"><?php /* translators: Column name or table row header. */ _e( 'In response to' ); ?></th>
   177 	<td>
   183 	<td>
   178 		<?php
   184 		<?php
   179 		$post_id = $comment->comment_post_ID;
   185 		$post_id = $comment->comment_post_ID;
   180 		if ( current_user_can( 'edit_post', $post_id ) ) {
   186 		if ( current_user_can( 'edit_post', $post_id ) ) {
   181 			$post_link  = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
   187 			$post_link  = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>";
   188 		if ( $comment->comment_parent ) {
   194 		if ( $comment->comment_parent ) {
   189 			$parent      = get_comment( $comment->comment_parent );
   195 			$parent      = get_comment( $comment->comment_parent );
   190 			$parent_link = esc_url( get_comment_link( $parent ) );
   196 			$parent_link = esc_url( get_comment_link( $parent ) );
   191 			$name        = get_comment_author( $parent );
   197 			$name        = get_comment_author( $parent );
   192 			printf(
   198 			printf(
   193 				/* translators: %s: comment link */
   199 				/* translators: %s: Comment link. */
   194 				' | ' . __( 'In reply to %s.' ),
   200 				' | ' . __( 'In reply to %s.' ),
   195 				'<a href="' . $parent_link . '">' . $name . '</a>'
   201 				'<a href="' . $parent_link . '">' . $name . '</a>'
   196 			);
   202 			);
   197 		}
   203 		}
   198 		?>
   204 		?>
   200 	</tr>
   206 	</tr>
   201 	<tr>
   207 	<tr>
   202 	<th scope="row"><?php _e( 'Submitted on' ); ?></th>
   208 	<th scope="row"><?php _e( 'Submitted on' ); ?></th>
   203 	<td>
   209 	<td>
   204 		<?php
   210 		<?php
   205 		/* translators: 1: comment date, 2: comment time */
       
   206 		$submitted = sprintf(
   211 		$submitted = sprintf(
       
   212 			/* translators: 1: Comment date, 2: Comment time. */
   207 			__( '%1$s at %2$s' ),
   213 			__( '%1$s at %2$s' ),
   208 			/* translators: comment date format. See https://secure.php.net/date */
   214 			/* translators: Comment date format. See https://www.php.net/date */
   209 			get_comment_date( __( 'Y/m/d' ), $comment ),
   215 			get_comment_date( __( 'Y/m/d' ), $comment ),
       
   216 			/* translators: Comment time format. See https://www.php.net/date */
   210 			get_comment_date( __( 'g:i a' ), $comment )
   217 			get_comment_date( __( 'g:i a' ), $comment )
   211 		);
   218 		);
   212 		if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
   219 		if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
   213 			echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
   220 			echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
   214 		} else {
   221 		} else {
   216 		}
   223 		}
   217 		?>
   224 		?>
   218 		</td>
   225 		</td>
   219 	</tr>
   226 	</tr>
   220 	<tr>
   227 	<tr>
   221 	<th scope="row"><?php /* translators: field name in comment form */ _ex( 'Comment', 'noun' ); ?></th>
   228 	<th scope="row"><?php /* translators: Field name in comment form. */ _ex( 'Comment', 'noun' ); ?></th>
   222 	<td class="comment-content">
   229 	<td class="comment-content">
   223 		<?php comment_text( $comment ); ?>
   230 		<?php comment_text( $comment ); ?>
   224 	<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>
   231 	<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>
   225 	</td>
   232 	</td>
   226 	</tr>
   233 	</tr>
   250 	case 'unspamcomment':
   257 	case 'unspamcomment':
   251 	case 'approvecomment':
   258 	case 'approvecomment':
   252 	case 'unapprovecomment':
   259 	case 'unapprovecomment':
   253 		$comment_id = absint( $_REQUEST['c'] );
   260 		$comment_id = absint( $_REQUEST['c'] );
   254 
   261 
   255 		if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
   262 		if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
   256 			check_admin_referer( 'approve-comment_' . $comment_id );
   263 			check_admin_referer( 'approve-comment_' . $comment_id );
   257 		} else {
   264 		} else {
   258 			check_admin_referer( 'delete-comment_' . $comment_id );
   265 			check_admin_referer( 'delete-comment_' . $comment_id );
   259 		}
   266 		}
   260 
   267 
   261 		$noredir = isset( $_REQUEST['noredir'] );
   268 		$noredir = isset( $_REQUEST['noredir'] );
   262 
   269 
   263 		if ( ! $comment = get_comment( $comment_id ) ) {
   270 		$comment = get_comment( $comment_id );
       
   271 		if ( ! $comment ) {
   264 			comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) );
   272 			comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) );
   265 		}
   273 		}
   266 		if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
   274 		if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
   267 			comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
   275 			comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
   268 		}
   276 		}
   269 
   277 
   270 		if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
   278 		if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) {
   271 			$redir = wp_get_referer();
   279 			$redir = wp_get_referer();
   272 		} elseif ( '' != wp_get_original_referer() && ! $noredir ) {
   280 		} elseif ( wp_get_original_referer() && ! $noredir ) {
   273 			$redir = wp_get_original_referer();
   281 			$redir = wp_get_original_referer();
   274 		} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) {
   282 		} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) {
   275 			$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
   283 			$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
   276 		} else {
   284 		} else {
   277 			$redir = admin_url( 'edit-comments.php' );
   285 			$redir = admin_url( 'edit-comments.php' );
   278 		}
   286 		}
   279 
   287 
   329 		$comment_id      = absint( $_POST['comment_ID'] );
   337 		$comment_id      = absint( $_POST['comment_ID'] );
   330 		$comment_post_id = absint( $_POST['comment_post_ID'] );
   338 		$comment_post_id = absint( $_POST['comment_post_ID'] );
   331 
   339 
   332 		check_admin_referer( 'update-comment_' . $comment_id );
   340 		check_admin_referer( 'update-comment_' . $comment_id );
   333 
   341 
   334 		edit_comment();
   342 		$updated = edit_comment();
       
   343 		if ( is_wp_error( $updated ) ) {
       
   344 			wp_die( $updated->get_error_message() );
       
   345 		}
   335 
   346 
   336 		$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
   347 		$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id;
   337 
   348 
   338 		/**
   349 		/**
   339 		 * Filters the URI the user is redirected to after editing a comment in the admin.
   350 		 * Filters the URI the user is redirected to after editing a comment in the admin.
   342 		 *
   353 		 *
   343 		 * @param string $location The URI the user will be redirected to.
   354 		 * @param string $location The URI the user will be redirected to.
   344 		 * @param int $comment_id The ID of the comment being edited.
   355 		 * @param int $comment_id The ID of the comment being edited.
   345 		 */
   356 		 */
   346 		$location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
   357 		$location = apply_filters( 'comment_edit_redirect', $location, $comment_id );
       
   358 
   347 		wp_redirect( $location );
   359 		wp_redirect( $location );
   348 
   360 		exit;
   349 		exit();
       
   350 
   361 
   351 	default:
   362 	default:
   352 		wp_die( __( 'Unknown action.' ) );
   363 		wp_die( __( 'Unknown action.' ) );
   353 
   364 
   354 } // end switch
   365 } // End switch.
   355 
   366 
   356 include( ABSPATH . 'wp-admin/admin-footer.php' );
   367 require_once ABSPATH . 'wp-admin/admin-footer.php';