Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: comment.php
* @link https://developer.wordpress.org/reference/functions/get_comment_meta/
[500] Fix | Delete
*
[501] Fix | Delete
* @param int $comment_id Comment ID.
[502] Fix | Delete
* @param string $key Optional. The meta key to retrieve. By default,
[503] Fix | Delete
* returns data for all keys. Default empty string.
[504] Fix | Delete
* @param bool $single Optional. Whether to return a single value.
[505] Fix | Delete
* This parameter has no effect if `$key` is not specified.
[506] Fix | Delete
* Default false.
[507] Fix | Delete
* @return mixed An array of values if `$single` is false.
[508] Fix | Delete
* The value of meta data field if `$single` is true.
[509] Fix | Delete
* False for an invalid `$comment_id` (non-numeric, zero, or negative value).
[510] Fix | Delete
* An empty array if a valid but non-existing comment ID is passed and `$single` is false.
[511] Fix | Delete
* An empty string if a valid but non-existing comment ID is passed and `$single` is true.
[512] Fix | Delete
* Note: Non-serialized values are returned as strings:
[513] Fix | Delete
* - false values are returned as empty strings ('')
[514] Fix | Delete
* - true values are returned as '1'
[515] Fix | Delete
* - numbers are returned as strings
[516] Fix | Delete
* Arrays and objects retain their original type.
[517] Fix | Delete
*/
[518] Fix | Delete
function get_comment_meta( $comment_id, $key = '', $single = false ) {
[519] Fix | Delete
return get_metadata( 'comment', $comment_id, $key, $single );
[520] Fix | Delete
}
[521] Fix | Delete
[522] Fix | Delete
/**
[523] Fix | Delete
* Queue comment meta for lazy-loading.
[524] Fix | Delete
*
[525] Fix | Delete
* @since 6.3.0
[526] Fix | Delete
*
[527] Fix | Delete
* @param array $comment_ids List of comment IDs.
[528] Fix | Delete
*/
[529] Fix | Delete
function wp_lazyload_comment_meta( array $comment_ids ) {
[530] Fix | Delete
if ( empty( $comment_ids ) ) {
[531] Fix | Delete
return;
[532] Fix | Delete
}
[533] Fix | Delete
$lazyloader = wp_metadata_lazyloader();
[534] Fix | Delete
$lazyloader->queue_objects( 'comment', $comment_ids );
[535] Fix | Delete
}
[536] Fix | Delete
[537] Fix | Delete
/**
[538] Fix | Delete
* Updates comment meta field based on comment ID.
[539] Fix | Delete
*
[540] Fix | Delete
* Use the $prev_value parameter to differentiate between meta fields with the
[541] Fix | Delete
* same key and comment ID.
[542] Fix | Delete
*
[543] Fix | Delete
* If the meta field for the comment does not exist, it will be added.
[544] Fix | Delete
*
[545] Fix | Delete
* For historical reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
[546] Fix | Delete
*
[547] Fix | Delete
* @since 2.9.0
[548] Fix | Delete
*
[549] Fix | Delete
* @link https://developer.wordpress.org/reference/functions/update_comment_meta/
[550] Fix | Delete
*
[551] Fix | Delete
* @param int $comment_id Comment ID.
[552] Fix | Delete
* @param string $meta_key Metadata key.
[553] Fix | Delete
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
[554] Fix | Delete
* @param mixed $prev_value Optional. Previous value to check before updating.
[555] Fix | Delete
* If specified, only update existing metadata entries with
[556] Fix | Delete
* this value. Otherwise, update all entries. Default empty string.
[557] Fix | Delete
* @return int|bool Meta ID if the key didn't exist, true on successful update,
[558] Fix | Delete
* false on failure or if the value passed to the function
[559] Fix | Delete
* is the same as the one that is already in the database.
[560] Fix | Delete
*/
[561] Fix | Delete
function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
[562] Fix | Delete
return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
/**
[566] Fix | Delete
* Sets the cookies used to store an unauthenticated commentator's identity. Typically used
[567] Fix | Delete
* to recall previous comments by this commentator that are still held in moderation.
[568] Fix | Delete
*
[569] Fix | Delete
* @since 3.4.0
[570] Fix | Delete
* @since 4.9.6 The `$cookies_consent` parameter was added.
[571] Fix | Delete
*
[572] Fix | Delete
* @param WP_Comment $comment Comment object.
[573] Fix | Delete
* @param WP_User $user Comment author's user object. The user may not exist.
[574] Fix | Delete
* @param bool $cookies_consent Optional. Comment author's consent to store cookies. Default true.
[575] Fix | Delete
*/
[576] Fix | Delete
function wp_set_comment_cookies( $comment, $user, $cookies_consent = true ) {
[577] Fix | Delete
// If the user already exists, or the user opted out of cookies, don't set cookies.
[578] Fix | Delete
if ( $user->exists() ) {
[579] Fix | Delete
return;
[580] Fix | Delete
}
[581] Fix | Delete
[582] Fix | Delete
if ( false === $cookies_consent ) {
[583] Fix | Delete
// Remove any existing cookies.
[584] Fix | Delete
$past = time() - YEAR_IN_SECONDS;
[585] Fix | Delete
setcookie( 'comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );
[586] Fix | Delete
setcookie( 'comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );
[587] Fix | Delete
setcookie( 'comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );
[588] Fix | Delete
[589] Fix | Delete
return;
[590] Fix | Delete
}
[591] Fix | Delete
[592] Fix | Delete
/**
[593] Fix | Delete
* Filters the lifetime of the comment cookie in seconds.
[594] Fix | Delete
*
[595] Fix | Delete
* @since 2.8.0
[596] Fix | Delete
* @since 6.6.0 The default $seconds value changed from 30000000 to YEAR_IN_SECONDS.
[597] Fix | Delete
*
[598] Fix | Delete
* @param int $seconds Comment cookie lifetime. Default YEAR_IN_SECONDS.
[599] Fix | Delete
*/
[600] Fix | Delete
$comment_cookie_lifetime = time() + apply_filters( 'comment_cookie_lifetime', YEAR_IN_SECONDS );
[601] Fix | Delete
[602] Fix | Delete
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
[603] Fix | Delete
[604] Fix | Delete
setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
[605] Fix | Delete
setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
[606] Fix | Delete
setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );
[607] Fix | Delete
}
[608] Fix | Delete
[609] Fix | Delete
/**
[610] Fix | Delete
* Sanitizes the cookies sent to the user already.
[611] Fix | Delete
*
[612] Fix | Delete
* Will only do anything if the cookies have already been created for the user.
[613] Fix | Delete
* Mostly used after cookies had been sent to use elsewhere.
[614] Fix | Delete
*
[615] Fix | Delete
* @since 2.0.4
[616] Fix | Delete
*/
[617] Fix | Delete
function sanitize_comment_cookies() {
[618] Fix | Delete
if ( isset( $_COOKIE[ 'comment_author_' . COOKIEHASH ] ) ) {
[619] Fix | Delete
/**
[620] Fix | Delete
* Filters the comment author's name cookie before it is set.
[621] Fix | Delete
*
[622] Fix | Delete
* When this filter hook is evaluated in wp_filter_comment(),
[623] Fix | Delete
* the comment author's name string is passed.
[624] Fix | Delete
*
[625] Fix | Delete
* @since 1.5.0
[626] Fix | Delete
*
[627] Fix | Delete
* @param string $author_cookie The comment author name cookie.
[628] Fix | Delete
*/
[629] Fix | Delete
$comment_author = apply_filters( 'pre_comment_author_name', $_COOKIE[ 'comment_author_' . COOKIEHASH ] );
[630] Fix | Delete
$comment_author = wp_unslash( $comment_author );
[631] Fix | Delete
$comment_author = esc_attr( $comment_author );
[632] Fix | Delete
[633] Fix | Delete
$_COOKIE[ 'comment_author_' . COOKIEHASH ] = $comment_author;
[634] Fix | Delete
}
[635] Fix | Delete
[636] Fix | Delete
if ( isset( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
[637] Fix | Delete
/**
[638] Fix | Delete
* Filters the comment author's email cookie before it is set.
[639] Fix | Delete
*
[640] Fix | Delete
* When this filter hook is evaluated in wp_filter_comment(),
[641] Fix | Delete
* the comment author's email string is passed.
[642] Fix | Delete
*
[643] Fix | Delete
* @since 1.5.0
[644] Fix | Delete
*
[645] Fix | Delete
* @param string $author_email_cookie The comment author email cookie.
[646] Fix | Delete
*/
[647] Fix | Delete
$comment_author_email = apply_filters( 'pre_comment_author_email', $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] );
[648] Fix | Delete
$comment_author_email = wp_unslash( $comment_author_email );
[649] Fix | Delete
$comment_author_email = esc_attr( $comment_author_email );
[650] Fix | Delete
[651] Fix | Delete
$_COOKIE[ 'comment_author_email_' . COOKIEHASH ] = $comment_author_email;
[652] Fix | Delete
}
[653] Fix | Delete
[654] Fix | Delete
if ( isset( $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] ) ) {
[655] Fix | Delete
/**
[656] Fix | Delete
* Filters the comment author's URL cookie before it is set.
[657] Fix | Delete
*
[658] Fix | Delete
* When this filter hook is evaluated in wp_filter_comment(),
[659] Fix | Delete
* the comment author's URL string is passed.
[660] Fix | Delete
*
[661] Fix | Delete
* @since 1.5.0
[662] Fix | Delete
*
[663] Fix | Delete
* @param string $author_url_cookie The comment author URL cookie.
[664] Fix | Delete
*/
[665] Fix | Delete
$comment_author_url = apply_filters( 'pre_comment_author_url', $_COOKIE[ 'comment_author_url_' . COOKIEHASH ] );
[666] Fix | Delete
$comment_author_url = wp_unslash( $comment_author_url );
[667] Fix | Delete
[668] Fix | Delete
$_COOKIE[ 'comment_author_url_' . COOKIEHASH ] = $comment_author_url;
[669] Fix | Delete
}
[670] Fix | Delete
}
[671] Fix | Delete
[672] Fix | Delete
/**
[673] Fix | Delete
* Validates whether this comment is allowed to be made.
[674] Fix | Delete
*
[675] Fix | Delete
* @since 2.0.0
[676] Fix | Delete
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function
[677] Fix | Delete
* to return a WP_Error object instead of dying.
[678] Fix | Delete
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
[679] Fix | Delete
*
[680] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[681] Fix | Delete
*
[682] Fix | Delete
* @param array $commentdata Contains information on the comment.
[683] Fix | Delete
* @param bool $wp_error When true, a disallowed comment will result in the function
[684] Fix | Delete
* returning a WP_Error object, rather than executing wp_die().
[685] Fix | Delete
* Default false.
[686] Fix | Delete
* @return int|string|WP_Error Allowed comments return the approval status (0|1|'spam'|'trash').
[687] Fix | Delete
* If `$wp_error` is true, disallowed comments return a WP_Error.
[688] Fix | Delete
*/
[689] Fix | Delete
function wp_allow_comment( $commentdata, $wp_error = false ) {
[690] Fix | Delete
global $wpdb;
[691] Fix | Delete
[692] Fix | Delete
/*
[693] Fix | Delete
* Simple duplicate check.
[694] Fix | Delete
* expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
[695] Fix | Delete
*/
[696] Fix | Delete
$dupe = $wpdb->prepare(
[697] Fix | Delete
"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",
[698] Fix | Delete
wp_unslash( $commentdata['comment_post_ID'] ),
[699] Fix | Delete
wp_unslash( $commentdata['comment_parent'] ),
[700] Fix | Delete
wp_unslash( $commentdata['comment_author'] )
[701] Fix | Delete
);
[702] Fix | Delete
if ( $commentdata['comment_author_email'] ) {
[703] Fix | Delete
$dupe .= $wpdb->prepare(
[704] Fix | Delete
'AND comment_author_email = %s ',
[705] Fix | Delete
wp_unslash( $commentdata['comment_author_email'] )
[706] Fix | Delete
);
[707] Fix | Delete
}
[708] Fix | Delete
$dupe .= $wpdb->prepare(
[709] Fix | Delete
') AND comment_content = %s LIMIT 1',
[710] Fix | Delete
wp_unslash( $commentdata['comment_content'] )
[711] Fix | Delete
);
[712] Fix | Delete
[713] Fix | Delete
$dupe_id = $wpdb->get_var( $dupe );
[714] Fix | Delete
[715] Fix | Delete
/**
[716] Fix | Delete
* Filters the ID, if any, of the duplicate comment found when creating a new comment.
[717] Fix | Delete
*
[718] Fix | Delete
* Return an empty value from this filter to allow what WP considers a duplicate comment.
[719] Fix | Delete
*
[720] Fix | Delete
* @since 4.4.0
[721] Fix | Delete
*
[722] Fix | Delete
* @param int $dupe_id ID of the comment identified as a duplicate.
[723] Fix | Delete
* @param array $commentdata Data for the comment being created.
[724] Fix | Delete
*/
[725] Fix | Delete
$dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata );
[726] Fix | Delete
[727] Fix | Delete
if ( $dupe_id ) {
[728] Fix | Delete
/**
[729] Fix | Delete
* Fires immediately after a duplicate comment is detected.
[730] Fix | Delete
*
[731] Fix | Delete
* @since 3.0.0
[732] Fix | Delete
*
[733] Fix | Delete
* @param array $commentdata Comment data.
[734] Fix | Delete
*/
[735] Fix | Delete
do_action( 'comment_duplicate_trigger', $commentdata );
[736] Fix | Delete
[737] Fix | Delete
/**
[738] Fix | Delete
* Filters duplicate comment error message.
[739] Fix | Delete
*
[740] Fix | Delete
* @since 5.2.0
[741] Fix | Delete
*
[742] Fix | Delete
* @param string $comment_duplicate_message Duplicate comment error message.
[743] Fix | Delete
*/
[744] Fix | Delete
$comment_duplicate_message = apply_filters( 'comment_duplicate_message', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) );
[745] Fix | Delete
[746] Fix | Delete
if ( $wp_error ) {
[747] Fix | Delete
return new WP_Error( 'comment_duplicate', $comment_duplicate_message, 409 );
[748] Fix | Delete
} else {
[749] Fix | Delete
if ( wp_doing_ajax() ) {
[750] Fix | Delete
die( $comment_duplicate_message );
[751] Fix | Delete
}
[752] Fix | Delete
[753] Fix | Delete
wp_die( $comment_duplicate_message, 409 );
[754] Fix | Delete
}
[755] Fix | Delete
}
[756] Fix | Delete
[757] Fix | Delete
/**
[758] Fix | Delete
* Fires immediately before a comment is marked approved.
[759] Fix | Delete
*
[760] Fix | Delete
* Allows checking for comment flooding.
[761] Fix | Delete
*
[762] Fix | Delete
* @since 2.3.0
[763] Fix | Delete
* @since 4.7.0 The `$avoid_die` parameter was added.
[764] Fix | Delete
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
[765] Fix | Delete
*
[766] Fix | Delete
* @param string $comment_author_ip Comment author's IP address.
[767] Fix | Delete
* @param string $comment_author_email Comment author's email.
[768] Fix | Delete
* @param string $comment_date_gmt GMT date the comment was posted.
[769] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error object instead of executing
[770] Fix | Delete
* wp_die() or die() if a comment flood is occurring.
[771] Fix | Delete
*/
[772] Fix | Delete
do_action(
[773] Fix | Delete
'check_comment_flood',
[774] Fix | Delete
$commentdata['comment_author_IP'],
[775] Fix | Delete
$commentdata['comment_author_email'],
[776] Fix | Delete
$commentdata['comment_date_gmt'],
[777] Fix | Delete
$wp_error
[778] Fix | Delete
);
[779] Fix | Delete
[780] Fix | Delete
/**
[781] Fix | Delete
* Filters whether a comment is part of a comment flood.
[782] Fix | Delete
*
[783] Fix | Delete
* The default check is wp_check_comment_flood(). See check_comment_flood_db().
[784] Fix | Delete
*
[785] Fix | Delete
* @since 4.7.0
[786] Fix | Delete
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
[787] Fix | Delete
*
[788] Fix | Delete
* @param bool $is_flood Is a comment flooding occurring? Default false.
[789] Fix | Delete
* @param string $comment_author_ip Comment author's IP address.
[790] Fix | Delete
* @param string $comment_author_email Comment author's email.
[791] Fix | Delete
* @param string $comment_date_gmt GMT date the comment was posted.
[792] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error object instead of executing
[793] Fix | Delete
* wp_die() or die() if a comment flood is occurring.
[794] Fix | Delete
*/
[795] Fix | Delete
$is_flood = apply_filters(
[796] Fix | Delete
'wp_is_comment_flood',
[797] Fix | Delete
false,
[798] Fix | Delete
$commentdata['comment_author_IP'],
[799] Fix | Delete
$commentdata['comment_author_email'],
[800] Fix | Delete
$commentdata['comment_date_gmt'],
[801] Fix | Delete
$wp_error
[802] Fix | Delete
);
[803] Fix | Delete
[804] Fix | Delete
if ( $is_flood ) {
[805] Fix | Delete
/** This filter is documented in wp-includes/comment-template.php */
[806] Fix | Delete
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) );
[807] Fix | Delete
[808] Fix | Delete
return new WP_Error( 'comment_flood', $comment_flood_message, 429 );
[809] Fix | Delete
}
[810] Fix | Delete
[811] Fix | Delete
return wp_check_comment_data( $commentdata );
[812] Fix | Delete
}
[813] Fix | Delete
[814] Fix | Delete
/**
[815] Fix | Delete
* Hooks WP's native database-based comment-flood check.
[816] Fix | Delete
*
[817] Fix | Delete
* This wrapper maintains backward compatibility with plugins that expect to
[818] Fix | Delete
* be able to unhook the legacy check_comment_flood_db() function from
[819] Fix | Delete
* 'check_comment_flood' using remove_action().
[820] Fix | Delete
*
[821] Fix | Delete
* @since 2.3.0
[822] Fix | Delete
* @since 4.7.0 Converted to be an add_filter() wrapper.
[823] Fix | Delete
*/
[824] Fix | Delete
function check_comment_flood_db() {
[825] Fix | Delete
add_filter( 'wp_is_comment_flood', 'wp_check_comment_flood', 10, 5 );
[826] Fix | Delete
}
[827] Fix | Delete
[828] Fix | Delete
/**
[829] Fix | Delete
* Checks whether comment flooding is occurring.
[830] Fix | Delete
*
[831] Fix | Delete
* Won't run, if current user can manage options, so to not block
[832] Fix | Delete
* administrators.
[833] Fix | Delete
*
[834] Fix | Delete
* @since 4.7.0
[835] Fix | Delete
*
[836] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[837] Fix | Delete
*
[838] Fix | Delete
* @param bool $is_flood Is a comment flooding occurring?
[839] Fix | Delete
* @param string $ip Comment author's IP address.
[840] Fix | Delete
* @param string $email Comment author's email address.
[841] Fix | Delete
* @param string $date MySQL time string.
[842] Fix | Delete
* @param bool $avoid_die When true, a disallowed comment will result in the function
[843] Fix | Delete
* returning without executing wp_die() or die(). Default false.
[844] Fix | Delete
* @return bool Whether comment flooding is occurring.
[845] Fix | Delete
*/
[846] Fix | Delete
function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false ) {
[847] Fix | Delete
global $wpdb;
[848] Fix | Delete
[849] Fix | Delete
// Another callback has declared a flood. Trust it.
[850] Fix | Delete
if ( true === $is_flood ) {
[851] Fix | Delete
return $is_flood;
[852] Fix | Delete
}
[853] Fix | Delete
[854] Fix | Delete
// Don't throttle admins or moderators.
[855] Fix | Delete
if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) {
[856] Fix | Delete
return false;
[857] Fix | Delete
}
[858] Fix | Delete
[859] Fix | Delete
$hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );
[860] Fix | Delete
[861] Fix | Delete
if ( is_user_logged_in() ) {
[862] Fix | Delete
$user = get_current_user_id();
[863] Fix | Delete
$check_column = '`user_id`';
[864] Fix | Delete
} else {
[865] Fix | Delete
$user = $ip;
[866] Fix | Delete
$check_column = '`comment_author_IP`';
[867] Fix | Delete
}
[868] Fix | Delete
[869] Fix | Delete
$sql = $wpdb->prepare(
[870] Fix | Delete
"SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1",
[871] Fix | Delete
$hour_ago,
[872] Fix | Delete
$user,
[873] Fix | Delete
$email
[874] Fix | Delete
);
[875] Fix | Delete
[876] Fix | Delete
$lasttime = $wpdb->get_var( $sql );
[877] Fix | Delete
[878] Fix | Delete
if ( $lasttime ) {
[879] Fix | Delete
$time_lastcomment = mysql2date( 'U', $lasttime, false );
[880] Fix | Delete
$time_newcomment = mysql2date( 'U', $date, false );
[881] Fix | Delete
[882] Fix | Delete
/**
[883] Fix | Delete
* Filters the comment flood status.
[884] Fix | Delete
*
[885] Fix | Delete
* @since 2.1.0
[886] Fix | Delete
*
[887] Fix | Delete
* @param bool $bool Whether a comment flood is occurring. Default false.
[888] Fix | Delete
* @param int $time_lastcomment Timestamp of when the last comment was posted.
[889] Fix | Delete
* @param int $time_newcomment Timestamp of when the new comment was posted.
[890] Fix | Delete
*/
[891] Fix | Delete
$flood_die = apply_filters( 'comment_flood_filter', false, $time_lastcomment, $time_newcomment );
[892] Fix | Delete
[893] Fix | Delete
if ( $flood_die ) {
[894] Fix | Delete
/**
[895] Fix | Delete
* Fires before the comment flood message is triggered.
[896] Fix | Delete
*
[897] Fix | Delete
* @since 1.5.0
[898] Fix | Delete
*
[899] Fix | Delete
* @param int $time_lastcomment Timestamp of when the last comment was posted.
[900] Fix | Delete
* @param int $time_newcomment Timestamp of when the new comment was posted.
[901] Fix | Delete
*/
[902] Fix | Delete
do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment );
[903] Fix | Delete
[904] Fix | Delete
if ( $avoid_die ) {
[905] Fix | Delete
return true;
[906] Fix | Delete
} else {
[907] Fix | Delete
/**
[908] Fix | Delete
* Filters the comment flood error message.
[909] Fix | Delete
*
[910] Fix | Delete
* @since 5.2.0
[911] Fix | Delete
*
[912] Fix | Delete
* @param string $comment_flood_message Comment flood error message.
[913] Fix | Delete
*/
[914] Fix | Delete
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) );
[915] Fix | Delete
[916] Fix | Delete
if ( wp_doing_ajax() ) {
[917] Fix | Delete
die( $comment_flood_message );
[918] Fix | Delete
}
[919] Fix | Delete
[920] Fix | Delete
wp_die( $comment_flood_message, 429 );
[921] Fix | Delete
}
[922] Fix | Delete
}
[923] Fix | Delete
}
[924] Fix | Delete
[925] Fix | Delete
return false;
[926] Fix | Delete
}
[927] Fix | Delete
[928] Fix | Delete
/**
[929] Fix | Delete
* Separates an array of comments into an array keyed by comment_type.
[930] Fix | Delete
*
[931] Fix | Delete
* @since 2.7.0
[932] Fix | Delete
*
[933] Fix | Delete
* @param WP_Comment[] $comments Array of comments.
[934] Fix | Delete
* @return array<string, WP_Comment[]> Array of comments keyed by comment type.
[935] Fix | Delete
*/
[936] Fix | Delete
function separate_comments( &$comments ) {
[937] Fix | Delete
$comments_by_type = array(
[938] Fix | Delete
'comment' => array(),
[939] Fix | Delete
'trackback' => array(),
[940] Fix | Delete
'pingback' => array(),
[941] Fix | Delete
'pings' => array(),
[942] Fix | Delete
);
[943] Fix | Delete
[944] Fix | Delete
$count = count( $comments );
[945] Fix | Delete
[946] Fix | Delete
for ( $i = 0; $i < $count; $i++ ) {
[947] Fix | Delete
$type = $comments[ $i ]->comment_type;
[948] Fix | Delete
[949] Fix | Delete
if ( empty( $type ) ) {
[950] Fix | Delete
$type = 'comment';
[951] Fix | Delete
}
[952] Fix | Delete
[953] Fix | Delete
$comments_by_type[ $type ][] = &$comments[ $i ];
[954] Fix | Delete
[955] Fix | Delete
if ( 'trackback' === $type || 'pingback' === $type ) {
[956] Fix | Delete
$comments_by_type['pings'][] = &$comments[ $i ];
[957] Fix | Delete
}
[958] Fix | Delete
}
[959] Fix | Delete
[960] Fix | Delete
return $comments_by_type;
[961] Fix | Delete
}
[962] Fix | Delete
[963] Fix | Delete
/**
[964] Fix | Delete
* Calculates the total number of comment pages.
[965] Fix | Delete
*
[966] Fix | Delete
* @since 2.7.0
[967] Fix | Delete
*
[968] Fix | Delete
* @uses Walker_Comment
[969] Fix | Delete
*
[970] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[971] Fix | Delete
*
[972] Fix | Delete
* @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Defaults to `$wp_query->comments`.
[973] Fix | Delete
* @param int $per_page Optional. Comments per page. Defaults to the value of `comments_per_page`
[974] Fix | Delete
* query var, option of the same name, or 1 (in that order).
[975] Fix | Delete
* @param bool $threaded Optional. Control over flat or threaded comments. Defaults to the value
[976] Fix | Delete
* of `thread_comments` option.
[977] Fix | Delete
* @return int Number of comment pages.
[978] Fix | Delete
*/
[979] Fix | Delete
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
[980] Fix | Delete
global $wp_query;
[981] Fix | Delete
[982] Fix | Delete
if ( null === $comments && null === $per_page && null === $threaded && ! empty( $wp_query->max_num_comment_pages ) ) {
[983] Fix | Delete
return $wp_query->max_num_comment_pages;
[984] Fix | Delete
}
[985] Fix | Delete
[986] Fix | Delete
if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) {
[987] Fix | Delete
$comments = $wp_query->comments;
[988] Fix | Delete
}
[989] Fix | Delete
[990] Fix | Delete
if ( empty( $comments ) ) {
[991] Fix | Delete
return 0;
[992] Fix | Delete
}
[993] Fix | Delete
[994] Fix | Delete
if ( ! get_option( 'page_comments' ) ) {
[995] Fix | Delete
return 1;
[996] Fix | Delete
}
[997] Fix | Delete
[998] Fix | Delete
if ( ! isset( $per_page ) ) {
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function