[wp-trac] [WordPress Trac] #34348: Error during add term
WordPress Trac
noreply at wordpress.org
Mon Oct 19 03:00:18 UTC 2015
#34348: Error during add term
------------------------------+-----------------------------
Reporter: sebastian.pisula | Owner: boonebgorges
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 4.4
Component: Taxonomy | Version: trunk
Severity: major | Resolution:
Keywords: needs-patch | Focuses: administration
------------------------------+-----------------------------
Comment (by boonebgorges):
sebastian.pisula - Thanks for the report, and good find.
This is a very, very annoying problem. The problematic code is this:
{{{
$term = get_term( $term_id, $taxonomy );
$term = (array) $term;
}}}
If I thought that `wp_ajax_add_tag()` were the only place in the universe
where this happens, I'd just change how it works - by adding a
`to_array()` method or something like that. But it's likely that there are
plugins doing the exact same thing. The problem is that, in order to
support uses of `(array) $term` where the client expects each term
property to be scalar, we can never add any additional structure to the
term object. That's pretty ridiculous.
So, in the long run, I think we should do one or more of the following:
* Make `WP_Ajax_Response` do something more intelligent when one or more
of its `supplemental` fields is non-scalar (skip it, `json_encode()` it,
whatever)
* Stop doing `foreach ( $term as $k => $v )` and expecting `$v` to be
scalar. If you need the raw data, we'll provide a method for that purpose.
* Tell plugin authors that they cannot expect object properties to be
scalar.
For the time being, I can rewrite the way that `data` is implemented so
that we avoid non-scalar properties on `WP_Term`. It's not a restriction
that I want to be held to in the future, but for now we'll make it work.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34348#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list