get_page_of_comment( int $comment_id, array $args = array() ): int|null
- Since
- 2.7.0
- Source
wp-includes/comment.php:1046
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
$comment_idint- Comment ID.
$argsarrayoptional- Array of optional arguments.Default:
array()$typestringdefault: 'all'Limit paginated comments to those matching a given type. Accepts 'comment', 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.$per_pageintPer-page count to use when calculating pagination. Defaults to the value of the 'comments_per_page' option.$max_depthint|stringIf greater than 1, comment page will be determined for the top-level parent$comment_id. Defaults to the value of the 'thread_comments_depth' option.
Return value
int|null- Comment page number or null on error.
Performance profile
How much work a call to get_page_of_comment() 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
- 10–124
- Plugin surface
- 2 hooks
- Called by
- 2
Reaches the database via ->query().
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 142.
Third-party callbacks on 'get_page_of_comment_query_args', 'get_page_of_comment' run inside this call, and their cost is not bounded by anything here.
2 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 - sqldatabase query
->query()called directly - cacheobject cache
wp_cache_get()one call below get_page_of_comment() - serializeserialisation
maybe_unserialize()one call below get_page_of_comment()
Further down the call graph this can also reach transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 45 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_page_of_comment() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10 | get_comment() |
$page !== null | 36–47 | get_comment(), wp_parse_args(), get_option(), apply_filters() |
$page === null | 43–54 | get_comment(), wp_parse_args(), get_option(), get_page_of_comment() |
get_option() && $page !== null | 47–52 | get_comment(), wp_parse_args(), get_option(), get_option(), apply_filters() |
get_option() && $page !== null | 47–52 | get_comment(), wp_parse_args(), get_option(), get_query_var(), apply_filters() |
$page === null | 49–60 | get_comment(), wp_parse_args(), get_option(), get_option(), get_page_of_comment() |
get_option() && $page !== null | 52–57 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), apply_filters() |
$page === null && get_option() | 53–65 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_page_of_comment() |
get_option() && $page === null | 54–59 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_page_of_comment() |
get_option() && $page === null | 59–65 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_page_of_comment() |
get_option() && $page === null | 64–69 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_option(), get_page_of_comment() |
get_option() && $page === null | 64–70 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_page_of_comment() |
33 further outcomes, up to 123 instructions
get_option() && $page === null | 69–74 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_option(), get_page_of_comment() |
$page === null && !is_user_logged_in() && $older_comment_count === 0 | 82–99 | get_comment(), wp_parse_args(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
$page === null && is_user_logged_in() && $older_comment_count === 0 | 84–98 | get_comment(), wp_parse_args(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
$page === null && !is_user_logged_in() && $older_comment_count !== 0 | 87–104 | get_comment(), wp_parse_args(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
$page === null && !is_user_logged_in() && $older_comment_count === 0 | 88–105 | get_comment(), wp_parse_args(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
$page === null && is_user_logged_in() && $older_comment_count !== 0 | 89–103 | get_comment(), wp_parse_args(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
$page === null && is_user_logged_in() && $older_comment_count === 0 | 90–104 | get_comment(), wp_parse_args(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
$page === null && get_option() && !is_user_logged_in() && $older_comment_count === 0 | 92–110 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count === 0 | 93–104 | get_comment(), wp_parse_args(), get_option(), get_query_var(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
$page === null && !is_user_logged_in() && $older_comment_count !== 0 | 93–110 | get_comment(), wp_parse_args(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
$page === null && get_option() && is_user_logged_in() && $older_comment_count === 0 | 94–109 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count === 0 | 95–103 | get_comment(), wp_parse_args(), get_option(), get_query_var(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
$page === null && is_user_logged_in() && $older_comment_count !== 0 | 95–109 | get_comment(), wp_parse_args(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
$page === null && get_option() && !is_user_logged_in() && $older_comment_count !== 0 | 97–115 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count !== 0 | 98–109 | get_comment(), wp_parse_args(), get_option(), get_query_var(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count === 0 | 98–110 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
$page === null && get_option() && is_user_logged_in() && $older_comment_count !== 0 | 99–114 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count !== 0 | 100–108 | get_comment(), wp_parse_args(), get_option(), get_query_var(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count === 0 | 100–109 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count === 0 | 103–114 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count !== 0 | 103–115 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count === 0 | 103–115 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count === 0 | 105–113 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count !== 0 | 105–114 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count === 0 | 105–114 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count !== 0 | 108–119 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count !== 0 | 108–120 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count === 0 | 108–119 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count !== 0 | 110–118 | get_comment(), wp_parse_args(), get_option(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count !== 0 | 110–119 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count === 0 | 110–118 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), apply_filters() |
get_option() && $page === null && !is_user_logged_in() && $older_comment_count !== 0 | 113–124 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_option(), is_user_logged_in(), wp_get_unapproved_comment_author_email(), apply_filters(), ->query(), ceil(), apply_filters() |
get_option() && $page === null && is_user_logged_in() && $older_comment_count !== 0 | 115–123 | get_comment(), wp_parse_args(), get_option(), get_query_var(), get_option(), get_option(), get_option(), is_user_logged_in(), get_current_user_id(), apply_filters(), ->query(), ceil(), 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: 142 instructions, 10–124 executed per call, 14 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 · 2
2 hooks fire while get_page_of_comment() runs, in this order:
- apply_filters( get_page_of_comment_query_args )filterline 1149 (+103 into the body)
Filters the arguments used to query comments in get_page_of_comment().
- apply_filters( get_page_of_comment )filterline 1191 (+145 into the body)
Filters the calculated page on which a comment appears.
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_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.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- get_current_user_id()Gets the current user's ID.
- wp_get_unapproved_comment_author_email()Gets unapproved comment author's email.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Comment_Query::__construct()Constructor.
Used by · 2
- get_comment_link()Retrieves the link to a given comment.
- get_page_of_comment()Calculates what page number a comment will appear on for comment paging.
Source code
function get_page_of_comment( $comment_id, $args = array() ) { global $wpdb; $page = null; $comment = get_comment( $comment_id ); if ( ! $comment ) { return null; } $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', ); $args = wp_parse_args( $args, $defaults ); $original_args = $args; // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option. if ( get_option( 'page_comments' ) ) { if ( '' === $args['per_page'] ) { $args['per_page'] = get_query_var( 'comments_per_page' ); } if ( '' === $args['per_page'] ) { $args['per_page'] = get_option( 'comments_per_page' ); } } if ( empty( $args['per_page'] ) ) { $args['per_page'] = 0; $args['page'] = 0; } if ( $args['per_page'] < 1 ) { $page = 1; } if ( null === $page ) { if ( '' === $args['max_depth'] ) { if ( get_option( 'thread_comments' ) ) { $args['max_depth'] = get_option( 'thread_comments_depth' ); } else { $args['max_depth'] = -1; } } // Find this comment's top-level parent if threading is enabled. if ( $args['max_depth'] > 1 && '0' !== $comment->comment_parent ) { return get_page_of_comment( $comment->comment_parent, $args ); } $comment_args = array( 'type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'orderby' => 'none', 'parent' => 0, 'date_query' => array( array( 'column' => "$wpdb->comments.comment_date_gmt", 'before' => $comment->comment_date_gmt, ), ), ); if ( is_user_logged_in() ) { $comment_args['include_unapproved'] = array( get_current_user_id() ); } else { $unapproved_email = wp_get_unapproved_comment_author_email(); if ( $unapproved_email ) { $comment_args['include_unapproved'] = array( $unapproved_email ); } } /**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.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/comment.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.