WP_Media_List_Table::get_columns(): string[]
- Source
wp-admin/includes/class-wp-media-list-table.php:364
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
string[]- Array of column titles keyed by their column name.
Performance profile
How much work a call to WP_Media_List_Table::get_columns() 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
- 52–81
- Plugin surface
- 2 hooks
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 99.
Third-party callbacks on 'manage_taxonomies_for_attachment_columns', 'manage_media_columns' 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 - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below WP_Media_List_Table::get_columns() - serializeserialisation
maybe_unserialize()one call below WP_Media_List_Table::get_columns()
Further down the call graph this can also reach query 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Media_List_Table::get_columns() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 52–53 | _x(), __(), get_taxonomies_for_attachments(), wp_filter_object_list(), apply_filters(), array_filter(), _x(), apply_filters() |
!post_type_supports() | 63–64 | _x(), __(), get_taxonomies_for_attachments(), wp_filter_object_list(), apply_filters(), array_filter(), _x(), post_type_supports(), _x(), apply_filters() |
post_type_supports() && !get_option() | 67–68 | _x(), __(), get_taxonomies_for_attachments(), wp_filter_object_list(), apply_filters(), array_filter(), _x(), post_type_supports(), get_option(), _x(), apply_filters() |
post_type_supports() && get_option() | 80–81 | _x(), __(), get_taxonomies_for_attachments(), wp_filter_object_list(), apply_filters(), array_filter(), _x(), post_type_supports(), get_option(), esc_attr__(), __(), sprintf(), _x(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 99 instructions, 52–81 executed per call, 7 branches. The work does not change between versions.
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 · 2
2 hooks fire while WP_Media_List_Table::get_columns() runs, in this order:
- apply_filters( manage_taxonomies_for_attachment_columns )filterline 382 (+18 into the body)
Filters the taxonomy columns for attachments in the Media list table.
- apply_filters( manage_media_columns )filterline 423 (+59 into the body)
Filters the Media list table columns.
Uses · 9
- _x()Retrieves translated string with gettext context.
- __()Retrieves the translation of $text.
- get_taxonomies_for_attachments()Retrieves all of the taxonomies that are registered for attachments.
- wp_filter_object_list()Filters a list of objects, based on a set of key => value arguments.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- post_type_supports()Checks a post type's support for a given feature.
- get_option()Retrieves an option value based on an option name.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
Source code
public function get_columns() { $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; /* translators: Column name. */ $posts_columns['title'] = _x( 'File', 'column name' ); $posts_columns['author'] = __( 'Author' ); $taxonomies = get_taxonomies_for_attachments( 'objects' ); $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); /** * Filters the taxonomy columns for attachments in the Media list table. * * @since 3.5.0 * * @param string[] $taxonomies An array of registered taxonomy names to show for attachments. * @param string $post_type The post type. Default 'attachment'. */ $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' ); $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' ); foreach ( $taxonomies as $taxonomy ) { if ( 'category' === $taxonomy ) { $column_key = 'categories'; } elseif ( 'post_tag' === $taxonomy ) { $column_key = 'tags'; } else { $column_key = 'taxonomy-' . $taxonomy; } $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name; } /* translators: Column name. */ if ( ! $this->detached ) { $posts_columns['parent'] = _x( 'Uploaded to', 'column name' ); if ( post_type_supports( 'attachment', 'comments' ) && get_option( 'wp_attachment_pages_enabled' ) ) { $posts_columns['comments'] = sprintf( '<span class="vers comment-grey-bubble" title="%1$s" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span>', esc_attr__( 'Comments' ), /* translators: Hidden accessibility text. */ __( 'Comments' ) ); } } /* translators: Column name. */ $posts_columns['date'] = _x( 'Date', 'column name' ); /** * Filters the Media list table columns. * * @since 2.5.0 * * @param string[] $posts_columns An array of columns displayed in the Media list table. * @param bool $detached Whether the list table contains media not attached * to any posts. Default true. */ return apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.