WP_Media_List_Table::column_default() WordPress Method
The WP_Media_List_Table::column_default() method is used to generate the default column values for a particular row in the media list table. This method is called by the WP_Media_List_Table::single_row() method for each row in the table. It is also called by the WP_Media_List_Table::display_rows() method for each row in the table. The WP_Media_List_Table::column_default() method accepts two parameters: $media_id (int) – The ID of the media item. $column_name (string) – The name of the column. This method returns the value for the column.
WP_Media_List_Table::column_default( WP_Post $item, string $column_name ) #
Handles output for the default column.
Parameters
Source
File: wp-admin/includes/class-wp-media-list-table.php
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 ( 0 === strpos( $column_name, 'taxonomy-' ) ) { $taxonomy = substr( $column_name, 9 ); } else { $taxonomy = false; } if ( $taxonomy ) { $terms = get_the_terms( $post->ID, $taxonomy ); if ( is_array( $terms ) ) { $out = array(); foreach ( $terms as $t ) { $posts_in_term_qv = array(); $posts_in_term_qv['taxonomy'] = $taxonomy; $posts_in_term_qv['term'] = $t->slug; $out[] = 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(), $out ); } 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 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Renamed $post to $item to match parent class for PHP 8 named parameter support. |
4.3.0 | Introduced. |