wppaste
WordPress

get_comment_reply_link( array $args = array(), int|WP_Comment $comment = null, int|WP_Post $post = null ): string|false|null

Since
2.7.0, 4.4.0
Source
wp-includes/comment-template.php:1755
Retrieves HTML content for reply to comment link.

Compatibility

WordPress
since 4.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarrayoptional
Override default arguments.Default: array()
  • $add_belowstringdefault: 'comment'

    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.
  • $respond_idstringdefault: 'respond'

    The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(), and appended to the link URL as a hash value.
  • $reply_textstringdefault: 'Reply'

    The visible text of the Reply link.
  • $reply_to_textstringdefault: 'Reply to %s'. Should start with the visible reply_text value

    The accessible name of the Reply link, using %s as a placeholder for the comment author's name.
  • $show_reply_to_textbooldefault: false

    Whether to use reply_to_text as visible link text.
  • $login_textstringdefault: 'Log in to Reply'

    The text of the link to reply if logged out.
  • $max_depthintdefault: 0

    The max depth of the comment tree.
  • $depthintdefault: 0

    The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth' option set in Settings > Discussion.
  • $beforestringdefault: empty

    The text or HTML to add before the reply link.
  • $afterstringdefault: empty

    The text or HTML to add after the reply link.
$commentint|WP_Commentoptional
Comment being replied to. Default current comment.Default: null
$postint|WP_Postoptional
Post ID or WP_Post object the comment is going to be displayed on.
Default current post.Default: null

Return value

string|false|null
Link to show comment form on success. False if comments are closed. Null on failure.

Performance profile

How much work a call to get_comment_reply_link() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
41–183

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 222.

Plugin surface
2 hooks

Third-party callbacks on 'comment_reply_link_args', 'comment_reply_link' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below get_comment_reply_link()
  • serializeserialisationmaybe_unserialize()one call below get_comment_reply_link()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 29 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_comment_reply_link() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always41–45_x(), __(), __(), wp_parse_args()
empty($comment)51_x(), __(), __(), wp_parse_args(), get_comment()
!empty($comment) && !comments_open()63–65_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open()
!empty($comment) && comments_open() && !is_user_logged_in()113–115_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_permalink(), wp_login_url(), esc_url(), apply_filters()
!empty($comment) && comments_open() && get_option() && !is_user_logged_in()115–117_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_permalink(), wp_login_url(), esc_url(), apply_filters()
!empty($comment) && comments_open() && !get_option()154–157_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open()156–159_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && is_user_logged_in()157–160_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && !get_option()159–162_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()159–162_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open()161–164_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && !get_option()161–166_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
17 further outcomes, up to 183 instructions
!empty($comment) && comments_open() && is_user_logged_in()162–165_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open()163–168_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()164–167_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && is_user_logged_in()164–169_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && !get_option()166–171_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()166–171_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open()168–173_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && is_user_logged_in()169–174_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && !get_option()170–173_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()171–176_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open()172–175_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && is_user_logged_in()173–176_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open() && !get_option()175–178_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()175–178_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), apply_filters()
!empty($comment) && comments_open()177–180_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && is_user_logged_in()178–181_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_permalink(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()
!empty($comment) && comments_open() && get_option() && is_user_logged_in()180–183_x(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open(), get_option(), get_comment_link(), apply_filters(), get_option(), is_user_logged_in(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), get_comment_author(), sprintf(), replytocom(), add_query_arg(), esc_attr(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev22041–181132 fewer instructions than PHP 8.5
8.522241–18313
8.422241–183137 fewer instructions than PHP 8.3
8.322941–18913
8.222941–18913
8.122941–189132 fewer instructions than PHP 7.4
7.423141–19013

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while get_comment_reply_link() runs, in this order:

  1. apply_filters( comment_reply_link_args )filterline 1812 (+57 into the body)

    Filters the comment reply link arguments.

  2. apply_filters( comment_reply_link )filterline 1873 (+118 into the body)

    Filters the comment reply link.

Uses · 16

  • _x()Retrieves translated string with gettext context.
  • __()Retrieves the translation of $text.
  • wp_parse_args()Merges user defined arguments into defaults array.
  • get_comment()Retrieves comment data given a comment ID or comment object.
  • get_post()Retrieves post data given a post ID or post object.
  • comments_open()Determines whether the current post is open for comments.
  • get_option()Retrieves an option value based on an option name.
  • get_comment_link()Retrieves the link to a given comment.
  • get_permalink()Retrieves the full permalink for the current post or post ID.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • is_user_logged_in()Determines whether the current visitor is a logged in user.
  • esc_url()Checks and cleans a URL.
Show all 16

Used by · 3

Source code

function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {	$defaults = array(		'add_below'          => 'comment',		'respond_id'         => 'respond',		/* translators: Comment reply button text. */		'reply_text'         => _x( 'Reply', 'verb' ),		/* translators: Comment reply button text. %s: Comment author name. */		'reply_to_text'      => __( 'Reply to %s' ),		'login_text'         => __( 'Log in to Reply' ),		'max_depth'          => 0,		'depth'              => 0,		'before'             => '',		'after'              => '',		'show_reply_to_text' => false,	); 	$args = wp_parse_args( $args, $defaults ); 	$args['max_depth'] = (int) $args['max_depth'];	$args['depth']     = (int) $args['depth']; 	if ( 0 === $args['depth'] || $args['max_depth'] <= $args['depth'] ) {		return null;	} 	$comment = get_comment( $comment ); 	if ( empty( $comment ) ) {		return null;	} 	if ( empty( $post ) ) {		$post = $comment->comment_post_ID;	} 	$post = get_post( $post ); 	if ( ! comments_open( $post->ID ) ) {		return false;	} 	if ( get_option( 'page_comments' ) ) {		$permalink = str_replace( '#comment-' . $comment->comment_ID, '', get_comment_link( $comment ) );	} else {		$permalink = get_permalink( $post->ID );	} 	/**	 * Filters the comment reply link arguments.	 *	 * @since 4.1.0	 *	 * @param array      $args    Comment reply link arguments. See get_comment_reply_link()	 *                            for more information on accepted arguments.	 * @param WP_Comment $comment The object of the comment being replied to.	 * @param WP_Post    $post    The WP_Post object.	 */	$args = apply_filters( 'comment_reply_link_args', $args, $comment, $post ); 	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {		$link = sprintf(			'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',			esc_url( wp_login_url( get_permalink() ) ),			$args['login_text']		);	} else {		$data_attributes = array(			'commentid'      => $comment->comment_ID,			'postid'         => $post->ID,			'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,			'respondelement' => $args['respond_id'],			'replyto'        => sprintf( $args['reply_to_text'], get_comment_author( $comment ) ),		); 		$data_attribute_string = ''; 		foreach ( $data_attributes as $name => $value ) {			$data_attribute_string .= " data-{$name}=\"" . esc_attr( $value ) . '"';		}

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.4.0
Added the ability for $comment to also accept a WP_Comment object.from the docblock
2.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/comment-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.