WP_Media_List_Table::column_default( WP_Post $item, string $column_name )
- Since
- 4.3.0, 5.9.0
- Source
wp-admin/includes/class-wp-media-list-table.php:693
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- Current column name.
Performance profile
How much work a call to WP_Media_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
- 16–30
- Plugin surface
- 1 hook
- 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 87.
Third-party callbacks on 'manage_media_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
do_action()called directly - querycontent query
get_post()one call below WP_Media_List_Table::column_default() - cacheobject cache
wp_cache_add()one call below WP_Media_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_Media_List_Table::column_default() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 16–20 | do_action() |
is_array($terms) | 25–30 | get_the_terms(), wp_get_list_item_separator() |
!is_array($terms) | 26–30 | get_the_terms(), get_taxonomy() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 87 | 16–30 | 7 | |
| 8.5 | 87 | 16–30 | 7 | |
| 8.4 | 87 | 16–30 | 7 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 97 | 16–40 | 7 | |
| 8.2 | 97 | 16–40 | 7 | |
| 8.1 | 97 | 16–40 | 7 | |
| 7.4 | 97 | 16–40 | 7 |
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_Media_List_Table::column_default() runs, in this order:
- do_action( manage_media_custom_column )actionline 743 (+50 into the body)
Fires for each custom column in the Media list table.
Uses · 9
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- get_the_terms()Retrieves the terms of the taxonomy that are attached to the post.
- esc_url()Checks and cleans a URL.
- add_query_arg()Retrieves a modified URL query string.
- esc_html()Escaping for HTML blocks.
- sanitize_term_field()Sanitizes the field value in the term based on the context.
- wp_get_list_item_separator()Retrieves the list item separator based on the locale.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- do_action()Calls the callback functions that have been added to an action hook.
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 ) { $terms = get_the_terms( $post->ID, $taxonomy ); if ( is_array( $terms ) ) { $output = array(); foreach ( $terms as $t ) { $posts_in_term_qv = array(); $posts_in_term_qv['taxonomy'] = $taxonomy; $posts_in_term_qv['term'] = $t->slug; $output[] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ), esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) ); } echo implode( wp_get_list_item_separator(), $output ); } else { echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>'; } return; } /** * Fires for each custom column in the Media list table. * * Custom columns are registered using the {@see 'manage_media_columns'} filter. * * @since 2.5.0 * * @param string $column_name Name of the custom column. * @param int $post_id Attachment ID. */ do_action( 'manage_media_custom_column', $column_name, $post->ID ); }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-media-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.