author | ymh <ymh.work@gmail.com> |
Thu, 29 Sep 2022 08:06:27 +0200 | |
changeset 20 | 7b1b88e27a20 |
parent 19 | 3d72ae0968f4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Comment Management Screen |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** Load WordPress Bootstrap */ |
|
16 | 10 |
require_once __DIR__ . '/admin.php'; |
0 | 11 |
|
9 | 12 |
$parent_file = 'edit-comments.php'; |
0 | 13 |
$submenu_file = 'edit-comments.php'; |
14 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @global string $action |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
*/ |
5 | 18 |
global $action; |
9 | 19 |
wp_reset_vars( array( 'action' ) ); |
0 | 20 |
|
9 | 21 |
if ( isset( $_POST['deletecomment'] ) ) { |
0 | 22 |
$action = 'deletecomment'; |
9 | 23 |
} |
0 | 24 |
|
16 | 25 |
if ( 'cdc' === $action ) { |
0 | 26 |
$action = 'delete'; |
16 | 27 |
} elseif ( 'mac' === $action ) { |
0 | 28 |
$action = 'approve'; |
9 | 29 |
} |
0 | 30 |
|
31 |
if ( isset( $_GET['dt'] ) ) { |
|
16 | 32 |
if ( 'spam' === $_GET['dt'] ) { |
0 | 33 |
$action = 'spam'; |
16 | 34 |
} elseif ( 'trash' === $_GET['dt'] ) { |
0 | 35 |
$action = 'trash'; |
9 | 36 |
} |
0 | 37 |
} |
38 |
||
18 | 39 |
if ( isset( $_REQUEST['c'] ) ) { |
40 |
$comment_id = absint( $_REQUEST['c'] ); |
|
41 |
$comment = get_comment( $comment_id ); |
|
16 | 42 |
|
18 | 43 |
// Prevent actions on a comment associated with a trashed post. |
44 |
if ( $comment && 'trash' === get_post_status( $comment->comment_post_ID ) ) { |
|
45 |
wp_die( |
|
19 | 46 |
__( 'You cannot edit this comment because the associated post is in the Trash. Please restore the post first, then try again.' ) |
18 | 47 |
); |
48 |
} |
|
49 |
} else { |
|
50 |
$comment = null; |
|
16 | 51 |
} |
52 |
||
9 | 53 |
switch ( $action ) { |
0 | 54 |
|
9 | 55 |
case 'editcomment': |
19 | 56 |
// Used in the HTML title tag. |
9 | 57 |
$title = __( 'Edit Comment' ); |
0 | 58 |
|
9 | 59 |
get_current_screen()->add_help_tab( |
60 |
array( |
|
61 |
'id' => 'overview', |
|
62 |
'title' => __( 'Overview' ), |
|
63 |
'content' => |
|
16 | 64 |
'<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>' . |
65 |
'<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>', |
|
9 | 66 |
) |
67 |
); |
|
0 | 68 |
|
9 | 69 |
get_current_screen()->set_help_sidebar( |
70 |
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
16 | 71 |
'<p>' . __( '<a href="https://wordpress.org/support/article/comments-screen/">Documentation on Comments</a>' ) . '</p>' . |
9 | 72 |
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
73 |
); |
|
0 | 74 |
|
9 | 75 |
wp_enqueue_script( 'comment' ); |
16 | 76 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 77 |
|
16 | 78 |
if ( ! $comment ) { |
9 | 79 |
comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'javascript:history.go(-1)' ) ); |
80 |
} |
|
0 | 81 |
|
9 | 82 |
if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
83 |
comment_footer_die( __( 'Sorry, you are not allowed to edit this comment.' ) ); |
|
84 |
} |
|
0 | 85 |
|
16 | 86 |
if ( 'trash' === $comment->comment_approved ) { |
9 | 87 |
comment_footer_die( __( 'This comment is in the Trash. Please move it out of the Trash if you want to edit it.' ) ); |
88 |
} |
|
0 | 89 |
|
9 | 90 |
$comment = get_comment_to_edit( $comment_id ); |
0 | 91 |
|
16 | 92 |
require ABSPATH . 'wp-admin/edit-form-comment.php'; |
0 | 93 |
|
9 | 94 |
break; |
0 | 95 |
|
9 | 96 |
case 'delete': |
97 |
case 'approve': |
|
98 |
case 'trash': |
|
99 |
case 'spam': |
|
19 | 100 |
// Used in the HTML title tag. |
9 | 101 |
$title = __( 'Moderate Comment' ); |
0 | 102 |
|
16 | 103 |
if ( ! $comment ) { |
9 | 104 |
wp_redirect( admin_url( 'edit-comments.php?error=1' ) ); |
105 |
die(); |
|
106 |
} |
|
0 | 107 |
|
9 | 108 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
109 |
wp_redirect( admin_url( 'edit-comments.php?error=2' ) ); |
|
110 |
die(); |
|
111 |
} |
|
0 | 112 |
|
9 | 113 |
// No need to re-approve/re-trash/re-spam a comment. |
16 | 114 |
if ( str_replace( '1', 'approve', $comment->comment_approved ) === $action ) { |
9 | 115 |
wp_redirect( admin_url( 'edit-comments.php?same=' . $comment_id ) ); |
116 |
die(); |
|
117 |
} |
|
0 | 118 |
|
16 | 119 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 120 |
|
9 | 121 |
$formaction = $action . 'comment'; |
16 | 122 |
$nonce_action = ( 'approve' === $action ) ? 'approve-comment_' : 'delete-comment_'; |
9 | 123 |
$nonce_action .= $comment_id; |
0 | 124 |
|
9 | 125 |
?> |
126 |
<div class="wrap"> |
|
0 | 127 |
|
9 | 128 |
<h1><?php echo esc_html( $title ); ?></h1> |
0 | 129 |
|
9 | 130 |
<?php |
131 |
switch ( $action ) { |
|
132 |
case 'spam': |
|
133 |
$caution_msg = __( 'You are about to mark the following comment as spam:' ); |
|
16 | 134 |
$button = _x( 'Mark as spam', 'comment' ); |
9 | 135 |
break; |
136 |
case 'trash': |
|
137 |
$caution_msg = __( 'You are about to move the following comment to the Trash:' ); |
|
138 |
$button = __( 'Move to Trash' ); |
|
139 |
break; |
|
140 |
case 'delete': |
|
141 |
$caution_msg = __( 'You are about to delete the following comment:' ); |
|
16 | 142 |
$button = __( 'Permanently delete comment' ); |
9 | 143 |
break; |
144 |
default: |
|
145 |
$caution_msg = __( 'You are about to approve the following comment:' ); |
|
16 | 146 |
$button = __( 'Approve comment' ); |
9 | 147 |
break; |
148 |
} |
|
0 | 149 |
|
16 | 150 |
if ( '0' !== $comment->comment_approved ) { // If not unapproved. |
9 | 151 |
$message = ''; |
152 |
switch ( $comment->comment_approved ) { |
|
153 |
case '1': |
|
154 |
$message = __( 'This comment is currently approved.' ); |
|
155 |
break; |
|
156 |
case 'spam': |
|
157 |
$message = __( 'This comment is currently marked as spam.' ); |
|
158 |
break; |
|
159 |
case 'trash': |
|
160 |
$message = __( 'This comment is currently in the Trash.' ); |
|
161 |
break; |
|
162 |
} |
|
163 |
if ( $message ) { |
|
164 |
echo '<div id="message" class="notice notice-info"><p>' . $message . '</p></div>'; |
|
165 |
} |
|
166 |
} |
|
167 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
<div id="message" class="notice notice-warning"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo $caution_msg; ?></p></div> |
0 | 169 |
|
170 |
<table class="form-table comment-ays"> |
|
5 | 171 |
<tr> |
18 | 172 |
<th scope="row"><?php _e( 'Author' ); ?></th> |
173 |
<td><?php comment_author( $comment ); ?></td> |
|
0 | 174 |
</tr> |
9 | 175 |
<?php if ( get_comment_author_email( $comment ) ) { ?> |
0 | 176 |
<tr> |
18 | 177 |
<th scope="row"><?php _e( 'Email' ); ?></th> |
178 |
<td><?php comment_author_email( $comment ); ?></td> |
|
0 | 179 |
</tr> |
180 |
<?php } ?> |
|
9 | 181 |
<?php if ( get_comment_author_url( $comment ) ) { ?> |
0 | 182 |
<tr> |
18 | 183 |
<th scope="row"><?php _e( 'URL' ); ?></th> |
184 |
<td><a href="<?php comment_author_url( $comment ); ?>"><?php comment_author_url( $comment ); ?></a></td> |
|
0 | 185 |
</tr> |
186 |
<?php } ?> |
|
187 |
<tr> |
|
16 | 188 |
<th scope="row"><?php /* translators: Column name or table row header. */ _e( 'In response to' ); ?></th> |
5 | 189 |
<td> |
9 | 190 |
<?php |
5 | 191 |
$post_id = $comment->comment_post_ID; |
192 |
if ( current_user_can( 'edit_post', $post_id ) ) { |
|
9 | 193 |
$post_link = "<a href='" . esc_url( get_edit_post_link( $post_id ) ) . "'>"; |
5 | 194 |
$post_link .= esc_html( get_the_title( $post_id ) ) . '</a>'; |
195 |
} else { |
|
196 |
$post_link = esc_html( get_the_title( $post_id ) ); |
|
197 |
} |
|
198 |
echo $post_link; |
|
199 |
||
200 |
if ( $comment->comment_parent ) { |
|
201 |
$parent = get_comment( $comment->comment_parent ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
$parent_link = esc_url( get_comment_link( $parent ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
$name = get_comment_author( $parent ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
printf( |
16 | 205 |
/* translators: %s: Comment link. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
' | ' . __( 'In reply to %s.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
'<a href="' . $parent_link . '">' . $name . '</a>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
); |
5 | 209 |
} |
9 | 210 |
?> |
5 | 211 |
</td> |
18 | 212 |
</tr> |
213 |
<tr> |
|
5 | 214 |
<th scope="row"><?php _e( 'Submitted on' ); ?></th> |
215 |
<td> |
|
9 | 216 |
<?php |
217 |
$submitted = sprintf( |
|
16 | 218 |
/* translators: 1: Comment date, 2: Comment time. */ |
9 | 219 |
__( '%1$s at %2$s' ), |
18 | 220 |
/* translators: Comment date format. See https://www.php.net/manual/datetime.format.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
get_comment_date( __( 'Y/m/d' ), $comment ), |
18 | 222 |
/* translators: Comment time format. See https://www.php.net/manual/datetime.format.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
get_comment_date( __( 'g:i a' ), $comment ) |
5 | 224 |
); |
9 | 225 |
if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
echo $submitted; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
} |
9 | 230 |
?> |
18 | 231 |
</td> |
232 |
</tr> |
|
233 |
<tr> |
|
16 | 234 |
<th scope="row"><?php /* translators: Field name in comment form. */ _ex( 'Comment', 'noun' ); ?></th> |
9 | 235 |
<td class="comment-content"> |
236 |
<?php comment_text( $comment ); ?> |
|
18 | 237 |
<p class="edit-comment"> |
238 |
<a href="<?php echo esc_url( admin_url( "comment.php?action=editcomment&c={$comment->comment_ID}" ) ); ?>"><?php esc_html_e( 'Edit' ); ?></a> |
|
239 |
</p> |
|
5 | 240 |
</td> |
18 | 241 |
</tr> |
242 |
</table> |
|
0 | 243 |
|
18 | 244 |
<form action="comment.php" method="get" class="comment-ays-submit"> |
9 | 245 |
<p> |
246 |
<?php submit_button( $button, 'primary', 'submit', false ); ?> |
|
18 | 247 |
<a href="<?php echo esc_url( admin_url( 'edit-comments.php' ) ); ?>" class="button-cancel"><?php esc_html_e( 'Cancel' ); ?></a> |
9 | 248 |
</p> |
0 | 249 |
|
9 | 250 |
<?php wp_nonce_field( $nonce_action ); ?> |
251 |
<input type="hidden" name="action" value="<?php echo esc_attr( $formaction ); ?>" /> |
|
252 |
<input type="hidden" name="c" value="<?php echo esc_attr( $comment->comment_ID ); ?>" /> |
|
253 |
<input type="hidden" name="noredir" value="1" /> |
|
18 | 254 |
</form> |
0 | 255 |
|
18 | 256 |
</div> |
9 | 257 |
<?php |
258 |
break; |
|
0 | 259 |
|
9 | 260 |
case 'deletecomment': |
261 |
case 'trashcomment': |
|
262 |
case 'untrashcomment': |
|
263 |
case 'spamcomment': |
|
264 |
case 'unspamcomment': |
|
265 |
case 'approvecomment': |
|
266 |
case 'unapprovecomment': |
|
267 |
$comment_id = absint( $_REQUEST['c'] ); |
|
0 | 268 |
|
16 | 269 |
if ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { |
9 | 270 |
check_admin_referer( 'approve-comment_' . $comment_id ); |
271 |
} else { |
|
272 |
check_admin_referer( 'delete-comment_' . $comment_id ); |
|
273 |
} |
|
0 | 274 |
|
9 | 275 |
$noredir = isset( $_REQUEST['noredir'] ); |
0 | 276 |
|
16 | 277 |
$comment = get_comment( $comment_id ); |
278 |
if ( ! $comment ) { |
|
9 | 279 |
comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' <a href="%s">' . __( 'Go back' ) . '</a>.', 'edit-comments.php' ) ); |
280 |
} |
|
281 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
|
282 |
comment_footer_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); |
|
283 |
} |
|
0 | 284 |
|
16 | 285 |
if ( wp_get_referer() && ! $noredir && false === strpos( wp_get_referer(), 'comment.php' ) ) { |
9 | 286 |
$redir = wp_get_referer(); |
16 | 287 |
} elseif ( wp_get_original_referer() && ! $noredir ) { |
9 | 288 |
$redir = wp_get_original_referer(); |
16 | 289 |
} elseif ( in_array( $action, array( 'approvecomment', 'unapprovecomment' ), true ) ) { |
9 | 290 |
$redir = admin_url( 'edit-comments.php?p=' . absint( $comment->comment_post_ID ) ); |
291 |
} else { |
|
292 |
$redir = admin_url( 'edit-comments.php' ); |
|
293 |
} |
|
0 | 294 |
|
9 | 295 |
$redir = remove_query_arg( array( 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved' ), $redir ); |
0 | 296 |
|
9 | 297 |
switch ( $action ) { |
298 |
case 'deletecomment': |
|
299 |
wp_delete_comment( $comment ); |
|
300 |
$redir = add_query_arg( array( 'deleted' => '1' ), $redir ); |
|
301 |
break; |
|
302 |
case 'trashcomment': |
|
303 |
wp_trash_comment( $comment ); |
|
304 |
$redir = add_query_arg( |
|
305 |
array( |
|
306 |
'trashed' => '1', |
|
307 |
'ids' => $comment_id, |
|
308 |
), |
|
309 |
$redir |
|
310 |
); |
|
311 |
break; |
|
312 |
case 'untrashcomment': |
|
313 |
wp_untrash_comment( $comment ); |
|
314 |
$redir = add_query_arg( array( 'untrashed' => '1' ), $redir ); |
|
315 |
break; |
|
316 |
case 'spamcomment': |
|
317 |
wp_spam_comment( $comment ); |
|
318 |
$redir = add_query_arg( |
|
319 |
array( |
|
320 |
'spammed' => '1', |
|
321 |
'ids' => $comment_id, |
|
322 |
), |
|
323 |
$redir |
|
324 |
); |
|
325 |
break; |
|
326 |
case 'unspamcomment': |
|
327 |
wp_unspam_comment( $comment ); |
|
328 |
$redir = add_query_arg( array( 'unspammed' => '1' ), $redir ); |
|
329 |
break; |
|
330 |
case 'approvecomment': |
|
331 |
wp_set_comment_status( $comment, 'approve' ); |
|
332 |
$redir = add_query_arg( array( 'approved' => 1 ), $redir ); |
|
333 |
break; |
|
334 |
case 'unapprovecomment': |
|
335 |
wp_set_comment_status( $comment, 'hold' ); |
|
336 |
$redir = add_query_arg( array( 'unapproved' => 1 ), $redir ); |
|
337 |
break; |
|
338 |
} |
|
0 | 339 |
|
9 | 340 |
wp_redirect( $redir ); |
341 |
die; |
|
0 | 342 |
|
9 | 343 |
case 'editedcomment': |
344 |
$comment_id = absint( $_POST['comment_ID'] ); |
|
345 |
$comment_post_id = absint( $_POST['comment_post_ID'] ); |
|
0 | 346 |
|
9 | 347 |
check_admin_referer( 'update-comment_' . $comment_id ); |
0 | 348 |
|
16 | 349 |
$updated = edit_comment(); |
350 |
if ( is_wp_error( $updated ) ) { |
|
351 |
wp_die( $updated->get_error_message() ); |
|
352 |
} |
|
0 | 353 |
|
9 | 354 |
$location = ( empty( $_POST['referredby'] ) ? "edit-comments.php?p=$comment_post_id" : $_POST['referredby'] ) . '#comment-' . $comment_id; |
0 | 355 |
|
9 | 356 |
/** |
357 |
* Filters the URI the user is redirected to after editing a comment in the admin. |
|
358 |
* |
|
359 |
* @since 2.1.0 |
|
360 |
* |
|
361 |
* @param string $location The URI the user will be redirected to. |
|
362 |
* @param int $comment_id The ID of the comment being edited. |
|
363 |
*/ |
|
364 |
$location = apply_filters( 'comment_edit_redirect', $location, $comment_id ); |
|
16 | 365 |
|
9 | 366 |
wp_redirect( $location ); |
16 | 367 |
exit; |
0 | 368 |
|
9 | 369 |
default: |
370 |
wp_die( __( 'Unknown action.' ) ); |
|
0 | 371 |
|
16 | 372 |
} // End switch. |
0 | 373 |
|
16 | 374 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |