wppaste
WordPress

WP_Users_List_Table::prepare_items()

Since
3.1.0
Source
wp-admin/includes/class-wp-users-list-table.php:83
Prepares the users list for display.

Compatibility

WordPress
since 3.1.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.

Performance profile

How much work a call to WP_Users_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_results().

Scaling
Constant

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

Instructions
64–95

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

Plugin surface
1 hook

Third-party callbacks on 'users_list_table_query_args' 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
  • sqldatabase query->get_results()called directly

Further down the call graph this can also reach cache. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

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

WhenInstructionsCalls it makes
!isset($value) && $role !== "none"64–82->get_items_per_page(), ->get_pagenum(), apply_filters(), number(), ->get_results(), ->get_total(), total_items()
!isset($value) && $role === "none"70–88->get_items_per_page(), ->get_pagenum(), wp_get_users_with_no_role(), apply_filters(), number(), ->get_results(), ->get_total(), total_items()
isset($value) && $role !== "none"71–89wp_unslash(), ->get_items_per_page(), ->get_pagenum(), apply_filters(), number(), ->get_results(), ->get_total(), total_items()
isset($value) && $role === "none"77–95wp_unslash(), ->get_items_per_page(), ->get_pagenum(), wp_get_users_with_no_role(), apply_filters(), number(), ->get_results(), ->get_total(), total_items()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10464–9481 fewer instruction than PHP 8.5
8.510564–958
8.410564–9582 fewer instructions than PHP 8.3
8.310764–978
8.210764–978
8.110764–978
7.410764–978

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

  1. apply_filters( users_list_table_query_args )filterline 137 (+54 into the body)

    Filters the query arguments used to retrieve users for the current users list table.

Uses · 7

  • wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
  • wp_get_users_with_no_role()Gets the user IDs of all users with no role on this site.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • WP_Users_List_Table::get_items_per_page()
  • WP_Users_List_Table::get_pagenum()
  • WP_User_Query::__construct()Constructor.
  • WP_Users_List_Table::set_pagination_args()

Source code

	public function prepare_items() {		global $role, $usersearch; 		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; 		$role = $_REQUEST['role'] ?? ''; 		$per_page       = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';		$users_per_page = $this->get_items_per_page( $per_page ); 		$paged = $this->get_pagenum(); 		if ( 'none' === $role ) {			$args = array(				'number'  => $users_per_page,				'offset'  => ( $paged - 1 ) * $users_per_page,				'include' => wp_get_users_with_no_role( $this->site_id ),				'search'  => $usersearch,				'fields'  => 'all_with_meta',			);		} else {			$args = array(				'number' => $users_per_page,				'offset' => ( $paged - 1 ) * $users_per_page,				'role'   => $role,				'search' => $usersearch,				'fields' => 'all_with_meta',			);		} 		if ( '' !== $args['search'] ) {			$args['search'] = '*' . $args['search'] . '*';		} 		if ( $this->is_site_users ) {			$args['blog_id'] = $this->site_id;		} 		if ( isset( $_REQUEST['orderby'] ) ) {			$args['orderby'] = $_REQUEST['orderby'];		} 		if ( isset( $_REQUEST['order'] ) ) {			$args['order'] = $_REQUEST['order'];		} 		/**		 * Filters the query arguments used to retrieve users for the current users list table.		 *		 * @since 4.4.0		 *		 * @param array $args Arguments passed to WP_User_Query to retrieve items for the current		 *                    users list table.		 */		$args = apply_filters( 'users_list_table_query_args', $args ); 		// Query the user IDs for this page.		$wp_user_search = new WP_User_Query( $args ); 		$this->items = $wp_user_search->get_results(); 		$this->set_pagination_args(			array(				'total_items' => $wp_user_search->get_total(),				'per_page'    => $users_per_page,			)		);	}

Changelog

Introduced in 3.1.0. 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-users-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.