Add optional comment ID argument to comment template functions. Props filosofo. fixes #12006

git-svn-id: http://svn.automattic.com/wordpress/trunk@12821 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-01-25 17:34:13 +00:00
parent bc62f53df4
commit dd69637c65
1 changed files with 58 additions and 35 deletions

View File

@ -17,10 +17,11 @@
* @since 1.5.0
* @uses apply_filters() Calls 'get_comment_author' hook on the comment author
*
* @param int $comment_ID The ID of the comment for which to retrieve the author. Optional.
* @return string The comment author
*/
function get_comment_author() {
global $comment;
function get_comment_author( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( empty($comment->comment_author) ) {
if (!empty($comment->user_id)){
$user=get_userdata($comment->user_id);
@ -39,9 +40,11 @@ function get_comment_author() {
*
* @since 0.71
* @uses apply_filters() Calls 'comment_author' on comment author before displaying
*
* @param int $comment_ID The ID of the comment for which to print the author. Optional.
*/
function comment_author() {
$author = apply_filters('comment_author', get_comment_author() );
function comment_author( $comment_ID = 0 ) {
$author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
echo $author;
}
@ -52,10 +55,11 @@ function comment_author() {
* @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
* @uses $comment
*
* @param int $comment_ID The ID of the comment for which to get the author's email. Optional.
* @return string The current comment author's email
*/
function get_comment_author_email() {
global $comment;
function get_comment_author_email( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
return apply_filters('get_comment_author_email', $comment->comment_author_email);
}
@ -70,9 +74,11 @@ function get_comment_author_email() {
*
* @since 0.71
* @uses apply_filters() Calls 'author_email' hook on the author email
*
* @param int $comment_ID The ID of the comment for which to print the author's email. Optional.
*/
function comment_author_email() {
echo apply_filters('author_email', get_comment_author_email() );
function comment_author_email( $comment_ID = 0 ) {
echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
}
/**
@ -135,12 +141,13 @@ function get_comment_author_email_link($linktext='', $before='', $after='') {
* @since 1.5.0
* @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
*
* @param int $comment_ID The ID of the comment for which to get the author's link. Optional.
* @return string Comment Author name or HTML link for author's URL
*/
function get_comment_author_link() {
function get_comment_author_link( $comment_ID = 0 ) {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url = get_comment_author_url();
$author = get_comment_author();
$url = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );
if ( empty( $url ) || 'http://' == $url )
$return = $author;
@ -154,9 +161,11 @@ function get_comment_author_link() {
*
* @since 0.71
* @see get_comment_author_link() Echos result
*
* @param int The ID of the comment for which to print the author's link. Optional.
*/
function comment_author_link() {
echo get_comment_author_link();
function comment_author_link( $comment_ID = 0 ) {
echo get_comment_author_link( $comment_ID );
}
/**
@ -166,10 +175,11 @@ function comment_author_link() {
* @uses $comment
* @uses apply_filters()
*
* @return unknown
* @param int $comment_ID The ID of the comment for which to get the author's IP address. Optional.
* @return string The comment author's IP address.
*/
function get_comment_author_IP() {
global $comment;
function get_comment_author_IP( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
}
@ -178,9 +188,11 @@ function get_comment_author_IP() {
*
* @since 0.71
* @see get_comment_author_IP() Echos Result
*
* @param int $comment_ID The ID of the comment for which to print the author's IP address. Optional.
*/
function comment_author_IP() {
echo get_comment_author_IP();
function comment_author_IP( $comment_ID = 0 ) {
echo get_comment_author_IP( $comment_ID );
}
/**
@ -189,10 +201,11 @@ function comment_author_IP() {
* @since 1.5.0
* @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
*
* @param int $comment_ID The ID of the comment for which to get the author's URL. Optional.
* @return string
*/
function get_comment_author_url() {
global $comment;
function get_comment_author_url( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
$url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
$url = esc_url( $url, array('http', 'https') );
return apply_filters('get_comment_author_url', $url);
@ -204,9 +217,11 @@ function get_comment_author_url() {
* @since 0.71
* @uses apply_filters()
* @uses get_comment_author_url() Retrieves the comment author's URL
*
* @param int $comment_ID The ID of the comment for which to print the author's URL. Optional.
*/
function comment_author_url() {
echo apply_filters('comment_url', get_comment_author_url());
function comment_author_url( $comment_ID = 0 ) {
echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
}
/**
@ -351,10 +366,11 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
* @uses $comment
*
* @param string $d The format of the date (defaults to user's config)
* @param int $comment_ID The ID of the comment for which to get the date. Optional.
* @return string The comment's date
*/
function get_comment_date( $d = '' ) {
global $comment;
function get_comment_date( $d = '', $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( '' == $d )
$date = mysql2date(get_option('date_format'), $comment->comment_date);
else
@ -368,9 +384,10 @@ function get_comment_date( $d = '' ) {
* @since 0.71
*
* @param string $d The format of the date (defaults to user's config)
* @param int $comment_ID The ID of the comment for which to print the date. Optional.
*/
function comment_date( $d = '' ) {
echo get_comment_date( $d );
function comment_date( $d = '', $comment_ID = 0 ) {
echo get_comment_date( $d, $comment_ID );
}
/**
@ -384,10 +401,11 @@ function comment_date( $d = '' ) {
* @uses $comment
* @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
*
* @param int $comment_ID The ID of the comment for which to get the excerpt. Optional.
* @return string The maybe truncated comment with 20 words or less
*/
function get_comment_excerpt() {
global $comment;
function get_comment_excerpt( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
$comment_text = strip_tags($comment->comment_content);
$blah = explode(' ', $comment_text);
if (count($blah) > 20) {
@ -410,8 +428,10 @@ function get_comment_excerpt() {
*
* @since 1.2.0
* @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
*
* @param int $comment_ID The ID of the comment for which to print the excerpt. Optional.
*/
function comment_excerpt() {
function comment_excerpt( $comment_ID = 0 ) {
echo apply_filters('comment_excerpt', get_comment_excerpt() );
}
@ -575,10 +595,11 @@ function comments_number( $zero = false, $one = false, $more = false, $deprecate
* @since 1.5.0
* @uses $comment
*
* @param int $comment_ID The ID of the comment for which to get the text. Optional.
* @return string The comment content
*/
function get_comment_text() {
global $comment;
function get_comment_text( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
return apply_filters('get_comment_text', $comment->comment_content);
}
@ -588,8 +609,10 @@ function get_comment_text() {
* @since 0.71
* @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
* @uses get_comment_text() Gets the comment content
*
* @param int $comment_ID The ID of the comment for which to print the text. Optional.
*/
function comment_text() {
function comment_text( $comment_ID = 0 ) {
echo apply_filters('comment_text', get_comment_text() );
}
@ -633,11 +656,11 @@ function comment_time( $d = '' ) {
* @uses $comment
* @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
*
* @param int $comment_ID The ID of the comment for which to get the type. Optional.
* @return string The comment type
*/
function get_comment_type() {
global $comment;
function get_comment_type( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( '' == $comment->comment_type )
$comment->comment_type = 'comment';