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
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: emptyText or HTML to add before the reply link.$afterstringdefault: emptyText 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
- Scaling
- Constant
- Instructions
- 31–73
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.
Third-party callbacks on 'post_comments_link' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_post_reply_link() - serializeserialisation
maybe_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.
| When | Instructions | Calls 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 86 | 31–73 | 3 | |
| 8.5 | 86 | 31–73 | 3 | |
| 8.4 | 86 | 31–73 | 3 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 87 | 31–73 | 3 | |
| 8.2 | 87 | 31–73 | 3 | |
| 8.1 | 87 | 31–73 | 3 | |
| 7.4 | 87 | 31–73 | 3 |
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:
- apply_filters( post_comments_link )filterline 1965 (+50 into the body)
Filters the formatted post comments link HTML.
Uses · 9
- __()Retrieves the translation of $text.
- wp_parse_args()Merges user defined arguments into defaults array.
- 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.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_login_url()Retrieves the login URL.
- 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.
Used by · 1
- post_reply_link()Displays the HTML content for reply to post link.
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.
Signature, return type and hooks compared across 5 parsed releases.
string|false|null to string|false.verified against sourceAbout 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.