wppaste
WordPress

WP_Comments_List_Table::get_views(): array<string,

Source
wp-admin/includes/class-wp-comments-list-table.php:250
Returns an array of comment status links.

Compatibility

WordPress
core
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.

Return value

array<string,
string> Comment status HTML links keyed by view.

Performance profile

How much work a call to WP_Comments_List_Table::get_views() 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_comments().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
64–76

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

Plugin surface
1 hook

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

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_comments()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below WP_Comments_List_Table::get_views()

Further down the call graph this can also reach option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 2 distinct outcomes

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

WhenInstructionsCalls it makes
always64–70wp_count_comments(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), admin_url(), ->get_views_links(), apply_filters()
!empty($comment_type) && $comment_type !== "all"72–76wp_count_comments(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), _nx_noop(), admin_url(), add_query_arg(), ->get_views_links(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev16363–75112 fewer instructions than PHP 8.5
8.516564–7611
8.416564–7611
8.316564–7611
8.216564–7611
8.116564–7611
7.416564–7611

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 WP_Comments_List_Table::get_views() runs, in this order:

  1. apply_filters( comment_status_links )filterline 365 (+115 into the body)

    Filters the comment status links.

Uses · 13

Show all 13
  • WP_Comments_List_Table::get_views_links()

Source code

	protected function get_views() {		global $post_id, $comment_status, $comment_type; 		$status_links = array();		$num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); 		$statuses = array(			/* translators: %s: Number of comments. */			'all'       => _nx_noop(				'All <span class="count">(%s)</span>',				'All <span class="count">(%s)</span>',				'comments'			), // Singular not used. 			/* translators: %s: Number of comments. */			'mine'      => _nx_noop(				'Mine <span class="count">(%s)</span>',				'Mine <span class="count">(%s)</span>',				'comments'			), 			/* translators: %s: Number of comments. */			'moderated' => _nx_noop(				'Pending <span class="count">(%s)</span>',				'Pending <span class="count">(%s)</span>',				'comments'			), 			/* translators: %s: Number of comments. */			'approved'  => _nx_noop(				'Approved <span class="count">(%s)</span>',				'Approved <span class="count">(%s)</span>',				'comments'			), 			/* translators: %s: Number of comments. */			'spam'      => _nx_noop(				'Spam <span class="count">(%s)</span>',				'Spam <span class="count">(%s)</span>',				'comments'			), 			/* translators: %s: Number of comments. */			'trash'     => _nx_noop(				'Trash <span class="count">(%s)</span>',				'Trash <span class="count">(%s)</span>',				'comments'			),		); 		if ( ! EMPTY_TRASH_DAYS ) {			unset( $statuses['trash'] );		} 		$link = admin_url( 'edit-comments.php' ); 		if ( ! empty( $comment_type ) && 'all' !== $comment_type ) {			$link = add_query_arg( 'comment_type', $comment_type, $link );		} 		foreach ( $statuses as $status => $label ) {			if ( 'mine' === $status ) {				$current_user_id    = get_current_user_id();				$num_comments->mine = get_comments(					array(						'post_id' => $post_id ? $post_id : 0,						'user_id' => $current_user_id,						'count'   => true,						'orderby' => 'none',					)				);				$link               = add_query_arg( 'user_id', $current_user_id, $link );			} else {				$link = remove_query_arg( 'user_id', $link );			} 			if ( ! isset( $num_comments->$status ) ) {				$num_comments->$status = 10;			}

Changelog

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.

7.0.4
Return type changed from none to array<string,.verified against source

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-wp-comments-list-table.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.