WP_Media_List_Table::get_columns(): string[]

In this article

Return

string[] Array of column titles keyed by their column name.

Source

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' ) ) {
			$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 );
}

Hooks

apply_filters( ‘manage_media_columns’, string[] $posts_columns, bool $detached )

Filters the Media list table columns.

apply_filters( ‘manage_taxonomies_for_attachment_columns’, string[] $taxonomies, string $post_type )

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

User Contributed Notes

You must log in before being able to contribute a note or feedback.