wppaste
WordPress

get_post_reply_link( array $args = array(), int|WP_Post $post = null ): string|false

Since
2.7.0
Source
wp-includes/comment-template.php:1915
Retrieves HTML content for reply to post link.

Compatibility

WordPress
since 2.7.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: is 'post'

    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: is 'Leave a Comment'

    Text of the Reply link.
  • $login_textstringdefault: is 'Log in to leave a Comment'

    Text of the link to reply if logged out.
  • $beforestringdefault: empty

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

    Text or HTML to add after the reply link.
$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
Link to show comment form on success. False if comments are closed.

Performance profile

How much work a call to get_post_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
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
31–73

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

Plugin surface
1 hook

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

Called by
1

1 place 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_post_reply_link()
  • serializeserialisationmaybe_unserialize()one call below get_post_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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
!comments_open()31__(), __(), wp_parse_args(), get_post(), comments_open()
comments_open() && get_option() && !is_user_logged_in()59__(), __(), wp_parse_args(), get_post(), comments_open(), get_option(), is_user_logged_in(), get_permalink(), wp_login_url(), apply_filters()
comments_open() && !get_option()70__(), __(), wp_parse_args(), get_post(), comments_open(), get_option(), sprintf(), get_permalink(), apply_filters()
comments_open() && get_option() && is_user_logged_in()73__(), __(), wp_parse_args(), get_post(), comments_open(), get_option(), is_user_logged_in(), sprintf(), get_permalink(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8631–733
8.58631–733
8.48631–7331 fewer instruction than PHP 8.3
8.38731–733
8.28731–733
8.18731–733
7.48731–733

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 · 1

One hook fires while get_post_reply_link() runs, in this order:

  1. apply_filters( post_comments_link )filterline 1965 (+50 into the body)

    Filters the formatted post comments link HTML.

Uses · 9

Used by · 1

Source code

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 = wp_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="%s">%s</a>',			wp_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='%s' onclick='%s'>%s</a>",			get_permalink( $post->ID ) . '#' . $args['respond_id'],			$onclick,			$args['reply_text']		);	} 	$post_reply_link = $args['before'] . $link . $args['after']; 	/**	 * Filters the formatted post comments link HTML.	 *	 * @since 2.7.0	 *	 * @param string      $post_reply_link The HTML-formatted post comments link.	 * @param int|WP_Post $post            The post ID or WP_Post object.	 */	return apply_filters( 'post_comments_link', $post_reply_link, $post );}

Changelog

Introduced in 2.7.0. One change between 6.7.7 and 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.

6.9.7
Return type changed from string|false|null to string|false.verified against source
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.