wppaste
WordPress

WP_Terms_List_Table::prepare_items()

Source
wp-admin/includes/class-wp-terms-list-table.php:77

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.

Performance profile

How much work a call to WP_Terms_List_Table::prepare_items() 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_terms().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
60–103

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

Plugin surface
3 hooks

Third-party callbacks on 'edit_tags_per_page', 'tagsperpage', 'edit_categories_per_page' 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

  • hookthird-party callbacksapply_filters()called directly
  • querycontent queryget_terms()called directly

Further down the call graph this can also reach option, cache, 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 · 12 distinct outcomes

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

WhenInstructionsCalls it makes
$taxonomy !== "post_tag" && $taxonomy !== "category" && empty($value)60–66->get_items_per_page(), ->get_pagenum(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
empty($value)65–78->get_items_per_page(), apply_filters(), ->get_pagenum(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
$taxonomy !== "post_tag" && $taxonomy !== "category"67–73->get_items_per_page(), wp_unslash(), ->get_pagenum(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
$taxonomy !== "post_tag" && $taxonomy !== "category"69–75->get_items_per_page(), ->get_pagenum(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
always72–85->get_items_per_page(), apply_filters(), wp_unslash(), ->get_pagenum(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
always74–87->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
$taxonomy !== "post_tag" && $taxonomy !== "category"76–82->get_items_per_page(), wp_unslash(), ->get_pagenum(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
$taxonomy !== "post_tag" && $taxonomy !== "category"78–84->get_items_per_page(), ->get_pagenum(), wp_unslash(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
always81–94->get_items_per_page(), apply_filters(), wp_unslash(), ->get_pagenum(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
always83–96->get_items_per_page(), apply_filters(), ->get_pagenum(), wp_unslash(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
$taxonomy !== "post_tag" && $taxonomy !== "category" && !empty($value)85–91->get_items_per_page(), wp_unslash(), ->get_pagenum(), wp_unslash(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()
!empty($value)90–103->get_items_per_page(), apply_filters(), wp_unslash(), ->get_pagenum(), wp_unslash(), wp_unslash(), is_taxonomy_hierarchical(), get_terms(), taxonomy(), total_items()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11160–1037
8.511160–1037
8.411160–10377 fewer instructions than PHP 8.3
8.311860–1107
8.211860–1107
8.111860–1107
7.411860–1107

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 · 3

3 hooks fire while WP_Terms_List_Table::prepare_items() runs, in this order:

  1. apply_filters( edit_tags_per_page )filterline 90 (+13 into the body)

    Filters the number of terms displayed per page for the Tags list table.

  2. do_action( tagsperpage )filter_deprecatedline 100 (+23 into the body)

    Filters the number of terms displayed per page for the Tags list table.

  3. apply_filters( edit_categories_per_page )filterline 109 (+32 into the body)

    Filters the number of terms displayed per page for the Categories list table.

Uses · 9

  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • apply_filters_deprecated()Fires functions attached to a deprecated filter hook.
  • wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
  • is_taxonomy_hierarchical()Determines whether the taxonomy object is hierarchical.
  • get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
  • wp_count_terms()Counts how many terms are in taxonomy.
  • WP_Terms_List_Table::get_items_per_page()
  • WP_Terms_List_Table::get_pagenum()
  • WP_Terms_List_Table::set_pagination_args()

Source code

	public function prepare_items() {		$taxonomy = $this->screen->taxonomy; 		$tags_per_page = $this->get_items_per_page( "edit_{$taxonomy}_per_page" ); 		if ( 'post_tag' === $taxonomy ) {			/**			 * Filters the number of terms displayed per page for the Tags list table.			 *			 * @since 2.8.0			 *			 * @param int $tags_per_page Number of tags to be displayed. Default 20.			 */			$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); 			/**			 * Filters the number of terms displayed per page for the Tags list table.			 *			 * @since 2.7.0			 * @deprecated 2.8.0 Use {@see 'edit_tags_per_page'} instead.			 *			 * @param int $tags_per_page Number of tags to be displayed. Default 20.			 */			$tags_per_page = apply_filters_deprecated( 'tagsperpage', array( $tags_per_page ), '2.8.0', 'edit_tags_per_page' );		} elseif ( 'category' === $taxonomy ) {			/**			 * Filters the number of terms displayed per page for the Categories list table.			 *			 * @since 2.8.0			 *			 * @param int $tags_per_page Number of categories to be displayed. Default 20.			 */			$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page );		} 		$search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; 		$args = array(			'taxonomy'   => $taxonomy,			'search'     => $search,			'page'       => $this->get_pagenum(),			'number'     => $tags_per_page,			'hide_empty' => 0,		); 		if ( ! empty( $_REQUEST['orderby'] ) ) {			$args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );		} 		if ( ! empty( $_REQUEST['order'] ) ) {			$args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );		} 		$args['offset'] = ( $args['page'] - 1 ) * $args['number']; 		// Save the values because 'number' and 'offset' can be subsequently overridden.		$this->callback_args = $args; 		if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {			// We'll need the full set of terms then.			$args['number'] = 0;			$args['offset'] = $args['number'];		} 		$this->items = get_terms( $args ); 		$this->set_pagination_args(			array(				'total_items' => wp_count_terms(					array(						'taxonomy' => $taxonomy,						'search'   => $search,					)				),				'per_page'    => $tags_per_page,			)		);	}

Changelog

Unchanged from 6.7.7 through 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.

About this page

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