[wp-trac] [WordPress Trac] #54521: Taxonomy term quick edit does not save if taxonomy has non latin characters
WordPress Trac
noreply at wordpress.org
Fri Nov 26 11:52:46 UTC 2021
#54521: Taxonomy term quick edit does not save if taxonomy has non latin characters
--------------------------------+-----------------------------
Reporter: panagiotis.synetos | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 5.8.2
Severity: normal | Keywords:
Focuses: administration |
--------------------------------+-----------------------------
This issue started from the following WooCommerce ticket
https://github.com/woocommerce/woocommerce/issues/31037
After investigating, I could reproduce the issue by doing the following
- Register a new taxonomy that contains Greek character `wp_ελληνικό_tax`
-
{{{
register_taxonomy( 'wp_ελληνικό_tax', array( 'post' ), $args );
}}}
- Create a term
- Edit the term through quick edit
[[Image(https://user-images.githubusercontent.com/2484390/141967192
-60de334d-e5ec-437e-9574-3cd9aa30110c.png)]]
(for a strange reason, I cannot make the image appear inline)
- You'll get a `0` error, with no indication
- If you edit the term through the normal edit (not quick edit) it works
fine.
I already have a suggestion on how to fix this error
https://developer.wordpress.org/reference/functions/wp_ajax_inline_save_tax/
This **wp_ajax_inline_save_tax** function, sanitizes the taxonomy, and
`wp_ελληνικό_tax` becomes `wp__tax`, which doesn't exist. (hence the 0
error)
Why is the taxonomy needed? Cause currently, it calls `get_term` , passing
`term_id` and `taxonomy_slug`.
Instead, what we could do is
- avoid sanitizing the taxonomy slug, seems like there is no need
- try and get the tag/term earlier, by calling `get_term` with just the
`term_id` (as `term_id` is unique, regardless of the taxonomy it belongs
to)
I have attached a revised version of this function
{{{#!php
<?php
function wp_ajax_inline_save_tax() {
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
if ( ! isset( $_POST['tax_ID'] ) || ! (int) $_POST['tax_ID'] ) {
wp_die( -1 );
}
$id = (int) $_POST['tax_ID'];
if ( ! current_user_can( 'edit_term', $id ) ) {
wp_die( -1 );
}
// Try and get the tag just by ID, without the taxonomy argument
$tag = get_term( $id );
if ( null === $tag || is_wp_error( $tag ) ) {
wp_die( 0 );
}
$taxonomy = $tag->taxonomy;
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array(
'screen' => 'edit-' . $taxonomy ) );
// $tag = get_term( $id, $taxonomy );
$_POST['description'] = $tag->description;
........
.......
}
}}}
If agreed, I'd like to work on this issue and do my first contribution on
WordPress.
Panos Synetos
Code Wrangler @ Automattic
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54521>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list