get_comment_link( WP_Comment|int|null $comment = null, array $args = array() ): string
- Since
- 1.5.0, 4.4.0
- Source
wp-includes/comment-template.php:778
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
$commentWP_Comment|int|nulloptional- Comment to retrieve. Default current comment.Default:
null $argsarrayoptional- An array of optional arguments to override the defaults.Default:
array()$typestringPassed to get_page_of_comment().$pageintCurrent page of comments, for calculating comment pagination.$per_pageintPer-page value for comment pagination.$max_depthintPassed to get_page_of_comment().$cpageint|stringValue to use for the comment's "comment-page" or "cpage" value. If provided, this value overrides any value calculated from$pageand$per_page.
Return value
string- The permalink to the given comment.
Performance profile
How much work a call to get_comment_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
- 43–102
- Plugin surface
- 1 hook
- Called by
- 21
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 116.
Third-party callbacks on 'get_comment_link' run inside this call, and their cost is not bounded by anything here.
21 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below get_comment_link() - cacheobject cache
wp_cache_get()one call below get_comment_link() - serializeserialisation
maybe_unserialize()one call below get_comment_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 · 74 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_comment_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$args && !->using_permalinks() | 43–45 | get_comment(), wp_parse_args(), get_permalink(), ->using_permalinks(), apply_filters() |
!->using_permalinks() | 47–63 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), apply_filters() |
!$args && ->using_permalinks() | 48–50 | get_comment(), wp_parse_args(), get_permalink(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
->using_permalinks() | 52–68 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$args && get_option() && !->using_permalinks() | 56–58 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage !== "" && !get_option() && !->using_permalinks() | 58–67 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$args && get_option() | 59–61 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$args && get_option() | 61–63 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && !$args && !->using_permalinks() | 62–71 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), ->using_permalinks(), apply_filters() |
$cpage !== "" && !->using_permalinks() | 62–72 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && !$args && !->using_permalinks() | 63–72 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), ->using_permalinks(), apply_filters() |
$cpage !== "" && !get_option() && ->using_permalinks() | 63–72 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
62 further outcomes, up to 102 instructions
$args && get_option() && ->using_permalinks() | 64–66 | get_comment(), wp_parse_args(), get_permalink(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && !get_option() && !->using_permalinks() | 66–75 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
!get_option() && $cpage === "" && !empty($in_comment_loop) && !$args && !->using_permalinks() | 66–75 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && !get_option() && !->using_permalinks() | 67–76 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && !$args && ->using_permalinks() | 67–76 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
!get_option() && $cpage === "" && empty($in_comment_loop) && !$args && !->using_permalinks() | 67–76 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), ->using_permalinks(), apply_filters() |
$cpage !== "" && $args && get_option() && !->using_permalinks() | 67–76 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage !== "" && ->using_permalinks() | 67–77 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage !== "" && $args && !->using_permalinks() | 67–76 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && !$args && ->using_permalinks() | 68–77 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage !== "" && $args && get_option() | 70–79 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
!get_option() && $cpage === "" && !empty($in_comment_loop) && $args && !->using_permalinks() | 70–79 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && !get_option() && ->using_permalinks() | 71–80 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
!get_option() && $cpage === "" && empty($in_comment_loop) && $args && !->using_permalinks() | 71–80 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
!get_option() && $cpage === "" && !empty($in_comment_loop) && !$args && ->using_permalinks() | 71–80 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && !$args && !->using_permalinks() | 71–80 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), ->using_permalinks(), apply_filters() |
$cpage !== "" && $args && !->using_permalinks() | 71–80 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && !get_option() && ->using_permalinks() | 72–81 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
!get_option() && $cpage === "" && empty($in_comment_loop) && !$args && ->using_permalinks() | 72–81 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && !$args && !->using_permalinks() | 72–81 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), ->using_permalinks(), apply_filters() |
$cpage !== "" && $args && get_option() | 72–81 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage !== "" && $args && ->using_permalinks() | 72–81 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage !== "" && $args | 74–83 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage !== "" && $args && get_option() && ->using_permalinks() | 75–84 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && get_option() && !->using_permalinks() | 75–84 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
!get_option() && $cpage === "" && !empty($in_comment_loop) && $args && ->using_permalinks() | 75–84 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && !->using_permalinks() | 75–84 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && get_option() && !->using_permalinks() | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
!get_option() && $cpage === "" && empty($in_comment_loop) && $args && ->using_permalinks() | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && !->using_permalinks() | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && !$args && ->using_permalinks() | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage !== "" && $args | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage !== "" && $args && !->using_permalinks() | 76–85 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && !$args && ->using_permalinks() | 77–86 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && get_option() | 78–87 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && get_option() | 79–88 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage !== "" && $args && ->using_permalinks() | 79–88 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && !->using_permalinks() | 79–88 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
get_option() && $cpage !== "" && $args | 79–88 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && get_option() | 80–89 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && !->using_permalinks() | 80–89 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && ->using_permalinks() | 80–89 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && get_option() | 81–90 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && ->using_permalinks() | 81–90 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage !== "" && $args | 81–90 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args | 82–91 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && get_option() && ->using_permalinks() | 83–92 | get_comment(), wp_parse_args(), get_permalink(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args | 83–92 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && get_option() && ->using_permalinks() | 84–93 | get_comment(), wp_parse_args(), get_permalink(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args | 84–93 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage !== "" && $args && ->using_permalinks() | 84–93 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && $args && !->using_permalinks() | 84–93 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args | 85–94 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && $args && !->using_permalinks() | 85–94 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), apply_filters() |
$cpage === "" && !empty($in_comment_loop) && $args && ->using_permalinks() | 87–96 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && $args | 87–96 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
$cpage === "" && empty($in_comment_loop) && $args && ->using_permalinks() | 88–97 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && $args | 88–97 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && $args | 89–98 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && $args | 90–99 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), add_query_arg(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && !empty($in_comment_loop) && $args && ->using_permalinks() | 92–101 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_query_var(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
get_option() && $cpage === "" && empty($in_comment_loop) && $args && ->using_permalinks() | 93–102 | get_comment(), wp_parse_args(), get_permalink(), get_option(), get_option(), get_page_of_comment(), get_option(), get_option(), ->using_permalinks(), trailingslashit(), ->using_permalinks(), user_trailingslashit(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 116 instructions, 43–102 executed per call, 13 branches. The work does not change between versions.
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_comment_link() runs, in this order:
- apply_filters( get_comment_link )filterline 862 (+84 into the body)
Filters the returned single comment permalink.
Uses · 10
- get_comment()Retrieves comment data given a comment ID or comment object.
- wp_parse_args()Merges user defined arguments into defaults array.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_option()Retrieves an option value based on an option name.
- get_query_var()Retrieves the value of a query variable in the WP_Query class.
- get_page_of_comment()Calculates what page number a comment will appear on for comment paging.
- trailingslashit()Appends a trailing slash.
- add_query_arg()Retrieves a modified URL query string.
- user_trailingslashit()Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 21
- TwentyNineteen_Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- TwentyTwenty_Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- WP_Comments_List_Table::column_comment()
- WP_Comments_List_Table::column_date()
- WP_REST_Comments_Controller::prepare_item_for_response()Prepares a single comment output for response.
- WP_Widget_Recent_Comments::widget()Outputs the content for the current Recent Comments widget instance.
- Walker_Comment::comment()Outputs a single comment.
- Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- _wp_ajax_delete_comment_response()Sends back current comment total and new page links if they need to be updated.
- _wp_dashboard_recent_comments_row()Outputs a row for the Recent Comments widget.
- comment_link()Displays the link to the comments.
- get_comment_reply_link()Retrieves HTML content for reply to comment link.
Show all 21
- get_comment_text()Retrieves the text of the current comment.
- render_block_core_comment_date()Renders the `core/comment-date` block on the server.
- render_block_core_latest_comments()Renders the `core/latest-comments` block on server.
- twentyeleven_comment()Template for comments and pingbacks.
- twentyten_comment()Template for comments and pingbacks.
- twentytwelve_comment()Template for comments and pingbacks.
- wp_comments_personal_data_exporter()Finds and exports personal data associated with an email address from the comments table.
- wp_notify_postauthor()Notifies an author (and/or others) of a comment/trackback/pingback on a post.
- wp_xmlrpc_server::_prepare_comment()Prepares comment data for return in an XML-RPC object.
Source code
function get_comment_link( $comment = null, $args = array() ) { global $wp_rewrite, $in_comment_loop; $comment = get_comment( $comment ); // Back-compat. if ( ! is_array( $args ) ) { $args = array( 'page' => $args ); } $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null, ); $args = wp_parse_args( $args, $defaults ); $comment_link = get_permalink( $comment->comment_post_ID ); // The 'cpage' param takes precedence. if ( ! is_null( $args['cpage'] ) ) { $cpage = $args['cpage']; // No 'cpage' is provided, so we calculate one. } else { if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) { $args['per_page'] = get_option( 'comments_per_page' ); } if ( empty( $args['per_page'] ) ) { $args['per_page'] = 0; $args['page'] = 0; } $cpage = $args['page']; if ( '' === $cpage ) { if ( ! empty( $in_comment_loop ) ) { $cpage = (int) get_query_var( 'cpage' ); } else { // Requires a database hit, so we only do it when we can't figure out from context. $cpage = get_page_of_comment( $comment->comment_ID, $args ); } } /* * If the default page displays the oldest comments, the permalinks for comments on the default page * do not need a 'cpage' query var. */ if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) { $cpage = ''; } } if ( $cpage && get_option( 'page_comments' ) ) { if ( $wp_rewrite->using_permalinks() ) { $comment_link = trailingslashit( $comment_link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage; } else { $comment_link = add_query_arg( 'cpage', $cpage, $comment_link ); } } if ( $wp_rewrite->using_permalinks() ) { $comment_link = user_trailingslashit( $comment_link, 'comment' ); } $comment_link = $comment_link . '#comment-' . $comment->comment_ID; /** * Filters the returned single comment permalink. * * @since 2.8.0 * @since 4.4.0 Added the `$cpage` parameter. * * @see get_page_of_comment() * * @param string $comment_link The comment permalink with '#comment-$id' appended.Changelog
Introduced in 1.5.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. Added $cpage argument.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.