get_comment_link

过滤器::过滤返回的单个注释permalink。

apply_filters( ‘get_comment_link’, string $link , WP_Comment $comment , array $args , int $cpage )

说明(Description)

另见函数 get_page_of_comment()


参数(Parameters)

参数类型说明
$link(string)注释permalink附加了“#comment-$id”。
$comment(WP_Comment)当前注释对象。
$args(array)重写默认值的参数数组。
$cpage(int)计算出的“cpage”值。

源码(Source)

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param mixed $comment Comment to retrieve. Default current comment.
 * @param array $args    Optional. An array of arguments to override the defaults.
 * @return string The permalink to the given comment.
 */
function get_comment_link( $comment = null, $args = array() ) {
	global $wp_rewrite, $in_comment_loop;
	$comment = get_comment($comment);
	// Backwards compat
	if ( ! is_array( $args ) ) {
		$args = array( 'page' => $args );
	}
	$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 ) ) . $wp_rewrite->comments_pagination_base . '-' . $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 );
	}
	$link = $link . '#comment-' . $comment->comment_ID;
	/**
	 * Filter the returned single comment permalink.
	 *
	 * @since 2.8.0
	 *
	 * @see get_page_of_comment()
	 *
	 * @param string $link    The comment permalink with '#comment-$id' appended.
	 * @param object $comment The current comment object.
	 * @param array  $args    An array of arguments to override the defaults.
	 */
	return apply_filters( 'get_comment_link', $link, $comment, $args );
}
更新版本源码位置使用被使用
4.4.0wp-includes/comment-template.php:79510
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索