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