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 @@ - + comment_post_ID; @@ -190,7 +196,7 @@ $parent_link = esc_url( get_comment_link( $parent ) ); $name = get_comment_author( $parent ); printf( - /* translators: %s: comment link */ + /* translators: %s: Comment link. */ ' | ' . __( 'In reply to %s.' ), '' . $name . '' ); @@ -202,11 +208,12 @@ comment_post_ID ) ) { @@ -218,7 +225,7 @@ - +

comment_ID}" ); ?>">

@@ -252,7 +259,7 @@ case 'unapprovecomment': $comment_id = absint( $_REQUEST['c'] ); - if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) { + if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { check_admin_referer( 'approve-comment_' . $comment_id ); } else { check_admin_referer( 'delete-comment_' . $comment_id ); @@ -260,18 +267,19 @@ $noredir = isset( $_REQUEST['noredir'] ); - if ( ! $comment = get_comment( $comment_id ) ) { + $comment = get_comment( $comment_id ); + if ( ! $comment ) { comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' ' . __( 'Go back' ) . '.', 'edit-comments.php' ) ); } if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); } - if ( '' != wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { + if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { $redir = wp_get_referer(); - } elseif ( '' != wp_get_original_referer() && ! $noredir ) { + } elseif ( wp_get_original_referer() && ! $noredir ) { $redir = wp_get_original_referer(); - } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ) ) ) { + } elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { $redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) ); } else { $redir = admin_url( 'edit-comments.php' ); @@ -331,7 +339,10 @@ check_admin_referer( 'update-comment_' . $comment_id ); - edit_comment(); + $updated = edit_comment(); + if ( is_wp_error( $updated ) ) { + wp_die( $updated->get_error_message() ); + } $location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id; @@ -344,13 +355,13 @@ * @param int $comment_id The ID of the comment being edited. */ $location = apply_filters( 'comment_edit_redirect', $location, $comment_id ); + wp_redirect( $location ); - - exit(); + exit; default: wp_die( __( 'Unknown action.' ) ); -} // end switch +} // End switch. -include( ABSPATH . 'wp-admin/admin-footer.php' ); +require_once ABSPATH . 'wp-admin/admin-footer.php';