Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: comment-template.php
}
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
/**
[503] Fix | Delete
* Returns the classes for the comment div as an array.
[504] Fix | Delete
*
[505] Fix | Delete
* @since 2.7.0
[506] Fix | Delete
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
[507] Fix | Delete
*
[508] Fix | Delete
* @global int $comment_alt
[509] Fix | Delete
* @global int $comment_depth
[510] Fix | Delete
* @global int $comment_thread_alt
[511] Fix | Delete
*
[512] Fix | Delete
* @param string|string[] $css_class Optional. One or more classes to add to the class list.
[513] Fix | Delete
* Default empty.
[514] Fix | Delete
* @param int|WP_Comment $comment_id Optional. Comment ID or WP_Comment object. Default current comment.
[515] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
[516] Fix | Delete
* @return string[] An array of classes.
[517] Fix | Delete
*/
[518] Fix | Delete
function get_comment_class( $css_class = '', $comment_id = null, $post = null ) {
[519] Fix | Delete
global $comment_alt, $comment_depth, $comment_thread_alt;
[520] Fix | Delete
[521] Fix | Delete
$classes = array();
[522] Fix | Delete
[523] Fix | Delete
$comment = get_comment( $comment_id );
[524] Fix | Delete
if ( ! $comment ) {
[525] Fix | Delete
return $classes;
[526] Fix | Delete
}
[527] Fix | Delete
[528] Fix | Delete
// Get the comment type (comment, trackback).
[529] Fix | Delete
$classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
[530] Fix | Delete
[531] Fix | Delete
// Add classes for comment authors that are registered users.
[532] Fix | Delete
$user = $comment->user_id ? get_userdata( $comment->user_id ) : false;
[533] Fix | Delete
if ( $user ) {
[534] Fix | Delete
$classes[] = 'byuser';
[535] Fix | Delete
$classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
[536] Fix | Delete
// For comment authors who are the author of the post.
[537] Fix | Delete
$_post = get_post( $post );
[538] Fix | Delete
if ( $_post ) {
[539] Fix | Delete
if ( $comment->user_id === $_post->post_author ) {
[540] Fix | Delete
$classes[] = 'bypostauthor';
[541] Fix | Delete
}
[542] Fix | Delete
}
[543] Fix | Delete
}
[544] Fix | Delete
[545] Fix | Delete
if ( empty( $comment_alt ) ) {
[546] Fix | Delete
$comment_alt = 0;
[547] Fix | Delete
}
[548] Fix | Delete
if ( empty( $comment_depth ) ) {
[549] Fix | Delete
$comment_depth = 1;
[550] Fix | Delete
}
[551] Fix | Delete
if ( empty( $comment_thread_alt ) ) {
[552] Fix | Delete
$comment_thread_alt = 0;
[553] Fix | Delete
}
[554] Fix | Delete
[555] Fix | Delete
if ( $comment_alt % 2 ) {
[556] Fix | Delete
$classes[] = 'odd';
[557] Fix | Delete
$classes[] = 'alt';
[558] Fix | Delete
} else {
[559] Fix | Delete
$classes[] = 'even';
[560] Fix | Delete
}
[561] Fix | Delete
[562] Fix | Delete
++$comment_alt;
[563] Fix | Delete
[564] Fix | Delete
// Alt for top-level comments.
[565] Fix | Delete
if ( 1 === $comment_depth ) {
[566] Fix | Delete
if ( $comment_thread_alt % 2 ) {
[567] Fix | Delete
$classes[] = 'thread-odd';
[568] Fix | Delete
$classes[] = 'thread-alt';
[569] Fix | Delete
} else {
[570] Fix | Delete
$classes[] = 'thread-even';
[571] Fix | Delete
}
[572] Fix | Delete
++$comment_thread_alt;
[573] Fix | Delete
}
[574] Fix | Delete
[575] Fix | Delete
$classes[] = "depth-$comment_depth";
[576] Fix | Delete
[577] Fix | Delete
if ( ! empty( $css_class ) ) {
[578] Fix | Delete
if ( ! is_array( $css_class ) ) {
[579] Fix | Delete
$css_class = preg_split( '#\s+#', $css_class );
[580] Fix | Delete
}
[581] Fix | Delete
$classes = array_merge( $classes, $css_class );
[582] Fix | Delete
}
[583] Fix | Delete
[584] Fix | Delete
$classes = array_map( 'esc_attr', $classes );
[585] Fix | Delete
[586] Fix | Delete
/**
[587] Fix | Delete
* Filters the returned CSS classes for the current comment.
[588] Fix | Delete
*
[589] Fix | Delete
* @since 2.7.0
[590] Fix | Delete
*
[591] Fix | Delete
* @param string[] $classes An array of comment classes.
[592] Fix | Delete
* @param string[] $css_class An array of additional classes added to the list.
[593] Fix | Delete
* @param string $comment_id The comment ID as a numeric string.
[594] Fix | Delete
* @param WP_Comment $comment The comment object.
[595] Fix | Delete
* @param int|WP_Post $post The post ID or WP_Post object.
[596] Fix | Delete
*/
[597] Fix | Delete
return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post );
[598] Fix | Delete
}
[599] Fix | Delete
[600] Fix | Delete
/**
[601] Fix | Delete
* Retrieves the comment date of the current comment.
[602] Fix | Delete
*
[603] Fix | Delete
* @since 1.5.0
[604] Fix | Delete
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
[605] Fix | Delete
*
[606] Fix | Delete
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
[607] Fix | Delete
* @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the date.
[608] Fix | Delete
* Default current comment.
[609] Fix | Delete
* @return string The comment's date.
[610] Fix | Delete
*/
[611] Fix | Delete
function get_comment_date( $format = '', $comment_id = 0 ) {
[612] Fix | Delete
$comment = get_comment( $comment_id );
[613] Fix | Delete
[614] Fix | Delete
$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
[615] Fix | Delete
[616] Fix | Delete
$comment_date = mysql2date( $_format, $comment->comment_date );
[617] Fix | Delete
[618] Fix | Delete
/**
[619] Fix | Delete
* Filters the returned comment date.
[620] Fix | Delete
*
[621] Fix | Delete
* @since 1.5.0
[622] Fix | Delete
*
[623] Fix | Delete
* @param string|int $comment_date Formatted date string or Unix timestamp.
[624] Fix | Delete
* @param string $format PHP date format.
[625] Fix | Delete
* @param WP_Comment $comment The comment object.
[626] Fix | Delete
*/
[627] Fix | Delete
return apply_filters( 'get_comment_date', $comment_date, $format, $comment );
[628] Fix | Delete
}
[629] Fix | Delete
[630] Fix | Delete
/**
[631] Fix | Delete
* Displays the comment date of the current comment.
[632] Fix | Delete
*
[633] Fix | Delete
* @since 0.71
[634] Fix | Delete
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
[635] Fix | Delete
*
[636] Fix | Delete
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
[637] Fix | Delete
* @param int|WP_Comment $comment_id WP_Comment or ID of the comment for which to print the date.
[638] Fix | Delete
* Default current comment.
[639] Fix | Delete
*/
[640] Fix | Delete
function comment_date( $format = '', $comment_id = 0 ) {
[641] Fix | Delete
echo get_comment_date( $format, $comment_id );
[642] Fix | Delete
}
[643] Fix | Delete
[644] Fix | Delete
/**
[645] Fix | Delete
* Retrieves the excerpt of the given comment.
[646] Fix | Delete
*
[647] Fix | Delete
* Returns a maximum of 20 words with an ellipsis appended if necessary.
[648] Fix | Delete
*
[649] Fix | Delete
* @since 1.5.0
[650] Fix | Delete
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
[651] Fix | Delete
*
[652] Fix | Delete
* @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the excerpt.
[653] Fix | Delete
* Default current comment.
[654] Fix | Delete
* @return string The possibly truncated comment excerpt.
[655] Fix | Delete
*/
[656] Fix | Delete
function get_comment_excerpt( $comment_id = 0 ) {
[657] Fix | Delete
$comment = get_comment( $comment_id );
[658] Fix | Delete
[659] Fix | Delete
if ( ! post_password_required( $comment->comment_post_ID ) ) {
[660] Fix | Delete
$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
[661] Fix | Delete
} else {
[662] Fix | Delete
$comment_text = __( 'Password protected' );
[663] Fix | Delete
}
[664] Fix | Delete
[665] Fix | Delete
/* translators: Maximum number of words used in a comment excerpt. */
[666] Fix | Delete
$comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );
[667] Fix | Delete
[668] Fix | Delete
/**
[669] Fix | Delete
* Filters the maximum number of words used in the comment excerpt.
[670] Fix | Delete
*
[671] Fix | Delete
* @since 4.4.0
[672] Fix | Delete
*
[673] Fix | Delete
* @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
[674] Fix | Delete
*/
[675] Fix | Delete
$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
[676] Fix | Delete
[677] Fix | Delete
$comment_excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );
[678] Fix | Delete
[679] Fix | Delete
/**
[680] Fix | Delete
* Filters the retrieved comment excerpt.
[681] Fix | Delete
*
[682] Fix | Delete
* @since 1.5.0
[683] Fix | Delete
* @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
[684] Fix | Delete
*
[685] Fix | Delete
* @param string $comment_excerpt The comment excerpt text.
[686] Fix | Delete
* @param string $comment_id The comment ID as a numeric string.
[687] Fix | Delete
* @param WP_Comment $comment The comment object.
[688] Fix | Delete
*/
[689] Fix | Delete
return apply_filters( 'get_comment_excerpt', $comment_excerpt, $comment->comment_ID, $comment );
[690] Fix | Delete
}
[691] Fix | Delete
[692] Fix | Delete
/**
[693] Fix | Delete
* Displays the excerpt of the current comment.
[694] Fix | Delete
*
[695] Fix | Delete
* @since 1.2.0
[696] Fix | Delete
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
[697] Fix | Delete
*
[698] Fix | Delete
* @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to print the excerpt.
[699] Fix | Delete
* Default current comment.
[700] Fix | Delete
*/
[701] Fix | Delete
function comment_excerpt( $comment_id = 0 ) {
[702] Fix | Delete
$comment = get_comment( $comment_id );
[703] Fix | Delete
[704] Fix | Delete
$comment_excerpt = get_comment_excerpt( $comment );
[705] Fix | Delete
[706] Fix | Delete
/**
[707] Fix | Delete
* Filters the comment excerpt for display.
[708] Fix | Delete
*
[709] Fix | Delete
* @since 1.2.0
[710] Fix | Delete
* @since 4.1.0 The `$comment_id` parameter was added.
[711] Fix | Delete
*
[712] Fix | Delete
* @param string $comment_excerpt The comment excerpt text.
[713] Fix | Delete
* @param string $comment_id The comment ID as a numeric string.
[714] Fix | Delete
*/
[715] Fix | Delete
echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
[716] Fix | Delete
}
[717] Fix | Delete
[718] Fix | Delete
/**
[719] Fix | Delete
* Retrieves the comment ID of the current comment.
[720] Fix | Delete
*
[721] Fix | Delete
* @since 1.5.0
[722] Fix | Delete
*
[723] Fix | Delete
* @return string The comment ID as a numeric string.
[724] Fix | Delete
*/
[725] Fix | Delete
function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
[726] Fix | Delete
$comment = get_comment();
[727] Fix | Delete
[728] Fix | Delete
$comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
[729] Fix | Delete
[730] Fix | Delete
/**
[731] Fix | Delete
* Filters the returned comment ID.
[732] Fix | Delete
*
[733] Fix | Delete
* @since 1.5.0
[734] Fix | Delete
* @since 4.1.0 The `$comment` parameter was added.
[735] Fix | Delete
*
[736] Fix | Delete
* @param string $comment_id The current comment ID as a numeric string.
[737] Fix | Delete
* @param WP_Comment $comment The comment object.
[738] Fix | Delete
*/
[739] Fix | Delete
return apply_filters( 'get_comment_ID', $comment_id, $comment ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
[740] Fix | Delete
}
[741] Fix | Delete
[742] Fix | Delete
/**
[743] Fix | Delete
* Displays the comment ID of the current comment.
[744] Fix | Delete
*
[745] Fix | Delete
* @since 0.71
[746] Fix | Delete
*/
[747] Fix | Delete
function comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
[748] Fix | Delete
echo get_comment_ID();
[749] Fix | Delete
}
[750] Fix | Delete
[751] Fix | Delete
/**
[752] Fix | Delete
* Retrieves the link to a given comment.
[753] Fix | Delete
*
[754] Fix | Delete
* @since 1.5.0
[755] Fix | Delete
* @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
[756] Fix | Delete
*
[757] Fix | Delete
* @see get_page_of_comment()
[758] Fix | Delete
*
[759] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[760] Fix | Delete
* @global bool $in_comment_loop
[761] Fix | Delete
*
[762] Fix | Delete
* @param WP_Comment|int|null $comment Optional. Comment to retrieve. Default current comment.
[763] Fix | Delete
* @param array $args {
[764] Fix | Delete
* An array of optional arguments to override the defaults.
[765] Fix | Delete
*
[766] Fix | Delete
* @type string $type Passed to get_page_of_comment().
[767] Fix | Delete
* @type int $page Current page of comments, for calculating comment pagination.
[768] Fix | Delete
* @type int $per_page Per-page value for comment pagination.
[769] Fix | Delete
* @type int $max_depth Passed to get_page_of_comment().
[770] Fix | Delete
* @type int|string $cpage Value to use for the comment's "comment-page" or "cpage" value.
[771] Fix | Delete
* If provided, this value overrides any value calculated from `$page`
[772] Fix | Delete
* and `$per_page`.
[773] Fix | Delete
* }
[774] Fix | Delete
* @return string The permalink to the given comment.
[775] Fix | Delete
*/
[776] Fix | Delete
function get_comment_link( $comment = null, $args = array() ) {
[777] Fix | Delete
global $wp_rewrite, $in_comment_loop;
[778] Fix | Delete
[779] Fix | Delete
$comment = get_comment( $comment );
[780] Fix | Delete
[781] Fix | Delete
// Back-compat.
[782] Fix | Delete
if ( ! is_array( $args ) ) {
[783] Fix | Delete
$args = array( 'page' => $args );
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
$defaults = array(
[787] Fix | Delete
'type' => 'all',
[788] Fix | Delete
'page' => '',
[789] Fix | Delete
'per_page' => '',
[790] Fix | Delete
'max_depth' => '',
[791] Fix | Delete
'cpage' => null,
[792] Fix | Delete
);
[793] Fix | Delete
[794] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[795] Fix | Delete
[796] Fix | Delete
$comment_link = get_permalink( $comment->comment_post_ID );
[797] Fix | Delete
[798] Fix | Delete
// The 'cpage' param takes precedence.
[799] Fix | Delete
if ( ! is_null( $args['cpage'] ) ) {
[800] Fix | Delete
$cpage = $args['cpage'];
[801] Fix | Delete
[802] Fix | Delete
// No 'cpage' is provided, so we calculate one.
[803] Fix | Delete
} else {
[804] Fix | Delete
if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
[805] Fix | Delete
$args['per_page'] = get_option( 'comments_per_page' );
[806] Fix | Delete
}
[807] Fix | Delete
[808] Fix | Delete
if ( empty( $args['per_page'] ) ) {
[809] Fix | Delete
$args['per_page'] = 0;
[810] Fix | Delete
$args['page'] = 0;
[811] Fix | Delete
}
[812] Fix | Delete
[813] Fix | Delete
$cpage = $args['page'];
[814] Fix | Delete
[815] Fix | Delete
if ( '' === $cpage ) {
[816] Fix | Delete
if ( ! empty( $in_comment_loop ) ) {
[817] Fix | Delete
$cpage = (int) get_query_var( 'cpage' );
[818] Fix | Delete
} else {
[819] Fix | Delete
// Requires a database hit, so we only do it when we can't figure out from context.
[820] Fix | Delete
$cpage = get_page_of_comment( $comment->comment_ID, $args );
[821] Fix | Delete
}
[822] Fix | Delete
}
[823] Fix | Delete
[824] Fix | Delete
/*
[825] Fix | Delete
* If the default page displays the oldest comments, the permalinks for comments on the default page
[826] Fix | Delete
* do not need a 'cpage' query var.
[827] Fix | Delete
*/
[828] Fix | Delete
if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) {
[829] Fix | Delete
$cpage = '';
[830] Fix | Delete
}
[831] Fix | Delete
}
[832] Fix | Delete
[833] Fix | Delete
if ( $cpage && get_option( 'page_comments' ) ) {
[834] Fix | Delete
if ( $wp_rewrite->using_permalinks() ) {
[835] Fix | Delete
if ( $cpage ) {
[836] Fix | Delete
$comment_link = trailingslashit( $comment_link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
[837] Fix | Delete
}
[838] Fix | Delete
[839] Fix | Delete
$comment_link = user_trailingslashit( $comment_link, 'comment' );
[840] Fix | Delete
} elseif ( $cpage ) {
[841] Fix | Delete
$comment_link = add_query_arg( 'cpage', $cpage, $comment_link );
[842] Fix | Delete
}
[843] Fix | Delete
}
[844] Fix | Delete
[845] Fix | Delete
if ( $wp_rewrite->using_permalinks() ) {
[846] Fix | Delete
$comment_link = user_trailingslashit( $comment_link, 'comment' );
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
$comment_link = $comment_link . '#comment-' . $comment->comment_ID;
[850] Fix | Delete
[851] Fix | Delete
/**
[852] Fix | Delete
* Filters the returned single comment permalink.
[853] Fix | Delete
*
[854] Fix | Delete
* @since 2.8.0
[855] Fix | Delete
* @since 4.4.0 Added the `$cpage` parameter.
[856] Fix | Delete
*
[857] Fix | Delete
* @see get_page_of_comment()
[858] Fix | Delete
*
[859] Fix | Delete
* @param string $comment_link The comment permalink with '#comment-$id' appended.
[860] Fix | Delete
* @param WP_Comment $comment The current comment object.
[861] Fix | Delete
* @param array $args An array of arguments to override the defaults.
[862] Fix | Delete
* @param int $cpage The calculated 'cpage' value.
[863] Fix | Delete
*/
[864] Fix | Delete
return apply_filters( 'get_comment_link', $comment_link, $comment, $args, $cpage );
[865] Fix | Delete
}
[866] Fix | Delete
[867] Fix | Delete
/**
[868] Fix | Delete
* Retrieves the link to the current post comments.
[869] Fix | Delete
*
[870] Fix | Delete
* @since 1.5.0
[871] Fix | Delete
*
[872] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
[873] Fix | Delete
* @return string The link to the comments.
[874] Fix | Delete
*/
[875] Fix | Delete
function get_comments_link( $post = 0 ) {
[876] Fix | Delete
$hash = get_comments_number( $post ) ? '#comments' : '#respond';
[877] Fix | Delete
$comments_link = get_permalink( $post ) . $hash;
[878] Fix | Delete
[879] Fix | Delete
/**
[880] Fix | Delete
* Filters the returned post comments permalink.
[881] Fix | Delete
*
[882] Fix | Delete
* @since 3.6.0
[883] Fix | Delete
*
[884] Fix | Delete
* @param string $comments_link Post comments permalink with '#comments' appended.
[885] Fix | Delete
* @param int|WP_Post $post Post ID or WP_Post object.
[886] Fix | Delete
*/
[887] Fix | Delete
return apply_filters( 'get_comments_link', $comments_link, $post );
[888] Fix | Delete
}
[889] Fix | Delete
[890] Fix | Delete
/**
[891] Fix | Delete
* Displays the link to the current post comments.
[892] Fix | Delete
*
[893] Fix | Delete
* @since 0.71
[894] Fix | Delete
*
[895] Fix | Delete
* @param string $deprecated Not Used.
[896] Fix | Delete
* @param string $deprecated_2 Not Used.
[897] Fix | Delete
*/
[898] Fix | Delete
function comments_link( $deprecated = '', $deprecated_2 = '' ) {
[899] Fix | Delete
if ( ! empty( $deprecated ) ) {
[900] Fix | Delete
_deprecated_argument( __FUNCTION__, '0.72' );
[901] Fix | Delete
}
[902] Fix | Delete
if ( ! empty( $deprecated_2 ) ) {
[903] Fix | Delete
_deprecated_argument( __FUNCTION__, '1.3.0' );
[904] Fix | Delete
}
[905] Fix | Delete
echo esc_url( get_comments_link() );
[906] Fix | Delete
}
[907] Fix | Delete
[908] Fix | Delete
/**
[909] Fix | Delete
* Retrieves the amount of comments a post has.
[910] Fix | Delete
*
[911] Fix | Delete
* @since 1.5.0
[912] Fix | Delete
*
[913] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
[914] Fix | Delete
* @return string|int If the post exists, a numeric string representing the number of comments
[915] Fix | Delete
* the post has, otherwise 0.
[916] Fix | Delete
*/
[917] Fix | Delete
function get_comments_number( $post = 0 ) {
[918] Fix | Delete
$post = get_post( $post );
[919] Fix | Delete
[920] Fix | Delete
$comments_number = $post ? $post->comment_count : 0;
[921] Fix | Delete
$post_id = $post ? $post->ID : 0;
[922] Fix | Delete
[923] Fix | Delete
/**
[924] Fix | Delete
* Filters the returned comment count for a post.
[925] Fix | Delete
*
[926] Fix | Delete
* @since 1.5.0
[927] Fix | Delete
*
[928] Fix | Delete
* @param string|int $comments_number A string representing the number of comments a post has, otherwise 0.
[929] Fix | Delete
* @param int $post_id Post ID.
[930] Fix | Delete
*/
[931] Fix | Delete
return apply_filters( 'get_comments_number', $comments_number, $post_id );
[932] Fix | Delete
}
[933] Fix | Delete
[934] Fix | Delete
/**
[935] Fix | Delete
* Displays the language string for the number of comments the current post has.
[936] Fix | Delete
*
[937] Fix | Delete
* @since 0.71
[938] Fix | Delete
* @since 5.4.0 The `$deprecated` parameter was changed to `$post`.
[939] Fix | Delete
*
[940] Fix | Delete
* @param string|false $zero Optional. Text for no comments. Default false.
[941] Fix | Delete
* @param string|false $one Optional. Text for one comment. Default false.
[942] Fix | Delete
* @param string|false $more Optional. Text for more than one comment. Default false.
[943] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
[944] Fix | Delete
*/
[945] Fix | Delete
function comments_number( $zero = false, $one = false, $more = false, $post = 0 ) {
[946] Fix | Delete
echo get_comments_number_text( $zero, $one, $more, $post );
[947] Fix | Delete
}
[948] Fix | Delete
[949] Fix | Delete
/**
[950] Fix | Delete
* Displays the language string for the number of comments the current post has.
[951] Fix | Delete
*
[952] Fix | Delete
* @since 4.0.0
[953] Fix | Delete
* @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
[954] Fix | Delete
*
[955] Fix | Delete
* @param string $zero Optional. Text for no comments. Default false.
[956] Fix | Delete
* @param string $one Optional. Text for one comment. Default false.
[957] Fix | Delete
* @param string $more Optional. Text for more than one comment. Default false.
[958] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
[959] Fix | Delete
* @return string Language string for the number of comments a post has.
[960] Fix | Delete
*/
[961] Fix | Delete
function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) {
[962] Fix | Delete
$comments_number = (int) get_comments_number( $post );
[963] Fix | Delete
[964] Fix | Delete
if ( $comments_number > 1 ) {
[965] Fix | Delete
if ( false === $more ) {
[966] Fix | Delete
$comments_number_text = sprintf(
[967] Fix | Delete
/* translators: %s: Number of comments. */
[968] Fix | Delete
_n( '%s Comment', '%s Comments', $comments_number ),
[969] Fix | Delete
number_format_i18n( $comments_number )
[970] Fix | Delete
);
[971] Fix | Delete
} else {
[972] Fix | Delete
// % Comments
[973] Fix | Delete
/*
[974] Fix | Delete
* translators: If comment number in your language requires declension,
[975] Fix | Delete
* translate this to 'on'. Do not translate into your own language.
[976] Fix | Delete
*/
[977] Fix | Delete
if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
[978] Fix | Delete
$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
[979] Fix | Delete
$text = preg_replace( '/&.+?;/', '', $text ); // Remove HTML entities.
[980] Fix | Delete
$text = trim( strip_tags( $text ), '% ' );
[981] Fix | Delete
[982] Fix | Delete
// Replace '% Comments' with a proper plural form.
[983] Fix | Delete
if ( $text && ! preg_match( '/[0-9]+/', $text ) && str_contains( $more, '%' ) ) {
[984] Fix | Delete
/* translators: %s: Number of comments. */
[985] Fix | Delete
$new_text = _n( '%s Comment', '%s Comments', $comments_number );
[986] Fix | Delete
$new_text = trim( sprintf( $new_text, '' ) );
[987] Fix | Delete
[988] Fix | Delete
$more = str_replace( $text, $new_text, $more );
[989] Fix | Delete
if ( ! str_contains( $more, '%' ) ) {
[990] Fix | Delete
$more = '% ' . $more;
[991] Fix | Delete
}
[992] Fix | Delete
}
[993] Fix | Delete
}
[994] Fix | Delete
[995] Fix | Delete
$comments_number_text = str_replace( '%', number_format_i18n( $comments_number ), $more );
[996] Fix | Delete
}
[997] Fix | Delete
} elseif ( 0 === $comments_number ) {
[998] Fix | Delete
$comments_number_text = ( false === $zero ) ? __( 'No Comments' ) : $zero;
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function