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