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