Advertisements

get_comment_link

Definition:
function get_comment_link( $comment = null, $args = array() {}

Retrieve the link to a given comment.

Parameters

  • object|string|int $comment: Comment to retrieve.
  • array $args: Optional args.

Return values

returns:The permalink to the given comment.

Defined filters

  • get_comment_link
    apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args )

Source code

function get_comment_link( $comment = null, $args = array() ) {

	global $wp_rewrite, $in_comment_loop;



	$comment = get_comment($comment);



	// Backwards compat

	if ( !is_array($args) ) {

		$page = $args;

		$args = array();

		$args['page'] = $page;

	}



	$defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );

	$args = wp_parse_args( $args, $defaults );



	if ( '' === $args['per_page'] && get_option('page_comments') )

		$args['per_page'] = get_option('comments_per_page');



	if ( empty($args['per_page']) ) {

		$args['per_page'] = 0;

		$args['page'] = 0;

	}



	if ( $args['per_page'] ) {

		if ( '' == $args['page'] )

			$args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );



		if ( $wp_rewrite->using_permalinks() )

			$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );

		else

			$link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );

	} else {

		$link = get_permalink( $comment->comment_post_ID );

	}



	return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args );

}

1320

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: