Edit File by line
/home/barbar84/www/wp-admin/includes
File: comment.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Comment Administration API.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
* @since 2.3.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Determine if a comment exists based on author and date.
[10] Fix | Delete
*
[11] Fix | Delete
* For best performance, use `$timezone = 'gmt'`, which queries a field that is properly indexed. The default value
[12] Fix | Delete
* for `$timezone` is 'blog' for legacy reasons.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 2.0.0
[15] Fix | Delete
* @since 4.4.0 Added the `$timezone` parameter.
[16] Fix | Delete
*
[17] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[18] Fix | Delete
*
[19] Fix | Delete
* @param string $comment_author Author of the comment.
[20] Fix | Delete
* @param string $comment_date Date of the comment.
[21] Fix | Delete
* @param string $timezone Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
[22] Fix | Delete
* @return string|null Comment post ID on success.
[23] Fix | Delete
*/
[24] Fix | Delete
function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
[25] Fix | Delete
global $wpdb;
[26] Fix | Delete
[27] Fix | Delete
$date_field = 'comment_date';
[28] Fix | Delete
if ( 'gmt' === $timezone ) {
[29] Fix | Delete
$date_field = 'comment_date_gmt';
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
return $wpdb->get_var(
[33] Fix | Delete
$wpdb->prepare(
[34] Fix | Delete
"SELECT comment_post_ID FROM $wpdb->comments
[35] Fix | Delete
WHERE comment_author = %s AND $date_field = %s",
[36] Fix | Delete
stripslashes( $comment_author ),
[37] Fix | Delete
stripslashes( $comment_date )
[38] Fix | Delete
)
[39] Fix | Delete
);
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Update a comment with values provided in $_POST.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 2.0.0
[46] Fix | Delete
* @since 5.5.0 A return value was added.
[47] Fix | Delete
*
[48] Fix | Delete
* @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
[49] Fix | Delete
* A WP_Error object on failure.
[50] Fix | Delete
*/
[51] Fix | Delete
function edit_comment() {
[52] Fix | Delete
if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
[53] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
if ( isset( $_POST['newcomment_author'] ) ) {
[57] Fix | Delete
$_POST['comment_author'] = $_POST['newcomment_author'];
[58] Fix | Delete
}
[59] Fix | Delete
if ( isset( $_POST['newcomment_author_email'] ) ) {
[60] Fix | Delete
$_POST['comment_author_email'] = $_POST['newcomment_author_email'];
[61] Fix | Delete
}
[62] Fix | Delete
if ( isset( $_POST['newcomment_author_url'] ) ) {
[63] Fix | Delete
$_POST['comment_author_url'] = $_POST['newcomment_author_url'];
[64] Fix | Delete
}
[65] Fix | Delete
if ( isset( $_POST['comment_status'] ) ) {
[66] Fix | Delete
$_POST['comment_approved'] = $_POST['comment_status'];
[67] Fix | Delete
}
[68] Fix | Delete
if ( isset( $_POST['content'] ) ) {
[69] Fix | Delete
$_POST['comment_content'] = $_POST['content'];
[70] Fix | Delete
}
[71] Fix | Delete
if ( isset( $_POST['comment_ID'] ) ) {
[72] Fix | Delete
$_POST['comment_ID'] = (int) $_POST['comment_ID'];
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
[76] Fix | Delete
if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] != $_POST[ $timeunit ] ) {
[77] Fix | Delete
$_POST['edit_date'] = '1';
[78] Fix | Delete
break;
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
if ( ! empty( $_POST['edit_date'] ) ) {
[83] Fix | Delete
$aa = $_POST['aa'];
[84] Fix | Delete
$mm = $_POST['mm'];
[85] Fix | Delete
$jj = $_POST['jj'];
[86] Fix | Delete
$hh = $_POST['hh'];
[87] Fix | Delete
$mn = $_POST['mn'];
[88] Fix | Delete
$ss = $_POST['ss'];
[89] Fix | Delete
$jj = ( $jj > 31 ) ? 31 : $jj;
[90] Fix | Delete
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
[91] Fix | Delete
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
[92] Fix | Delete
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
[93] Fix | Delete
[94] Fix | Delete
$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
return wp_update_comment( $_POST, true );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Returns a WP_Comment object based on comment ID.
[102] Fix | Delete
*
[103] Fix | Delete
* @since 2.0.0
[104] Fix | Delete
*
[105] Fix | Delete
* @param int $id ID of comment to retrieve.
[106] Fix | Delete
* @return WP_Comment|false Comment if found. False on failure.
[107] Fix | Delete
*/
[108] Fix | Delete
function get_comment_to_edit( $id ) {
[109] Fix | Delete
$comment = get_comment( $id );
[110] Fix | Delete
if ( ! $comment ) {
[111] Fix | Delete
return false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$comment->comment_ID = (int) $comment->comment_ID;
[115] Fix | Delete
$comment->comment_post_ID = (int) $comment->comment_post_ID;
[116] Fix | Delete
[117] Fix | Delete
$comment->comment_content = format_to_edit( $comment->comment_content );
[118] Fix | Delete
/**
[119] Fix | Delete
* Filters the comment content before editing.
[120] Fix | Delete
*
[121] Fix | Delete
* @since 2.0.0
[122] Fix | Delete
*
[123] Fix | Delete
* @param string $comment_content Comment content.
[124] Fix | Delete
*/
[125] Fix | Delete
$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
[126] Fix | Delete
[127] Fix | Delete
$comment->comment_author = format_to_edit( $comment->comment_author );
[128] Fix | Delete
$comment->comment_author_email = format_to_edit( $comment->comment_author_email );
[129] Fix | Delete
$comment->comment_author_url = format_to_edit( $comment->comment_author_url );
[130] Fix | Delete
$comment->comment_author_url = esc_url( $comment->comment_author_url );
[131] Fix | Delete
[132] Fix | Delete
return $comment;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Get the number of pending comments on a post or posts
[137] Fix | Delete
*
[138] Fix | Delete
* @since 2.3.0
[139] Fix | Delete
*
[140] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[141] Fix | Delete
*
[142] Fix | Delete
* @param int|int[] $post_id Either a single Post ID or an array of Post IDs
[143] Fix | Delete
* @return int|int[] Either a single Posts pending comments as an int or an array of ints keyed on the Post IDs
[144] Fix | Delete
*/
[145] Fix | Delete
function get_pending_comments_num( $post_id ) {
[146] Fix | Delete
global $wpdb;
[147] Fix | Delete
[148] Fix | Delete
$single = false;
[149] Fix | Delete
if ( ! is_array( $post_id ) ) {
[150] Fix | Delete
$post_id_array = (array) $post_id;
[151] Fix | Delete
$single = true;
[152] Fix | Delete
} else {
[153] Fix | Delete
$post_id_array = $post_id;
[154] Fix | Delete
}
[155] Fix | Delete
$post_id_array = array_map( 'intval', $post_id_array );
[156] Fix | Delete
$post_id_in = "'" . implode( "', '", $post_id_array ) . "'";
[157] Fix | Delete
[158] Fix | Delete
$pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
[159] Fix | Delete
[160] Fix | Delete
if ( $single ) {
[161] Fix | Delete
if ( empty( $pending ) ) {
[162] Fix | Delete
return 0;
[163] Fix | Delete
} else {
[164] Fix | Delete
return absint( $pending[0]['num_comments'] );
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
$pending_keyed = array();
[169] Fix | Delete
[170] Fix | Delete
// Default to zero pending for all posts in request.
[171] Fix | Delete
foreach ( $post_id_array as $id ) {
[172] Fix | Delete
$pending_keyed[ $id ] = 0;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
if ( ! empty( $pending ) ) {
[176] Fix | Delete
foreach ( $pending as $pend ) {
[177] Fix | Delete
$pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
return $pending_keyed;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Adds avatars to relevant places in admin.
[186] Fix | Delete
*
[187] Fix | Delete
* @since 2.5.0
[188] Fix | Delete
*
[189] Fix | Delete
* @param string $name User name.
[190] Fix | Delete
* @return string Avatar with the user name.
[191] Fix | Delete
*/
[192] Fix | Delete
function floated_admin_avatar( $name ) {
[193] Fix | Delete
$avatar = get_avatar( get_comment(), 32, 'mystery' );
[194] Fix | Delete
return "$avatar $name";
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* @since 2.7.0
[199] Fix | Delete
*/
[200] Fix | Delete
function enqueue_comment_hotkeys_js() {
[201] Fix | Delete
if ( 'true' === get_user_option( 'comment_shortcuts' ) ) {
[202] Fix | Delete
wp_enqueue_script( 'jquery-table-hotkeys' );
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Display error message at bottom of comments.
[208] Fix | Delete
*
[209] Fix | Delete
* @param string $msg Error Message. Assumed to contain HTML and be sanitized.
[210] Fix | Delete
*/
[211] Fix | Delete
function comment_footer_die( $msg ) {
[212] Fix | Delete
echo "<div class='wrap'><p>$msg</p></div>";
[213] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[214] Fix | Delete
die;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function