Edit File by line
/home/barbar84/www/wp-inclu...
File: comment.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Core Comment API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Comment
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Check whether a comment passes internal checks to be allowed to add.
[9] Fix | Delete
*
[10] Fix | Delete
* If manual comment moderation is set in the administration, then all checks,
[11] Fix | Delete
* regardless of their type and substance, will fail and the function will
[12] Fix | Delete
* return false.
[13] Fix | Delete
*
[14] Fix | Delete
* If the number of links exceeds the amount in the administration, then the
[15] Fix | Delete
* check fails. If any of the parameter contents contain any disallowed words,
[16] Fix | Delete
* then the check fails.
[17] Fix | Delete
*
[18] Fix | Delete
* If the comment author was approved before, then the comment is automatically
[19] Fix | Delete
* approved.
[20] Fix | Delete
*
[21] Fix | Delete
* If all checks pass, the function will return true.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 1.2.0
[24] Fix | Delete
*
[25] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[26] Fix | Delete
*
[27] Fix | Delete
* @param string $author Comment author name.
[28] Fix | Delete
* @param string $email Comment author email.
[29] Fix | Delete
* @param string $url Comment author URL.
[30] Fix | Delete
* @param string $comment Content of the comment.
[31] Fix | Delete
* @param string $user_ip Comment author IP address.
[32] Fix | Delete
* @param string $user_agent Comment author User-Agent.
[33] Fix | Delete
* @param string $comment_type Comment type, either user-submitted comment,
[34] Fix | Delete
* trackback, or pingback.
[35] Fix | Delete
* @return bool If all checks pass, true, otherwise false.
[36] Fix | Delete
*/
[37] Fix | Delete
function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type ) {
[38] Fix | Delete
global $wpdb;
[39] Fix | Delete
[40] Fix | Delete
// If manual moderation is enabled, skip all checks and return false.
[41] Fix | Delete
if ( 1 == get_option( 'comment_moderation' ) ) {
[42] Fix | Delete
return false;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/** This filter is documented in wp-includes/comment-template.php */
[46] Fix | Delete
$comment = apply_filters( 'comment_text', $comment, null, array() );
[47] Fix | Delete
[48] Fix | Delete
// Check for the number of external links if a max allowed number is set.
[49] Fix | Delete
$max_links = get_option( 'comment_max_links' );
[50] Fix | Delete
if ( $max_links ) {
[51] Fix | Delete
$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Filters the number of links found in a comment.
[55] Fix | Delete
*
[56] Fix | Delete
* @since 3.0.0
[57] Fix | Delete
* @since 4.7.0 Added the `$comment` parameter.
[58] Fix | Delete
*
[59] Fix | Delete
* @param int $num_links The number of links found.
[60] Fix | Delete
* @param string $url Comment author's URL. Included in allowed links total.
[61] Fix | Delete
* @param string $comment Content of the comment.
[62] Fix | Delete
*/
[63] Fix | Delete
$num_links = apply_filters( 'comment_max_links_url', $num_links, $url, $comment );
[64] Fix | Delete
[65] Fix | Delete
/*
[66] Fix | Delete
* If the number of links in the comment exceeds the allowed amount,
[67] Fix | Delete
* fail the check by returning false.
[68] Fix | Delete
*/
[69] Fix | Delete
if ( $num_links >= $max_links ) {
[70] Fix | Delete
return false;
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$mod_keys = trim( get_option( 'moderation_keys' ) );
[75] Fix | Delete
[76] Fix | Delete
// If moderation 'keys' (keywords) are set, process them.
[77] Fix | Delete
if ( ! empty( $mod_keys ) ) {
[78] Fix | Delete
$words = explode( "\n", $mod_keys );
[79] Fix | Delete
[80] Fix | Delete
foreach ( (array) $words as $word ) {
[81] Fix | Delete
$word = trim( $word );
[82] Fix | Delete
[83] Fix | Delete
// Skip empty lines.
[84] Fix | Delete
if ( empty( $word ) ) {
[85] Fix | Delete
continue;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/*
[89] Fix | Delete
* Do some escaping magic so that '#' (number of) characters in the spam
[90] Fix | Delete
* words don't break things:
[91] Fix | Delete
*/
[92] Fix | Delete
$word = preg_quote( $word, '#' );
[93] Fix | Delete
[94] Fix | Delete
/*
[95] Fix | Delete
* Check the comment fields for moderation keywords. If any are found,
[96] Fix | Delete
* fail the check for the given field by returning false.
[97] Fix | Delete
*/
[98] Fix | Delete
$pattern = "#$word#i";
[99] Fix | Delete
if ( preg_match( $pattern, $author ) ) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
if ( preg_match( $pattern, $email ) ) {
[103] Fix | Delete
return false;
[104] Fix | Delete
}
[105] Fix | Delete
if ( preg_match( $pattern, $url ) ) {
[106] Fix | Delete
return false;
[107] Fix | Delete
}
[108] Fix | Delete
if ( preg_match( $pattern, $comment ) ) {
[109] Fix | Delete
return false;
[110] Fix | Delete
}
[111] Fix | Delete
if ( preg_match( $pattern, $user_ip ) ) {
[112] Fix | Delete
return false;
[113] Fix | Delete
}
[114] Fix | Delete
if ( preg_match( $pattern, $user_agent ) ) {
[115] Fix | Delete
return false;
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/*
[121] Fix | Delete
* Check if the option to approve comments by previously-approved authors is enabled.
[122] Fix | Delete
*
[123] Fix | Delete
* If it is enabled, check whether the comment author has a previously-approved comment,
[124] Fix | Delete
* as well as whether there are any moderation keywords (if set) present in the author
[125] Fix | Delete
* email address. If both checks pass, return true. Otherwise, return false.
[126] Fix | Delete
*/
[127] Fix | Delete
if ( 1 == get_option( 'comment_previously_approved' ) ) {
[128] Fix | Delete
if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) {
[129] Fix | Delete
$comment_user = get_user_by( 'email', wp_unslash( $email ) );
[130] Fix | Delete
if ( ! empty( $comment_user->ID ) ) {
[131] Fix | Delete
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 1", $comment_user->ID ) );
[132] Fix | Delete
} else {
[133] Fix | Delete
// expected_slashed ($author, $email)
[134] Fix | Delete
$ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author, $email ) );
[135] Fix | Delete
}
[136] Fix | Delete
if ( ( 1 == $ok_to_comment ) &&
[137] Fix | Delete
( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) {
[138] Fix | Delete
return true;
[139] Fix | Delete
} else {
[140] Fix | Delete
return false;
[141] Fix | Delete
}
[142] Fix | Delete
} else {
[143] Fix | Delete
return false;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
return true;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Retrieve the approved comments for post $post_id.
[151] Fix | Delete
*
[152] Fix | Delete
* @since 2.0.0
[153] Fix | Delete
* @since 4.1.0 Refactored to leverage WP_Comment_Query over a direct query.
[154] Fix | Delete
*
[155] Fix | Delete
* @param int $post_id The ID of the post.
[156] Fix | Delete
* @param array $args Optional. See WP_Comment_Query::__construct() for information on accepted arguments.
[157] Fix | Delete
* @return int|array The approved comments, or number of comments if `$count`
[158] Fix | Delete
* argument is true.
[159] Fix | Delete
*/
[160] Fix | Delete
function get_approved_comments( $post_id, $args = array() ) {
[161] Fix | Delete
if ( ! $post_id ) {
[162] Fix | Delete
return array();
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
$defaults = array(
[166] Fix | Delete
'status' => 1,
[167] Fix | Delete
'post_id' => $post_id,
[168] Fix | Delete
'order' => 'ASC',
[169] Fix | Delete
);
[170] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[171] Fix | Delete
[172] Fix | Delete
$query = new WP_Comment_Query;
[173] Fix | Delete
return $query->query( $parsed_args );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Retrieves comment data given a comment ID or comment object.
[178] Fix | Delete
*
[179] Fix | Delete
* If an object is passed then the comment data will be cached and then returned
[180] Fix | Delete
* after being passed through a filter. If the comment is empty, then the global
[181] Fix | Delete
* comment variable will be used, if it is set.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 2.0.0
[184] Fix | Delete
*
[185] Fix | Delete
* @global WP_Comment $comment Global comment object.
[186] Fix | Delete
*
[187] Fix | Delete
* @param WP_Comment|string|int $comment Comment to retrieve.
[188] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[189] Fix | Delete
* correspond to a WP_Comment object, an associative array, or a numeric array,
[190] Fix | Delete
* respectively. Default OBJECT.
[191] Fix | Delete
* @return WP_Comment|array|null Depends on $output value.
[192] Fix | Delete
*/
[193] Fix | Delete
function get_comment( $comment = null, $output = OBJECT ) {
[194] Fix | Delete
if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
[195] Fix | Delete
$comment = $GLOBALS['comment'];
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
if ( $comment instanceof WP_Comment ) {
[199] Fix | Delete
$_comment = $comment;
[200] Fix | Delete
} elseif ( is_object( $comment ) ) {
[201] Fix | Delete
$_comment = new WP_Comment( $comment );
[202] Fix | Delete
} else {
[203] Fix | Delete
$_comment = WP_Comment::get_instance( $comment );
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
if ( ! $_comment ) {
[207] Fix | Delete
return null;
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Fires after a comment is retrieved.
[212] Fix | Delete
*
[213] Fix | Delete
* @since 2.3.0
[214] Fix | Delete
*
[215] Fix | Delete
* @param WP_Comment $_comment Comment data.
[216] Fix | Delete
*/
[217] Fix | Delete
$_comment = apply_filters( 'get_comment', $_comment );
[218] Fix | Delete
[219] Fix | Delete
if ( OBJECT == $output ) {
[220] Fix | Delete
return $_comment;
[221] Fix | Delete
} elseif ( ARRAY_A == $output ) {
[222] Fix | Delete
return $_comment->to_array();
[223] Fix | Delete
} elseif ( ARRAY_N == $output ) {
[224] Fix | Delete
return array_values( $_comment->to_array() );
[225] Fix | Delete
}
[226] Fix | Delete
return $_comment;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Retrieve a list of comments.
[231] Fix | Delete
*
[232] Fix | Delete
* The comment list can be for the blog as a whole or for an individual post.
[233] Fix | Delete
*
[234] Fix | Delete
* @since 2.7.0
[235] Fix | Delete
*
[236] Fix | Delete
* @param string|array $args Optional. Array or string of arguments. See WP_Comment_Query::__construct()
[237] Fix | Delete
* for information on accepted arguments. Default empty.
[238] Fix | Delete
* @return int|array List of comments or number of found comments if `$count` argument is true.
[239] Fix | Delete
*/
[240] Fix | Delete
function get_comments( $args = '' ) {
[241] Fix | Delete
$query = new WP_Comment_Query;
[242] Fix | Delete
return $query->query( $args );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* Retrieve all of the WordPress supported comment statuses.
[247] Fix | Delete
*
[248] Fix | Delete
* Comments have a limited set of valid status values, this provides the comment
[249] Fix | Delete
* status values and descriptions.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 2.7.0
[252] Fix | Delete
*
[253] Fix | Delete
* @return string[] List of comment status labels keyed by status.
[254] Fix | Delete
*/
[255] Fix | Delete
function get_comment_statuses() {
[256] Fix | Delete
$status = array(
[257] Fix | Delete
'hold' => __( 'Unapproved' ),
[258] Fix | Delete
'approve' => _x( 'Approved', 'comment status' ),
[259] Fix | Delete
'spam' => _x( 'Spam', 'comment status' ),
[260] Fix | Delete
'trash' => _x( 'Trash', 'comment status' ),
[261] Fix | Delete
);
[262] Fix | Delete
[263] Fix | Delete
return $status;
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Gets the default comment status for a post type.
[268] Fix | Delete
*
[269] Fix | Delete
* @since 4.3.0
[270] Fix | Delete
*
[271] Fix | Delete
* @param string $post_type Optional. Post type. Default 'post'.
[272] Fix | Delete
* @param string $comment_type Optional. Comment type. Default 'comment'.
[273] Fix | Delete
* @return string Expected return value is 'open' or 'closed'.
[274] Fix | Delete
*/
[275] Fix | Delete
function get_default_comment_status( $post_type = 'post', $comment_type = 'comment' ) {
[276] Fix | Delete
switch ( $comment_type ) {
[277] Fix | Delete
case 'pingback':
[278] Fix | Delete
case 'trackback':
[279] Fix | Delete
$supports = 'trackbacks';
[280] Fix | Delete
$option = 'ping';
[281] Fix | Delete
break;
[282] Fix | Delete
default:
[283] Fix | Delete
$supports = 'comments';
[284] Fix | Delete
$option = 'comment';
[285] Fix | Delete
break;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
// Set the status.
[289] Fix | Delete
if ( 'page' === $post_type ) {
[290] Fix | Delete
$status = 'closed';
[291] Fix | Delete
} elseif ( post_type_supports( $post_type, $supports ) ) {
[292] Fix | Delete
$status = get_option( "default_{$option}_status" );
[293] Fix | Delete
} else {
[294] Fix | Delete
$status = 'closed';
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Filters the default comment status for the given post type.
[299] Fix | Delete
*
[300] Fix | Delete
* @since 4.3.0
[301] Fix | Delete
*
[302] Fix | Delete
* @param string $status Default status for the given post type,
[303] Fix | Delete
* either 'open' or 'closed'.
[304] Fix | Delete
* @param string $post_type Post type. Default is `post`.
[305] Fix | Delete
* @param string $comment_type Type of comment. Default is `comment`.
[306] Fix | Delete
*/
[307] Fix | Delete
return apply_filters( 'get_default_comment_status', $status, $post_type, $comment_type );
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
/**
[311] Fix | Delete
* The date the last comment was modified.
[312] Fix | Delete
*
[313] Fix | Delete
* @since 1.5.0
[314] Fix | Delete
* @since 4.7.0 Replaced caching the modified date in a local static variable
[315] Fix | Delete
* with the Object Cache API.
[316] Fix | Delete
*
[317] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[318] Fix | Delete
*
[319] Fix | Delete
* @param string $timezone Which timezone to use in reference to 'gmt', 'blog', or 'server' locations.
[320] Fix | Delete
* @return string|false Last comment modified date on success, false on failure.
[321] Fix | Delete
*/
[322] Fix | Delete
function get_lastcommentmodified( $timezone = 'server' ) {
[323] Fix | Delete
global $wpdb;
[324] Fix | Delete
[325] Fix | Delete
$timezone = strtolower( $timezone );
[326] Fix | Delete
$key = "lastcommentmodified:$timezone";
[327] Fix | Delete
[328] Fix | Delete
$comment_modified_date = wp_cache_get( $key, 'timeinfo' );
[329] Fix | Delete
if ( false !== $comment_modified_date ) {
[330] Fix | Delete
return $comment_modified_date;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
switch ( $timezone ) {
[334] Fix | Delete
case 'gmt':
[335] Fix | Delete
$comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );
[336] Fix | Delete
break;
[337] Fix | Delete
case 'blog':
[338] Fix | Delete
$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );
[339] Fix | Delete
break;
[340] Fix | Delete
case 'server':
[341] Fix | Delete
$add_seconds_server = gmdate( 'Z' );
[342] Fix | Delete
[343] Fix | Delete
$comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) );
[344] Fix | Delete
break;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
if ( $comment_modified_date ) {
[348] Fix | Delete
wp_cache_set( $key, $comment_modified_date, 'timeinfo' );
[349] Fix | Delete
[350] Fix | Delete
return $comment_modified_date;
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
return false;
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Retrieves the total comment counts for the whole site or a single post.
[358] Fix | Delete
*
[359] Fix | Delete
* Unlike wp_count_comments(), this function always returns the live comment counts without caching.
[360] Fix | Delete
*
[361] Fix | Delete
* @since 2.0.0
[362] Fix | Delete
*
[363] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[364] Fix | Delete
*
[365] Fix | Delete
* @param int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that
[366] Fix | Delete
* comment counts for the whole site will be retrieved.
[367] Fix | Delete
* @return array() {
[368] Fix | Delete
* The number of comments keyed by their status.
[369] Fix | Delete
*
[370] Fix | Delete
* @type int $approved The number of approved comments.
[371] Fix | Delete
* @type int $awaiting_moderation The number of comments awaiting moderation (a.k.a. pending).
[372] Fix | Delete
* @type int $spam The number of spam comments.
[373] Fix | Delete
* @type int $trash The number of trashed comments.
[374] Fix | Delete
* @type int $post-trashed The number of comments for posts that are in the trash.
[375] Fix | Delete
* @type int $total_comments The total number of non-trashed comments, including spam.
[376] Fix | Delete
* @type int $all The total number of pending or approved comments.
[377] Fix | Delete
* }
[378] Fix | Delete
*/
[379] Fix | Delete
function get_comment_count( $post_id = 0 ) {
[380] Fix | Delete
global $wpdb;
[381] Fix | Delete
[382] Fix | Delete
$post_id = (int) $post_id;
[383] Fix | Delete
[384] Fix | Delete
$where = '';
[385] Fix | Delete
if ( $post_id > 0 ) {
[386] Fix | Delete
$where = $wpdb->prepare( 'WHERE comment_post_ID = %d', $post_id );
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
$totals = (array) $wpdb->get_results(
[390] Fix | Delete
"
[391] Fix | Delete
SELECT comment_approved, COUNT( * ) AS total
[392] Fix | Delete
FROM {$wpdb->comments}
[393] Fix | Delete
{$where}
[394] Fix | Delete
GROUP BY comment_approved
[395] Fix | Delete
",
[396] Fix | Delete
ARRAY_A
[397] Fix | Delete
);
[398] Fix | Delete
[399] Fix | Delete
$comment_count = array(
[400] Fix | Delete
'approved' => 0,
[401] Fix | Delete
'awaiting_moderation' => 0,
[402] Fix | Delete
'spam' => 0,
[403] Fix | Delete
'trash' => 0,
[404] Fix | Delete
'post-trashed' => 0,
[405] Fix | Delete
'total_comments' => 0,
[406] Fix | Delete
'all' => 0,
[407] Fix | Delete
);
[408] Fix | Delete
[409] Fix | Delete
foreach ( $totals as $row ) {
[410] Fix | Delete
switch ( $row['comment_approved'] ) {
[411] Fix | Delete
case 'trash':
[412] Fix | Delete
$comment_count['trash'] = $row['total'];
[413] Fix | Delete
break;
[414] Fix | Delete
case 'post-trashed':
[415] Fix | Delete
$comment_count['post-trashed'] = $row['total'];
[416] Fix | Delete
break;
[417] Fix | Delete
case 'spam':
[418] Fix | Delete
$comment_count['spam'] = $row['total'];
[419] Fix | Delete
$comment_count['total_comments'] += $row['total'];
[420] Fix | Delete
break;
[421] Fix | Delete
case '1':
[422] Fix | Delete
$comment_count['approved'] = $row['total'];
[423] Fix | Delete
$comment_count['total_comments'] += $row['total'];
[424] Fix | Delete
$comment_count['all'] += $row['total'];
[425] Fix | Delete
break;
[426] Fix | Delete
case '0':
[427] Fix | Delete
$comment_count['awaiting_moderation'] = $row['total'];
[428] Fix | Delete
$comment_count['total_comments'] += $row['total'];
[429] Fix | Delete
$comment_count['all'] += $row['total'];
[430] Fix | Delete
break;
[431] Fix | Delete
default:
[432] Fix | Delete
break;
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
return array_map( 'intval', $comment_count );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
//
[440] Fix | Delete
// Comment meta functions.
[441] Fix | Delete
//
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Add meta data field to a comment.
[445] Fix | Delete
*
[446] Fix | Delete
* @since 2.9.0
[447] Fix | Delete
*
[448] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/add_comment_meta/
[449] Fix | Delete
*
[450] Fix | Delete
* @param int $comment_id Comment ID.
[451] Fix | Delete
* @param string $meta_key Metadata name.
[452] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[453] Fix | Delete
* @param bool $unique Optional. Whether the same key should not be added.
[454] Fix | Delete
* Default false.
[455] Fix | Delete
* @return int|false Meta ID on success, false on failure.
[456] Fix | Delete
*/
[457] Fix | Delete
function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
[458] Fix | Delete
return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
/**
[462] Fix | Delete
* Remove metadata matching criteria from a comment.
[463] Fix | Delete
*
[464] Fix | Delete
* You can match based on the key, or key and value. Removing based on key and
[465] Fix | Delete
* value, will keep from removing duplicate metadata with the same key. It also
[466] Fix | Delete
* allows removing all metadata matching key, if needed.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 2.9.0
[469] Fix | Delete
*
[470] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/delete_comment_meta/
[471] Fix | Delete
*
[472] Fix | Delete
* @param int $comment_id Comment ID.
[473] Fix | Delete
* @param string $meta_key Metadata name.
[474] Fix | Delete
* @param mixed $meta_value Optional. Metadata value. If provided,
[475] Fix | Delete
* rows will only be removed that match the value.
[476] Fix | Delete
* Must be serializable if non-scalar. Default empty.
[477] Fix | Delete
* @return bool True on success, false on failure.
[478] Fix | Delete
*/
[479] Fix | Delete
function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
[480] Fix | Delete
return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
/**
[484] Fix | Delete
* Retrieve comment meta field for a comment.
[485] Fix | Delete
*
[486] Fix | Delete
* @since 2.9.0
[487] Fix | Delete
*
[488] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/get_comment_meta/
[489] Fix | Delete
*
[490] Fix | Delete
* @param int $comment_id Comment ID.
[491] Fix | Delete
* @param string $key Optional. The meta key to retrieve. By default,
[492] Fix | Delete
* returns data for all keys.
[493] Fix | Delete
* @param bool $single Optional. Whether to return a single value.
[494] Fix | Delete
* This parameter has no effect if $key is not specified.
[495] Fix | Delete
* Default false.
[496] Fix | Delete
* @return mixed An array if $single is false. The value of meta data field
[497] Fix | Delete
* if $single is true. False for an invalid $comment_id.
[498] Fix | Delete
*/
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function