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:1759
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 valueThe accessible name of the Reply link, using%sas a placeholder for the comment author's name.$show_reply_to_textbooldefault: falseWhether to usereply_to_textas visible link text.$login_textstringdefault: 'Log in to Reply'The text of the link to reply if logged out.$max_depthintdefault: 0The max depth of the comment tree.$depthintdefault: 0The 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: emptyThe text or HTML to add before the reply link.$afterstringdefault: emptyThe 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, if successful. False, if comments are closed.
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
- Scaling
- Scales with input
- Instructions
- 32–174
- Plugin surface
- 2 hooks
- Called by
- 3
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 213.
Third-party callbacks on 'comment_reply_link_args', 'comment_reply_link' run inside this call, and their cost is not bounded by anything here.
3 places 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_comment_reply_link() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 32–36 | __(), __(), __(), wp_parse_args() |
empty($comment) | 42 | __(), __(), __(), wp_parse_args(), get_comment() |
!empty($comment) && !comments_open() | 54–56 | __(), __(), __(), wp_parse_args(), get_comment(), get_post(), comments_open() |
!empty($comment) && comments_open() && !is_user_logged_in() | 104–106 | __(), __(), __(), 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() | 106–108 | __(), __(), __(), 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() | 145–148 | __(), __(), __(), 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() | 147–150 | __(), __(), __(), 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() | 148–151 | __(), __(), __(), 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() | 150–153 | __(), __(), __(), 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() | 150–153 | __(), __(), __(), 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() | 152–155 | __(), __(), __(), 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() | 152–157 | __(), __(), __(), 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 174 instructions
!empty($comment) && comments_open() && is_user_logged_in() | 153–156 | __(), __(), __(), 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() | 154–159 | __(), __(), __(), 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() | 155–158 | __(), __(), __(), 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() | 155–160 | __(), __(), __(), 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() | 157–162 | __(), __(), __(), 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() | 157–162 | __(), __(), __(), 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() | 159–164 | __(), __(), __(), 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() | 160–165 | __(), __(), __(), 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() | 161–164 | __(), __(), __(), 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() | 162–167 | __(), __(), __(), 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() | 163–166 | __(), __(), __(), 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() | 164–167 | __(), __(), __(), 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() | 166–169 | __(), __(), __(), 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() | 166–169 | __(), __(), __(), 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() | 168–171 | __(), __(), __(), 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() | 169–172 | __(), __(), __(), 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() | 171–174 | __(), __(), __(), 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 211 | 32–172 | 13 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 213 | 32–174 | 13 | |
| 8.4 | 213 | 32–174 | 13 | 7 fewer instructions than PHP 8.3 |
| 8.3 | 220 | 32–180 | 13 | |
| 8.2 | 220 | 32–180 | 13 | |
| 8.1 | 220 | 32–180 | 13 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 222 | 32–181 | 13 |
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:
- apply_filters( comment_reply_link_args )filterline 1812 (+53 into the body)
Filters the comment reply link arguments.
- apply_filters( comment_reply_link )filterline 1873 (+114 into the body)
Filters the comment reply link.
Uses · 15
- __()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.
- wp_login_url()Retrieves the login URL.
Show all 15
- get_comment_author()Retrieves the author of the current comment.
- esc_attr()Escaping for HTML attributes.
- add_query_arg()Retrieves a modified URL query string.
Used by · 3
- TwentyTwenty_Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- comment_reply_link()Displays the HTML content for reply to comment link.
- render_block_core_comment_reply_link()Renders the `core/comment-reply-link` block on the server.
Source code
function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { $defaults = array( 'add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __( 'Reply' ), /* 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 ); if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) { return; } $comment = get_comment( $comment ); if ( empty( $comment ) ) { return; } 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 ) . '"'; } $data_attribute_string = trim( $data_attribute_string ); $reply_text = $args['show_reply_to_text'] ? sprintf( $args['reply_to_text'], get_comment_author( $comment ) )Changelog
Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$comment to also accept a WP_Comment object.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 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.