get_post_reply_link()
最后更新于:2021-11-26 22:36:19
get_post_reply_link( array$args=array(), int|GC_Post$post=null)Retrieves HTML content for reply to post link.
参数
- $args
-
(array) (Optional) Override default arguments.
-
‘add_below’
(string) The first part of the selector used to identify the comment to respond below. The resulting value is passed as the first parameter to addComment.moveForm(), concatenated as $add_below-$comment->comment_ID. Default is ‘post’. -
‘respond_id’
(string) The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(), and appended to the link URL as a hash value. Default ‘respond’. -
‘reply_text’
(string) Text of the Reply link. Default is ‘Leave a Comment’. -
‘login_text’
(string) Text of the link to reply if logged out. Default is ‘Log in to leave a Comment’. -
‘before’
(string) Text or HTML to add before the reply link. -
‘after’
(string) Text or HTML to add after the reply link.
Default value: array()
-
‘add_below’
- $post
-
(int|GC_Post) (Optional) Post ID or GC_Post object the comment is going to be displayed on. Default current post.
Default value: null
响应
(string|false|null) Link to show comment form, if successful. False, if comments are closed.
源文件
文件: gc-includes/comment-template.php
function get_post_reply_link( $args = array(), $post = null ) {
$defaults = array(
'add_below' => 'post',
'respond_id' => 'respond',
'reply_text' => __( 'Leave a Comment' ),
'login_text' => __( 'Log in to leave a Comment' ),
'before' => '',
'after' => '',
);
$args = gc_parse_args( $args, $defaults );
$post = get_post( $post );
if ( ! comments_open( $post->ID ) ) {
return false;
}
if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
$link = sprintf(
'<a rel="nofollow" class="comment-reply-login" href="https://docs.gechiui.com/functions/get_post_reply_link/%s">%s</a>',
gc_login_url( get_permalink() ),
$args['login_text']
);
} else {
$onclick = sprintf(
'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
$args['add_below'],
$post->ID,
$args['respond_id']
);
$link = sprintf(
"<a rel='nofollow' class='comment-reply-link' href='https://docs.gechiui.com/functions/get_post_reply_link/%s' onclick='%s'>%s</a>",
get_permalink( $post->ID ) . '#' . $args['respond_id'],
$onclick,
$args['reply_text']
);
}
$formatted_link = $args['before'] . $link . $args['after'];
/**
* Filters the formatted post comments link HTML.
*
* @since 2.7.0
*
* @param string $formatted The HTML-formatted post comments link.
* @param int|GC_Post $post The post ID or GC_Post object.
*/
return apply_filters( 'post_comments_link', $formatted_link, $post );
}