File "comment-template.php"
Full Path: /home/ycoalition/public_html/blog/wp-includes/blocks/comment-template.php
File size: 8 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/**
* Comment template functions
*
* These functions are meant to live inside of the WordPress loop.
*
* @package WordPress
* @subpackage Template
*/
/**
* Retrieves the author of the current comment.
*
* If the comment has an empty comment_author field, then 'Anonymous' person is
* assumed.
*
* @since 1.5.0
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
*
* @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to retrieve the author.
* Default current comment.
* @return string The comment author
*/
function get_comment_author( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
if ( ! empty( $comment->comment_ID ) ) {
$comment_id = $comment->comment_ID;
} elseif ( is_scalar( $comment_id ) ) {
$comment_id = (string) $comment_id;
} else {
$comment_id = '0';
}
if ( empty( $comment->comment_author ) ) {
$user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
if ( $user ) {
$comment_author = $user->display_name;
} else {
$comment_author = __( 'Anonymous' );
}
} else {
$comment_author = $comment->comment_author;
}
/**
* Filters the returned comment author name.
*
* @since 1.5.0
* @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
*
* @param string $comment_author The comment author's username.
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The comment object.
*/
return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
}
/**
* Displays the author of the current comment.
*
* @since 0.71
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
*
* @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author.
* Default current comment.
*/
function comment_author( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
$comment_author = get_comment_author( $comment );
/**
* Filters the comment author's name for display.
*
* @since 1.2.0
* @since 4.1.0 The `$comment_id` parameter was added.
*
* @param string $comment_author The comment author's username.
* @param string $comment_id The comment ID as a numeric string.
*/
echo apply_filters( 'comment_author', $comment_author, $comment->comment_ID );
}
/**
* Retrieves the email of the author of the current comment.
*
* @since 1.5.0
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
*
* @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's email.
* Default current comment.
* @return string The current comment author's email
*/
function get_comment_author_email( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
/**
* Filters the comment author's returned email address.
*
* @since 1.5.0
* @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
*
* @param string $comment_author_email The comment author's email address.
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The comment object.
*/
return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
}
/**
* Displays the email of the author of the current global $comment.
*
* Care should be taken to protect the email address and assure that email
* harvesters do not capture your commenter's email address. Most assume that
* their email address will not appear in raw form on the site. Doing so will
* enable anyone, including those that people don't want to get the email
* address and use it for their own means good and bad.
*
* @since 0.71
* @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
*
* @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author's email.
* Default current comment.
*/
function comment_author_email( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
$comment_author_email = get_comment_author_email( $comment );
/**
* Filters the comment author's email for display.
*
* @since 1.2.0
* @since 4.1.0 The `$comment_id` parameter was added.
*
* @param string $comment_author_email The comment author's email address.
* @param string $comment_id The comment ID as a numeric string.
*/
echo apply_filters( 'author_email', $comment_author_email, $comment->comment_ID );
}
/**
* Displays the HTML email link to the author of the current comment.
*
* Care should be taken to protect the email address and assure that email
* harvesters do not capture your commenter's email address. Most assume that
* their email address will not appear in raw form on the site. Doing so will
* enable anyone, including those that people don't want to get the email
* address and use it for their own means good and bad.
*
* @since 0.71
* @since 4.6.0 Added the `$comment` parameter.
*
* @param string $link_text Optional. Text to display instead of the comment author's email address.
* Default empty.
* @param string $before Optional. Text or HTML to display before the email link. Default empty.
* @param string $after Optional. Text or HTML to display after the email link. Default empty.
* @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment.
*/
function comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
$link = get_comment_author_email_link( $link_text, $before, $after, $comment );
if ( $link ) {
echo $link;
}
}
/**
* Returns the HTML email link to the author of the current comment.
*
* Care should be taken to protect the email address and assure that email
* harvesters do not capture your commenter's email address. Most assume that
* their email address will not appear in raw form on the site. Doing so will
* enable anyone, including those that people don't want to get the email
* address and use it for their own means good and bad.
*
* @since 2.7.0
* @since 4.6.0 Added the `$comment` parameter.
*
* @param string $link_text Optional. Text to display instead of the comment author's email address.
* Default empty.
* @param string $before Optional. Text or HTML to display before the email link. Default empty.
* @param string $after Optional. Text or HTML to display after the email link. Default empty.
* @param int|WP_Comment $comment Optional. Comment ID or WP_Comment object. Default is the current comment.
* @return string HTML markup for the comment author email link. By default, the email address is obfuscated
* via the {@see 'comment_email'} filter with antispambot().
*/
function get_comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
$comment = get_comment( $comment );
/**
* Filters the comment author's email for display.
*
* Care should be taken to protect the email address and assure that email
* harvesters do not capture your commenter's email address.
*
* @since 1.2.0
* @since 4.1.0 The `$comment` parameter was added.
*
* @param string $comment_author_email The comment author's email address.
* @param WP_Comment $comment The comment object.
*/
$comment_author_email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
if ( ( ! empty( $comment_author_email ) ) && ( '@' !== $comment_author_email ) ) {
$display = ( '' !== $link_text ) ? $link_text : $comment_author_email;
$comment_author_email_link = $before . sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( 'mailto:' . $comment_author_email ),
esc_html( $display )
) . $after;