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