WP_Posts_List_Table::column_default( WP_Post $item, string $column_name )
- Since
- 4.3.0, 5.9.0
- Source
wp-admin/includes/class-wp-posts-list-table.php:1405
Compatibility
- WordPress
- since 5.9.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
$itemWP_Post- The current WP_Post object.
$column_namestring- The current column name.
Performance profile
How much work a call to WP_Posts_List_Table::column_default() 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
- Scales with input
- Instructions
- 27–41
- Plugin surface
- 4 hooks
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 126.
Third-party callbacks on 'post_column_taxonomy_links', 'manage_pages_custom_column', 'manage_posts_custom_column' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below WP_Posts_List_Table::column_default() - cacheobject cache
wp_cache_add()one call below WP_Posts_List_Table::column_default()
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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::column_default() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_array($terms) | 27–31 | get_taxonomy(), get_the_terms() |
| always | 33–38 | is_post_type_hierarchical(), do_action(), do_action() |
is_array($terms) | 36–41 | get_taxonomy(), get_the_terms(), apply_filters(), wp_get_list_item_separator() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 126 | 27–41 | 10 | |
| 8.5 | 126 | 27–41 | 10 | |
| 8.4 | 126 | 27–41 | 10 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 136 | 27–51 | 10 | |
| 8.2 | 136 | 27–51 | 10 | |
| 8.1 | 136 | 27–51 | 10 | |
| 7.4 | 136 | 27–51 | 10 |
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 · 4
4 hooks fire while WP_Posts_List_Table::column_default() runs, in this order:
- apply_filters( post_column_taxonomy_links )filterline 1454 (+49 into the body)
Filters the links in `$taxonomy` column of edit.php.
- do_action( manage_pages_custom_column )actionline 1476 (+71 into the body)
Fires in each custom column on the Posts list table.
- do_action( manage_posts_custom_column )actionline 1490 (+85 into the body)
Fires in each custom column in the Posts list table.
- do_action( manage_{$post->post_type}_posts_custom_column )actionline 1508 (+103 into the body)
Fires for each custom column of a specific post type in the Posts list table.
Uses · 10
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- get_the_terms()Retrieves the terms of the taxonomy that are attached to the post.
- esc_html()Escaping for HTML blocks.
- sanitize_term_field()Sanitizes the field value in the term based on the context.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_get_list_item_separator()Retrieves the list item separator based on the locale.
- is_post_type_hierarchical()Determines whether the post type is hierarchical.
- do_action()Calls the callback functions that have been added to an action hook.
- WP_Posts_List_Table::get_edit_link()Creates a link to edit.php with params.
Source code
public function column_default( $item, $column_name ) { // Restores the more descriptive, specific name for use within this method. $post = $item; if ( 'categories' === $column_name ) { $taxonomy = 'category'; } elseif ( 'tags' === $column_name ) { $taxonomy = 'post_tag'; } elseif ( str_starts_with( $column_name, 'taxonomy-' ) ) { $taxonomy = substr( $column_name, 9 ); } else { $taxonomy = false; } if ( $taxonomy ) { $taxonomy_object = get_taxonomy( $taxonomy ); $terms = get_the_terms( $post->ID, $taxonomy ); if ( is_array( $terms ) ) { $term_links = array(); foreach ( $terms as $t ) { $posts_in_term_qv = array(); if ( 'post' !== $post->post_type ) { $posts_in_term_qv['post_type'] = $post->post_type; } if ( $taxonomy_object->query_var ) { $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug; } else { $posts_in_term_qv['taxonomy'] = $taxonomy; $posts_in_term_qv['term'] = $t->slug; } $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ); $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label ); } /** * Filters the links in `$taxonomy` column of edit.php. * * @since 5.2.0 * * @param string[] $term_links Array of term editing links. * @param string $taxonomy Taxonomy name. * @param WP_Term[] $terms Array of term objects appearing in the post row. */ $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms ); echo implode( wp_get_list_item_separator(), $term_links ); } else { echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>'; } return; } if ( is_post_type_hierarchical( $post->post_type ) ) { /** * Fires in each custom column on the Posts list table. * * This hook only fires if the current post type is hierarchical, * such as pages. * * @since 2.5.0 * * @param string $column_name The name of the column to display. * @param int $post_id The current post ID. */ do_action( 'manage_pages_custom_column', $column_name, $post->ID ); } else { /** * Fires in each custom column in the Posts list table. * * This hook only fires if the current post type is non-hierarchical, * such as posts. *Changelog
Introduced in 4.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$post to $item to match parent class for PHP 8 named parameter support.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-wp-posts-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.