[wp-trac] [WordPress Trac] #45938: Adding new term meta fails if column is wrapped in a conditional
WordPress Trac
noreply at wordpress.org
Fri Jan 11 12:06:33 UTC 2019
#45938: Adding new term meta fails if column is wrapped in a conditional
---------------------------+--------------------------------------
Reporter: dingo_bastard | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 5.0.2
Severity: normal | Keywords: dev-feedback 2nd-opinion
Focuses: |
---------------------------+--------------------------------------
I have created two custom taxonomies in my custom post type, and I have
added one callback to render new columns in the taxonomy screen. Since the
two taxonomies share one column, but don't share another I created
something like this:
{{{#!php
<?php
add_filter( 'manage_edit-tax1_columns', 'taxonomy_additional_columns' );
add_filter( 'manage_edit-tax2_columns', 'taxonomy_additional_columns' );
function taxonomy_additional_columns( $columns ) {
$columns[ 'column1' ] = esc_html__( 'Column 1', 'plugin-name' );
if ( isset( ( get_current_screen() )->taxonomy ) && (
get_current_screen() )->taxonomy === 'tax2' ) {
$columns[ 'column2' ] = esc_html__( 'Column 2', 'plugin-name' );
}
return $columns;
}
// Render content in columns
add_filter( 'manage_tax1_custom_column', 'render_column_content', 10, 3 );
add_filter( 'manage_tax2_custom_column', 'render_column_content', 10, 3 );
function render_column_content( $content, $column_name, $term_id ) {
switch ( $column_name ) {
case... // render content from term meta
}
return $content;
}
}}}
While this works, it has a strange bug that's related to the fact that the
taxonomy terms are added using ajax and the added conditional check.
When you create a term in the second taxonomy, the term is added but the
second column is empty until you refresh the page.
I haven't dug much deeper as to why this happens. I guess that the
`get_current_screen()` isn't available in the ajax callback or something
like this.
The workaround is to create two separate functions for adding columns and
duplicate the first column.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45938>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list