wpseek.com
WordPress开发者和主题制作者的搜索引擎



comment_form_title › WordPress Function

Since2.7.0
已弃用n/a
comment_form_title ( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null )
参数: (4)
  • (string|false) $no_reply_text Optional. Text to display when not replying to a comment. Default false.
    Required: No
    默认: false
  • (string|false) $reply_text Optional. Text to display when replying to a comment. Default false. Accepts "%s" for the author of the comment being replied to.
    Required: No
    默认: false
  • (bool) $link_to_parent Optional. Boolean to control making the author's name a link to their comment. Default true.
    Required: No
    默认: true
  • (int|WP_Post|null) $post Optional. The post that the comment form is being displayed for. Defaults to the current global post.
    Required: No
    默认: null
定义在:
文档:
Change Log:
  • 6.2.0

Displays text based on comment reply status.

Only affects users with JavaScript disabled.


源码

function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
	global $comment;

	if ( false === $no_reply_text ) {
		$no_reply_text = __( 'Leave a Reply' );
	}

	if ( false === $reply_text ) {
		/* translators: %s: Author of the comment being replied to. */
		$reply_text = __( 'Leave a Reply to %s' );
	}

	$post = get_post( $post );
	if ( ! $post ) {
		echo $no_reply_text;
		return;
	}

	$reply_to_id = _get_comment_reply_id( $post->ID );

	if ( 0 === $reply_to_id ) {
		echo $no_reply_text;
		return;
	}

	// Sets the global so that template tags can be used in the comment form.
	$comment = get_comment( $reply_to_id );

	if ( $link_to_parent ) {
		$comment_author = sprintf(
			'<a href="#comment-%1$s">%2$s</a>',
			get_comment_ID(),
			get_comment_author( $reply_to_id )
		);
	} else {
		$comment_author = get_comment_author( $reply_to_id );
	}

	printf( $reply_text, $comment_author );
}