diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/comment.php --- a/wp/wp-admin/comment.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/comment.php Tue Dec 15 13:49:49 2020 +0100 @@ -7,7 +7,7 @@ */ /** Load WordPress Bootstrap */ -require_once( dirname( __FILE__ ) . '/admin.php' ); +require_once __DIR__ . '/admin.php'; $parent_file = 'edit-comments.php'; $submenu_file = 'edit-comments.php'; @@ -22,20 +22,30 @@ $action = 'deletecomment'; } -if ( 'cdc' == $action ) { +if ( 'cdc' === $action ) { $action = 'delete'; -} elseif ( 'mac' == $action ) { +} elseif ( 'mac' === $action ) { $action = 'approve'; } if ( isset( $_GET['dt'] ) ) { - if ( 'spam' == $_GET['dt'] ) { + if ( 'spam' === $_GET['dt'] ) { $action = 'spam'; - } elseif ( 'trash' == $_GET['dt'] ) { + } elseif ( 'trash' === $_GET['dt'] ) { $action = 'trash'; } } +$comment_id = absint( $_GET['c'] ); +$comment = get_comment( $comment_id ); + +// Prevent actions on a comment associated with a trashed post. +if ( 'trash' === get_post_status( $comment->comment_post_ID ) ) { + wp_die( + __( 'You can’t edit this comment because the associated post is in the Trash. Please restore the post first, then try again.' ) + ); +} + switch ( $action ) { case 'editcomment': @@ -46,23 +56,21 @@ 'id' => 'overview', 'title' => __( 'Overview' ), 'content' => - '
' . __( '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.' ) . '
' . - '' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '
', + '' . __( '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.' ) . '
' . + '' . __( 'You can also moderate the comment from this screen using the Status box, where you can also change the timestamp of the comment.' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . - '' . __( 'Documentation on Comments' ) . '
' . + '' . __( 'Documentation on Comments' ) . '
' . '' . __( 'Support' ) . '
' ); wp_enqueue_script( 'comment' ); - require_once( ABSPATH . 'wp-admin/admin-header.php' ); + require_once ABSPATH . 'wp-admin/admin-header.php'; - $comment_id = absint( $_GET['c'] ); - - if ( ! $comment = get_comment( $comment_id ) ) { + if ( ! $comment ) { comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' ' . __( 'Go back' ) . '.', 'javascript:history.go(-1)' ) ); } @@ -70,13 +78,13 @@ comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) ); } - if ( 'trash' == $comment->comment_approved ) { + if ( 'trash' === $comment->comment_approved ) { comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) ); } $comment = get_comment_to_edit( $comment_id ); - include( ABSPATH . 'wp-admin/edit-form-comment.php' ); + require ABSPATH . 'wp-admin/edit-form-comment.php'; break; @@ -86,9 +94,7 @@ case 'spam': $title = __( 'Moderate Comment' ); - $comment_id = absint( $_GET['c'] ); - - if ( ! $comment = get_comment( $comment_id ) ) { + if ( ! $comment ) { wp_redirect( admin_url( 'edit-comments.php?error=1' ) ); die(); } @@ -99,15 +105,15 @@ } // No need to re-approve/re-trash/re-spam a comment. - if ( $action == str_replace( '1', 'approve', $comment->comment_approved ) ) { + if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) { wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) ); die(); } - require_once( ABSPATH . 'wp-admin/admin-header.php' ); + require_once ABSPATH . 'wp-admin/admin-header.php'; $formaction = $action . 'comment'; - $nonce_action = 'approve' == $action ? 'approve-comment_' : 'delete-comment_'; + $nonce_action = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_'; $nonce_action .= $comment_id; ?> @@ -119,7 +125,7 @@ switch ( $action ) { case 'spam': $caution_msg = __( 'You are about to mark the following comment as spam:' ); - $button = _x( 'Mark as Spam', 'comment' ); + $button = _x( 'Mark as spam', 'comment' ); break; case 'trash': $caution_msg = __( 'You are about to move the following comment to the Trash:' ); @@ -127,15 +133,15 @@ break; case 'delete': $caution_msg = __( 'You are about to delete the following comment:' ); - $button = __( 'Permanently Delete Comment' ); + $button = __( 'Permanently delete comment' ); break; default: $caution_msg = __( 'You are about to approve the following comment:' ); - $button = __( 'Approve Comment' ); + $button = __( 'Approve comment' ); break; } - if ( $comment->comment_approved != '0' ) { // if not unapproved + if ( '0' !== $comment->comment_approved ) { // If not unapproved. $message = ''; switch ( $comment->comment_approved ) { case '1': @@ -173,7 +179,7 @@