WordPress.org

Make WordPress Core

Opened 22 months ago

Closed 19 months ago

Last modified 19 months ago

#21222 closed defect (bug) (invalid)

Unable to add columns to the Terms List table

Reported by: dglingren Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description

The base class WP_List_Table and its extended family is a great addition to the WordPress administration API. The WP_Posts_List_Table class has well-documented filters that support adding custom columns to the default table.

However, custom column support in the WP_Terms_List_Table class is incomplete. There is a filter in the column_default method, but it is useless because there is no filter in the get_columns method to allow expanding the column array.

Please consider changing the last line of the get_columns method to something like:

return apply_filters( "manage_{$taxonomy}_custom_get_columns", $columns );

or

return apply_filters( "manage_{$taxonomy}_columns", $columns );

The affected file is wp-admin/includes/class-terms-list-table.php. The choice for the filter name depends on whether you want to follow the convention used in the WP_Terms_List_Table class (first alternative) or the convention used in the WP_Posts_List_Table class (second alternative).

This one-line change would finish the job of making the default table expandable. Thank you for your consideration.

Change History (8)

comment:1 dglingren22 months ago

  • Cc david@… added

comment:2 SergeyBiryukov22 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

You can use manage_{$screen->id}_columns filter from WP_List_Table:
http://core.trac.wordpress.org/browser/tags/3.4.1/wp-admin/includes/class-wp-list-table.php#L89

For categories and tags, it's manage_edit-category_columns and manage_edit-post_tag_columns.

Closing as a duplicate of #20913.

comment:3 michelwppi19 months ago

  • Cc contact@… added
  • Resolution invalid deleted
  • Status changed from closed to reopened

To add the columns this filter manage_edit-category_columns is ok (add columns and title)

BUT

to fill each line of terms the filter "manage_{$screen->taxonomy}_custom_column" must not be a filter(if used: only first filter is possible as returned content and the other filter must echo the row ;-).

It must be an action like in line 671 of wp-posts-list-table

do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );

so in line 318 solution fixe is

do_action( "manage_{$screen->taxonomy}_custom_column",  $column_name, $tag->term_id );

Hope that help to understand our tests

M.

Last edited 19 months ago by michelwppi (previous) (diff)

comment:4 nacin19 months ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Line 319, give or take:

return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );

Return your content (rather than echoing, as occurs with the posts table).

comment:5 michelwppi19 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

BUT if you have two (or more filters), only the first returned value is displayed and for the second filter (another added column) you must echo..

comment:6 nacin19 months ago

Works fine for me:

add_filter( 'manage_edit-post_tag_columns', function( $cols ) {
	$cols['col1'] = 'Column 1';
	$cols['col2'] = 'Column 2';
	return $cols;
} );

add_filter( 'manage_post_tag_custom_column', function( $content, $column, $term_id ) {
	return "We are in $column for $term_id";
}, 10, 3 );

comment:7 michelwppi19 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

OK, you are right - the mistake came from first param 'empty' kept as a dummy var and not the content ... I change my way to manage content like here:

function co_manage_tax_column ( $content, $name, $id ) {
	if( $name != 'linked-post' )
			return $content;
	global $taxonomy ;
	$term = get_term((int)$id , $taxonomy ) ;	
	$a = $term->slug;
		
	//echo '<div>*'. $a .'</div>';	
	return $content.$a;	
}
add_filter( 'manage_category_custom_column', 'co_manage_tax_column', 12, 3);

and now, no interferences between the 2 filters for the two added columns.

Many thanks for your help to go deeper

M.

Last edited 19 months ago by michelwppi (previous) (diff)

comment:8 nacin19 months ago

  • Resolution changed from fixed to invalid
Note: See TracTickets for help on using tickets.