WP_Posts_List_Table::get_columns(): string[]
- Source
wp-admin/includes/class-wp-posts-list-table.php:655
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_Posts_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
- Light
- Scaling
- Scales with input
- Instructions
- 73–96
- Plugin surface
- 4 hooks
- Called by
- 0
Touches nothing outside its own arguments.
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 121.
Third-party callbacks on 'manage_taxonomies_for_{$post_type}_columns', 'manage_pages_columns', 'manage_posts_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
Further down the call graph this can also reach query, 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::get_columns() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!post_type_supports() | 73–78 | _x(), post_type_supports(), get_object_taxonomies(), wp_filter_object_list(), apply_filters(), array_filter(), post_type_supports(), __(), apply_filters(), apply_filters() |
post_type_supports() | 78–83 | _x(), post_type_supports(), __(), get_object_taxonomies(), wp_filter_object_list(), apply_filters(), array_filter(), post_type_supports(), __(), apply_filters(), apply_filters() |
!$post_status | 88–91 | _x(), post_type_supports(), get_object_taxonomies(), wp_filter_object_list(), apply_filters(), array_filter(), post_type_supports(), esc_attr__(), __(), sprintf(), __(), apply_filters(), apply_filters() |
post_type_supports() && !$post_status | 93–96 | _x(), post_type_supports(), __(), get_object_taxonomies(), wp_filter_object_list(), apply_filters(), array_filter(), post_type_supports(), esc_attr__(), __(), sprintf(), __(), apply_filters(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 121 | 73–96 | 9 | |
| 8.5 | 121 | 73–96 | 9 | |
| 8.4 | 121 | 73–96 | 9 | |
| 8.3 | 121 | 73–96 | 9 | |
| 8.2 | 121 | 73–96 | 9 | |
| 8.1 | 121 | 73–96 | 9 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 122 | 73–97 | 9 |
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::get_columns() runs, in this order:
- apply_filters( manage_taxonomies_for_{$post_type}_columns )filterline 688 (+33 into the body)
Filters the taxonomy columns in the Posts list table.
- apply_filters( manage_pages_columns )filterline 727 (+72 into the body)
Filters the columns displayed in the Pages list table.
- apply_filters( manage_posts_columns )filterline 738 (+83 into the body)
Filters the columns displayed in the Posts list table.
- apply_filters( manage_{$post_type}_posts_columns )filterline 755 (+100 into the body)
Filters the columns displayed in the Posts list table for a specific post type.
Uses · 8
- _x()Retrieves translated string with gettext context.
- post_type_supports()Checks a post type's support for a given feature.
- __()Retrieves the translation of $text.
- get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
- 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.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
Source code
public function get_columns() { $post_type = $this->screen->post_type; $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; /* translators: Posts screen column name. */ $posts_columns['title'] = _x( 'Title', 'column name' ); if ( post_type_supports( $post_type, 'author' ) ) { $posts_columns['author'] = __( 'Author' ); } $taxonomies = get_object_taxonomies( $post_type, 'objects' ); $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); /** * Filters the taxonomy columns in the Posts list table. * * The dynamic portion of the hook name, `$post_type`, refers to the post * type slug. * * Possible hook names include: * * - `manage_taxonomies_for_post_columns` * - `manage_taxonomies_for_page_columns` * * @since 3.5.0 * * @param string[] $taxonomies Array of taxonomy names to show columns for. * @param string $post_type The post type. */ $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type ); $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; } $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) { $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' ) ); } $posts_columns['date'] = __( 'Date' ); if ( 'page' === $post_type ) { /** * Filters the columns displayed in the Pages list table. * * @since 2.5.0 * * @param string[] $posts_columns An associative array of column headings. */ $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns ); } else { /** * Filters the columns displayed in the Posts list table. * * @since 1.5.0 *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 6.9.7 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.