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; |
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 { |
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 |