wppaste
WordPress

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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
52–81

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

Plugin surface
2 hooks

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.

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
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below WP_Media_List_Table::get_columns()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
always52–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:

  1. apply_filters( manage_taxonomies_for_attachment_columns )filterline 382 (+18 into the body)

    Filters the taxonomy columns for attachments in the Media list table.

  2. apply_filters( manage_media_columns )filterline 423 (+59 into the body)

    Filters the Media list table columns.

Uses · 9

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.

  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.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.